tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r573992 - in /incubator/tuscany/java/sca: itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ itest/conversations/src/main/resour...
Date Sun, 09 Sep 2007 11:08:29 GMT
Author: slaws
Date: Sun Sep  9 04:08:28 2007
New Revision: 573992

URL: http://svn.apache.org/viewvc?rev=573992&view=rev
Log:
TUSCANY-1511
Reset conversation id to null when @EndsConversation is called on callback. 
This is a fix for a @scope(CONVERSATION) client. Other scopes still required fixes

Added:
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationIdService.java
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalServiceStatelessScopeImpl.java
Removed:
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationIdService.java
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalServiceStatelessScope.java
Modified:
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationalClient.java
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationIdComponentImpl.java
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulImpl.java
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulNonConversationalCallbackImpl.java
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatelessImpl.java
    incubator/tuscany/java/sca/itest/conversations/src/main/resources/conversational.composite
    incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationIdTestCase.java
    incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationalTestCase.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java

Added: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationIdService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationIdService.java?rev=573992&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationIdService.java (added)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationIdService.java Sun Sep  9 04:08:28 2007
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.itest.conversational;
+
+import org.osoa.sca.annotations.Conversational;
+
+@Conversational
+public interface ConversationIdService {
+
+    String getCIDField();
+    String getCIDSetter();
+}

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationalClient.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationalClient.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationalClient.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/ConversationalClient.java Sun Sep  9 04:08:28 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.sca.itest.conversational;
 
+import org.osoa.sca.ServiceReference;
 import org.osoa.sca.annotations.Remotable;
 
 /**
@@ -42,8 +43,9 @@
 	public String runConversationBusinessExceptionCallback();
 	public int runConversationCallingEndedConversation();
 	public int runConversationCallingEndedConversationCallback();
+        public String runConversationCallingEndedConversationCheckConversationId(); 
+	public String runConversationCallingEndedConversationCallbackCheckConversationId();
 	public int runConversationAgeTimeout();
 	public int runConversationIdleTimeout();
 	public int runConversationPrincipleError();	
-
 }

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationIdComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationIdComponentImpl.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationIdComponentImpl.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationIdComponentImpl.java Sun Sep  9 04:08:28 2007
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.itest.conversational.impl;
 
+import org.apache.tuscany.sca.itest.conversational.ConversationIdService;
 import org.osoa.sca.annotations.ConversationID;
 import org.osoa.sca.annotations.Scope;
 import org.osoa.sca.annotations.Service;

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulImpl.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulImpl.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulImpl.java Sun Sep  9 04:08:28 2007
@@ -136,7 +136,17 @@
         callableReference.initializeCount(1);
         callableReference.incrementCount();
         clientCount = callableReference.retrieveCount();
-        return callableReference.endConversation();
+        
+        String clientConversationId = serviceReference.getConversationID().toString();
+        String serverConfersationId = callableReference.endConversation();
+        
+        if (clientConversationId.equals("MyConversation2") &&
+            serverConfersationId.equals("MyConversation2") ) {
+            return clientConversationId;
+        } else {
+            return "client = " + clientConversationId +
+                   "server = " + serverConfersationId;
+        }  
               
     }      
     public int runConversationCheckingScope(){
@@ -206,14 +216,55 @@
         conversationalService.initializeCount(1);
         conversationalService.endConversation();
         return conversationalService.retrieveCount();
-    }   
+    }       
     
     public int runConversationCallingEndedConversationCallback(){
         calls.append("runConversationCallingEndedConversationCallback,");
         conversationalService.initializeCountCallback(1);
         conversationalService.endConversationCallback();
         return conversationalService.retrieveCountCallback();
-    }  
+    } 
+     
+    public String runConversationCallingEndedConversationCheckConversationId(){
+        calls.append("runConversationCallingEndedConversationCheckConversationId,");
+        ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, 
+                                                                                                        "conversationalService");
+        serviceReference.setConversationID("MyConversation3");
+        
+        ConversationalService callableReference = serviceReference.getService();
+        
+        callableReference.initializeCount(1);
+        callableReference.incrementCount();
+        clientCount = callableReference.retrieveCount();
+        callableReference.endConversation();
+        
+        if (serviceReference.getConversationID() ==null ) {
+            return null;
+        } else {
+            return serviceReference.getConversationID().toString();
+        }
+
+    }    
+    
+    public String runConversationCallingEndedConversationCallbackCheckConversationId(){
+        calls.append("runConversationCallingEndedConversationCallbackCheckConversationId,");
+        ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, 
+                                                                                                        "conversationalService");
+        serviceReference.setConversationID("MyConversation3");
+        
+        ConversationalService callableReference = serviceReference.getService();
+        
+        callableReference.initializeCount(1);
+        callableReference.incrementCount();
+        clientCount = callableReference.retrieveCount();
+        callableReference.endConversationCallback();
+        
+        if (serviceReference.getConversationID() ==null ) {
+            return null;
+        } else {
+            return serviceReference.getConversationID().toString();
+        }
+    }    
     
     public int runConversationAgeTimeout(){
         calls.append("runConversationAgeTimeout,");
@@ -264,6 +315,7 @@
     
     public String endConversation(){
         calls.append("endConversation,");
+        callbackCount = 0;
         return null;
     }
 

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulNonConversationalCallbackImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulNonConversationalCallbackImpl.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulNonConversationalCallbackImpl.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatefulNonConversationalCallbackImpl.java Sun Sep  9 04:08:28 2007
@@ -202,6 +202,46 @@
         return "No Exception Returned";
     }   
     
+    public String runConversationCallingEndedConversationCheckConversationId(){
+        calls.append("runConversationCallingEndedConversationCheckConversationId,");
+        ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, 
+                                                                                                        "conversationalService");
+        serviceReference.setConversationID("MyConversation3");
+        
+        ConversationalService callableReference = serviceReference.getService();
+        
+        callableReference.initializeCount(1);
+        callableReference.incrementCount();
+        clientCount = callableReference.retrieveCount();
+        callableReference.endConversation();
+        
+        if (serviceReference.getConversationID() ==null ) {
+            return null;
+        } else {
+            return serviceReference.getConversationID().toString();
+        }
+    }    
+    
+    public String runConversationCallingEndedConversationCallbackCheckConversationId(){
+        calls.append("runConversationCallingEndedConversationCallbackCheckConversationId,");
+        ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, 
+                                                                                                        "conversationalService");
+        serviceReference.setConversationID("MyConversation3");
+        
+        ConversationalService callableReference = serviceReference.getService();
+        
+        callableReference.initializeCount(1);
+        callableReference.incrementCount();
+        clientCount = callableReference.retrieveCount();
+        callableReference.endConversationCallback();
+        
+        if (serviceReference.getConversationID() ==null ) {
+            return null;
+        } else {
+            return serviceReference.getConversationID().toString();
+        }
+    }     
+    
     public int runConversationCallingEndedConversation(){
         calls.append("runConversationCallingEndedConversation,");
         conversationalService.initializeCount(1);

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatelessImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatelessImpl.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatelessImpl.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalClientStatelessImpl.java Sun Sep  9 04:08:28 2007
@@ -130,8 +130,17 @@
         callableReference.initializeCount(1);
         callableReference.incrementCount();
         clientCount = callableReference.retrieveCount();
-        return callableReference.endConversation();
-              
+        
+        String clientConversationId = serviceReference.getConversationID().toString();
+        String serverConfersationId = callableReference.endConversation();
+        
+        if (clientConversationId.equals("MyConversation2") &&
+            serverConfersationId.equals("MyConversation2") ) {
+            return clientConversationId;
+        } else {
+            return "client = " + clientConversationId +
+                   "server = " + serverConfersationId;
+        }     
     }     
     public int runConversationCheckingScope(){
         calls.append("runConversationCheckingScope,");
@@ -168,7 +177,7 @@
         return clientCount;
     }	
     
-	public String runConversationBusinessException(){
+    public String runConversationBusinessException(){
 	    calls.append("runConversationbusinessException,");	    
 	    try {
             conversationalService.initializeCount(1);
@@ -210,6 +219,46 @@
         return conversationalService.retrieveCountCallback();
     }   
     
+    public String runConversationCallingEndedConversationCheckConversationId(){
+        calls.append("runConversationCallingEndedConversationCheckConversationId,");
+        ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, 
+                                                                                                        "conversationalService");
+        serviceReference.setConversationID("MyConversation3");
+        
+        ConversationalService callableReference = serviceReference.getService();
+        
+        callableReference.initializeCount(1);
+        callableReference.incrementCount();
+        clientCount = callableReference.retrieveCount();
+        callableReference.endConversation();
+        
+        if (serviceReference.getConversationID() ==null ) {
+            return null;
+        } else {
+            return serviceReference.getConversationID().toString();
+        }
+    }    
+    
+    public String runConversationCallingEndedConversationCallbackCheckConversationId(){
+        calls.append("runConversationCallingEndedConversationCallbackCheckConversationId,");
+        ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, 
+                                                                                                        "conversationalService");
+        serviceReference.setConversationID("MyConversation3");
+        
+        ConversationalService callableReference = serviceReference.getService();
+        
+        callableReference.initializeCount(1);
+        callableReference.incrementCount();
+        clientCount = callableReference.retrieveCount();
+        callableReference.endConversationCallback();
+        
+        if (serviceReference.getConversationID() ==null ) {
+            return null;
+        } else {
+            return serviceReference.getConversationID().toString();
+        } 
+    }    
+    
     public int runConversationAgeTimeout(){
         calls.append("runConversationAgeTimeout,");
         // done in other testing
@@ -261,6 +310,7 @@
     
     public String endConversation(){
         calls.append("endConversation,");
+        callbackCount = 0;
         return null;
     }
 

Added: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalServiceStatelessScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalServiceStatelessScopeImpl.java?rev=573992&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalServiceStatelessScopeImpl.java (added)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/itest/conversational/impl/ConversationalServiceStatelessScopeImpl.java Sun Sep  9 04:08:28 2007
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.itest.conversational.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.itest.conversational.ConversationalService;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Service;
+
+@Service(ConversationalService.class)
+public class ConversationalServiceStatelessScopeImpl implements ConversationalService {
+
+    @ConversationID
+    protected String cid;
+
+    static Map<String, Integer> state = new HashMap<String, Integer>();
+    
+    public void destroy() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public String endConversation() {
+        state.remove(cid);
+        return cid;
+    }
+
+    public String endConversationCallback() {
+        // TODO Auto-generated method stub
+        return null;
+        
+    }
+
+    public void incrementCount() {
+        state.put(cid, Integer.valueOf(state.get(cid)+1));
+    }
+
+    public void businessException() throws Exception {
+        throw new Exception("Business Exception");
+    }
+    
+    public void incrementCountCallback() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void init() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void initializeCount(int count) {
+        state.put(cid, Integer.valueOf(count));
+    }
+
+    public void initializeCountCallback(int count) {
+        // TODO Auto-generated method stub
+        
+    }
+    
+    public void businessExceptionCallback() throws Exception {
+        throw new Exception("Business Exception");
+    }    
+
+    public int retrieveCount() {
+        return state.get(cid);
+    }
+
+    public int retrieveCountCallback() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+    
+}

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/resources/conversational.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/resources/conversational.composite?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/resources/conversational.composite (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/resources/conversational.composite Sun Sep  9 04:08:28 2007
@@ -72,7 +72,7 @@
 	</component>       
    
     <component name="ConversationalServiceStateless">
-		<implementation.java class="org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessScope"/>
+		<implementation.java class="org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessScopeImpl"/>
 	</component>  
 	
     <component name="ConversationalServiceStatelessSL">

Modified: incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationIdTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationIdTestCase.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationIdTestCase.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationIdTestCase.java Sun Sep  9 04:08:28 2007
@@ -21,7 +21,6 @@
 
 
 import org.apache.tuscany.sca.host.embedded.SCADomain;
-import org.apache.tuscany.sca.itest.conversational.impl.ConversationIdService;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;

Modified: incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationalTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationalTestCase.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationalTestCase.java (original)
+++ incubator/tuscany/java/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationalTestCase.java Sun Sep  9 04:08:28 2007
@@ -81,7 +81,7 @@
     public void tearDown() throws Exception {
         domain.close();
     }
- 
+
     // stateless client stateful service tests
     // =======================================
     @Test
@@ -158,7 +158,19 @@
     public void testStatelessStatefulConversationCallingEndedConversationCallback() {
         int count = conversationalStatelessClientStatefulService.runConversationCallingEndedConversationCallback();
         Assert.assertEquals(0, count);
+    }   
+    
+    @Test
+    public void testStatelessStatefulConversationCallingEndedConversationCheckConversationId() {
+        String id = conversationalStatelessClientStatefulService.runConversationCallingEndedConversationCheckConversationId();
+        Assert.assertEquals(null, id);
     }     
+    
+    //@Test
+    public void testStatelessStatefulConversationCallingEndedConversationCallbackCheckConversationId() {
+        String id = conversationalStatelessClientStatefulService.runConversationCallingEndedConversationCallbackCheckConversationId();
+        Assert.assertEquals(null, id);
+    }    
 
     // stateless client stateless service tests
     // ========================================
@@ -223,6 +235,18 @@
         int count = conversationalStatelessClientStatelessService.runConversationCallingEndedConversationCallback();
         Assert.assertEquals(0, count);
     } 
+    
+    @Test
+    public void testStatelessStatelessConversationCallingEndedConversationCheckConversationId() {
+        String id = conversationalStatelessClientStatelessService.runConversationCallingEndedConversationCheckConversationId();
+        Assert.assertEquals(null, id);
+    }     
+    
+    //@Test
+    public void testStatelessStatelessConversationCallingEndedConversationCallbackCheckConversationId() {
+        String id = conversationalStatelessClientStatelessService.runConversationCallingEndedConversationCallbackCheckConversationId();
+        Assert.assertEquals(null, id);
+    }     
 
     // stateful client stateful service tests  
     // ======================================
@@ -283,12 +307,24 @@
         int count = conversationalStatefulClientStatefulService.runConversationCallingEndedConversation();
         Assert.assertEquals(0, count);
     }     
-    
+
     @Test
     public void testStatefulStatefulConversationCallingEndedConversationCallback() {
         int count = conversationalStatefulClientStatefulService.runConversationCallingEndedConversationCallback();
         Assert.assertEquals(0, count);
+    }    
+    
+    @Test
+    public void testStatefulStatefulConversationCallingEndedConversationCheckConversationId() {
+        String id = conversationalStatefulClientStatefulService.runConversationCallingEndedConversationCheckConversationId();
+        Assert.assertEquals(null, id);
     }     
+ 
+    @Test
+    public void testStatefulStatefulConversationCallingEndedConversationCallbackCheckConversationId() {
+        String id = conversationalStatefulClientStatefulService.runConversationCallingEndedConversationCallbackCheckConversationId();
+        Assert.assertEquals(null, id);
+    }    
    
     // stateful client stateless service tests  
     // =======================================
@@ -354,8 +390,20 @@
     public void testStatefulStatelessConversationCallingEndedConversationCallback() {
         int count = conversationalStatefulClientStatelessService.runConversationCallingEndedConversationCallback();
         Assert.assertEquals(0, count);
+    }  
+    
+    @Test
+    public void testStatefulStatelessConversationCallingEndedConversationCheckConversationId() {
+        String id = conversationalStatefulClientStatelessService.runConversationCallingEndedConversationCheckConversationId();
+        Assert.assertEquals(null, id);
     }     
     
+    @Test
+    public void testStatefulStatelessConversationCallingEndedConversationCallbackCheckConversationId() {
+        String id = conversationalStatefulClientStatelessService.runConversationCallingEndedConversationCallbackCheckConversationId();
+        Assert.assertEquals(null, id);
+    }      
+    
     // stateless client request scope service tests
     // ============================================
     @Test
@@ -436,6 +484,18 @@
         Assert.assertEquals(0, count);
     }  
     
+    @Test
+    public void testStatelessRequestConversationCallingEndedConversationCheckConversationId() {
+        String id = conversationalStatelessClientRequestService.runConversationCallingEndedConversationCheckConversationId();
+        Assert.assertEquals(null, id);
+    }     
+    
+    //@Test
+    public void testStatelessRequestConversationCallingEndedConversationCallbackCheckConversationId() {
+        String id = conversationalStatelessClientRequestService.runConversationCallingEndedConversationCallbackCheckConversationId();
+        Assert.assertEquals(null, id);
+    }    
+    
     // stateful client non conversational callback stateful service tests  
     // ==================================================================
    
@@ -503,6 +563,18 @@
     public void testStatefulNonConversationalCallbackStatefulConversationCallingEndedConversationCallback() {
         int count = conversationalStatefulClientNonConversationalCallbackStatelessService.runConversationCallingEndedConversationCallback();
         Assert.assertEquals(0, count);
-    }         
+    }    
+    
+    @Test
+    public void testStatefulNonConversationalCallbackStatefulConversationCallingEndedConversationCheckConversationId() {
+        String id = conversationalStatefulClientNonConversationalCallbackStatelessService.runConversationCallingEndedConversationCheckConversationId();
+        Assert.assertEquals(null, id);
+    }     
+    
+    @Test
+    public void testStatefulNonConversationalCallbackStatefulConversationCallingEndedConversationCallbackCheckConversationId() {
+        String id = conversationalStatefulClientNonConversationalCallbackStatelessService.runConversationCallingEndedConversationCallbackCheckConversationId();
+        Assert.assertEquals("MyConversation3", id);
+    }    
         
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java Sun Sep  9 04:08:28 2007
@@ -67,7 +67,6 @@
     protected transient Binding binding;
 
     protected String componentURI; //The URI of the owning component
-    protected Object conversationID; // The conversationID should be serializable
     protected Object callbackID; // The callbackID should be serializable
 
     protected String scdl;
@@ -216,8 +215,11 @@
                 }
                 if (parameters != null) {
                     this.callbackID = parameters.getCallbackID();
-                    this.conversationID = parameters.getConversationID();
                     this.componentURI = parameters.getComponentURI();
+                    
+                    if (conversation != null){
+                        conversation.setConversationID(parameters.getConversationID());
+                    }
                 }
                 URI uri = URI.create(componentURI + "/");
                 for (Binding binding : reference.getBindings()) {
@@ -284,7 +286,11 @@
             ReferenceParameters parameters = new ReferenceParameters();
             parameters.setCallbackID(callbackID);
             parameters.setComponentURI(componentURI);
-            parameters.setConversationID(conversationID);
+            if (conversation != null){
+                parameters.setConversationID(conversation.getConversationID());
+            } else {
+                parameters.setConversationID(null);
+            }
             reference.getExtensions().add(parameters);
             String scdl =
                 ((CompositeActivatorImpl)compositeActivator).getComponentContextHelper().toXML(component, reference);

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java Sun Sep  9 04:08:28 2007
@@ -72,22 +72,26 @@
     }
 
     public Object getConversationID() {
-        return conversationID;
+        if (getConversation() != null) {
+            return getConversation().getConversationID();
+        } else {
+            return null;
+        }
     }
 
     public void setConversationID(Object conversationID) throws IllegalStateException {
-        Conversation conversation = getConversation();
-        if (conversation == null) {
+        ConversationImpl conversation = (ConversationImpl)getConversation();
+        if (conversation != null) {
             if (conversationID == null) {
-                this.conversationID = UUID.randomUUID().toString();
+                conversation.setConversationID(UUID.randomUUID().toString());
             } else {
-                this.conversationID = conversationID;
+                conversation.setConversationID(conversationID);
             }
         } else {
-            // FIXME: [refng] Commented it out for now so that test cases are not broken
-            // throw new IllegalStateException("A conversation is currently associated with this reference");
-            this.conversationID = conversationID;
-            ((ConversationImpl) conversation).setConversationID(conversationID);
+            throw new IllegalStateException("Trying to set conversation id " + 
+                                            conversationID.toString() +
+                                            "on non conversational reference " + 
+                                            reference.getName());
         }
     }
 

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java Sun Sep  9 04:08:28 2007
@@ -206,13 +206,6 @@
         // make sure that the conversation id is set so it can be put in the 
         // outgoing messages.        
         if (conversational) {
-            if (conversation == null) {
-                // this call is via an automatic proxy rather than a
-                // callable/service reference so no conversation object 
-                // will have been constructed yet
-                conversation = new ConversationImpl();
-            }
-
             Object conversationId = conversation.getConversationID();
 
             // create a conversation id if one doesn't exist 
@@ -222,31 +215,26 @@
             if (conversationId == null) {
                 // create a new conversation Id
                 conversationId = createConversationID();
+                conversation.setConversationID(conversationId);
+            }
 
-                // If we are passing out a callback target
-                // register the calling component instance against this 
-                // new conversation id so that stateful callbacks will be
-                // able to find it
-                if (wire.getSource().getCallbackEndpoint() != null && callbackObject == null) {
-                    // the component instance is already registered
-                    // so add another registration
-                    ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);
+            msg.setConversationID(conversationId);
+            
+            // If we are passing out a callback target register the calling component instance against 
+            // this new conversation id so that stateful callbacks will be able to find it
+            // we don't check if the callback has conversation scope here as non-conversational
+            // scoped components still need to have the conversation ids on the calling reference set
+            // to null
+            if (wire.getSource().getCallbackEndpoint() != null && callbackObject == null) {
+                // the component instance will already registered by now so add another registration
+                ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);
 
-                    if (scopeContainer != null) {
-                        scopeContainer.addWrapperReference(msgContextConversationId, conversationId);
-                    }
+                if (scopeContainer != null) {
+                    scopeContainer.addWrapperReference(msgContextConversationId, conversation);
                 }
-
-                // we have just created a new conversation Id so 
-                // put it back in the conversation object
-                conversation.setConversationID(conversationId);
             }
-
-            //TODO - assuming that the conversation ID is a string here when
-            //       it can be any object that is serializable to XML
-            msg.setConversationID((String)conversationId);
         }
-
+        
         Invoker headInvoker = chain.getHeadInvoker();
         msg.setCorrelationID(callbackID);
         Operation operation = chain.getTargetOperation();
@@ -257,17 +245,6 @@
             if (sequence == ConversationSequence.CONVERSATION_END) {
                 msg.setConversationSequence(ConversationSequence.CONVERSATION_END);
                 conversationStarted = false;
-                if (conversation != null) {
-
-                    // remove conversation id from scope container
-                    ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);
-
-                    if (scopeContainer != null) {
-                        scopeContainer.remove(conversation.getConversationID());
-                    }
-
-                    conversation.setConversationID(null);
-                }
             } else if (sequence == ConversationSequence.CONVERSATION_CONTINUE) {
                 if (conversationStarted) {
                     msg.setConversationSequence(ConversationSequence.CONVERSATION_CONTINUE);
@@ -316,6 +293,25 @@
             // dispatch the wire down the chain and get the response
             Message resp = headInvoker.invoke(msg);
             Object body = resp.getBody();
+            
+            // Mark the object instance for removal if the conversation has ended
+            if (contract != null && contract.isConversational()) {
+                ConversationSequence sequence = operation.getConversationSequence();
+                if (sequence == ConversationSequence.CONVERSATION_END) {
+                    if (conversation != null) {
+
+                        // remove conversation id from scope container
+                        ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);
+
+                        if (scopeContainer != null) {
+                            scopeContainer.remove(conversation.getConversationID());
+                        }
+
+                        conversation.setConversationID(null);
+                    }
+                }
+            }               
+            
             if (resp.isFault()) {
                 throw (Throwable)body;
             }
@@ -323,6 +319,8 @@
         } finally {
             ThreadMessageContext.setMessageContext(msgContext);
         }
+        
+
     }
 
     private ScopeContainer<Object> getConversationalScopeContainer(RuntimeWire wire) {

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java?rev=573992&r1=573991&r2=573992&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java Sun Sep  9 04:08:28 2007
@@ -21,6 +21,7 @@
 package org.apache.tuscany.sca.core.scope;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -30,11 +31,13 @@
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.tuscany.sca.core.context.ConversationImpl;
 import org.apache.tuscany.sca.core.context.InstanceWrapper;
 import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.store.Store;
+import org.osoa.sca.Conversation;
 import org.osoa.sca.ConversationEndedException;
 
 /**
@@ -172,16 +175,32 @@
         return getInstanceWrapper(true,contextId);
     } 
     
-    public void addWrapperReference(Object existingContextId, Object newContextId) throws TargetResolutionException {
-        // get the instance wrapper via the existing id
-        InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(existingContextId);
+    /**
+     * This method allows a new context id to be registered alongside an existing one. This happens in
+     * one case, when a conversation includes a stateful callback. The client component instance
+     * must be registered against all outgoing conversation ids so that the component instance
+     * can be found when the callback arrives
+     * 
+     * @param existingContextId the context id against which the component is already registered
+     * @param context this should be a conversation object so that the conversation can b stored
+     *                and reset when the component instance is removed
+     */
+    public void addWrapperReference(Object existingContextId, Object contextId) throws TargetResolutionException {
+        Conversation conversation = (Conversation)contextId;
         
-        // add the id to the list of ids that the wrapper holds. Used for reference
-        // counting on destruction
-        anInstanceWrapper.addInstanceId(newContextId);
+        // get the instance wrapper via the existing id
+        InstanceLifeCycleWrapper existingInstanceWrapper = this.instanceLifecycleCollection.get(existingContextId);
+        InstanceLifeCycleWrapper newInstanceWrapper = this.instanceLifecycleCollection.get(conversation.getConversationID());
         
-        // add the reference to the collection
-        this.instanceLifecycleCollection.put(newContextId, anInstanceWrapper);  
+        // only add the extra reference once
+        if (newInstanceWrapper == null) {
+            // add the id to the list of ids that the wrapper holds. Used for reference
+            // counting and conversation resetting on destruction. 
+            existingInstanceWrapper.addCallbackConversation(conversation);
+            
+            // add the reference to the collection
+            this.instanceLifecycleCollection.put(conversation.getConversationID(), existingInstanceWrapper); 
+        }
     }
 
     public void registerWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException {
@@ -225,15 +244,17 @@
     
     private class InstanceLifeCycleWrapper 
     {
-        private List<Object> instanceIds = new ArrayList<Object>();
+        private Object clientConversationId;
+        private List<ConversationImpl> callbackConversations = new ArrayList<ConversationImpl>();
         private long   creationTime;
         private long   lastReferencedTime;
         private long   expirationInterval;
         private long   maxIdleTime;
+        private Conversation conversation;
         
         private InstanceLifeCycleWrapper(Object contextId) throws TargetResolutionException
         {
-         this.instanceIds.add(contextId);
+         this.clientConversationId = contextId;
          this.creationTime = System.currentTimeMillis();
          this.lastReferencedTime = this.creationTime;
          this.expirationInterval = max_age;
@@ -243,14 +264,14 @@
 
         private InstanceLifeCycleWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException
         {
-         this.instanceIds.add(contextId);
+         this.clientConversationId = contextId;
          this.creationTime = System.currentTimeMillis();
          this.lastReferencedTime = this.creationTime;
          this.expirationInterval = max_age;
          this.maxIdleTime = max_idle_time;
          wrappers.put(contextId, wrapper);       
-        }
-        
+        }      
+               
         private boolean isExpired() 
         {               
          long currentTime = System.currentTimeMillis(); 
@@ -267,11 +288,14 @@
          this.lastReferencedTime = System.currentTimeMillis();
         }
         
-        // add another instance id to this instance
-        private void addInstanceId(Object contextId){
-            InstanceWrapper ctx =  getInstanceWrapper(instanceIds.get(0));
-            instanceIds.add(contextId);
-            wrappers.put(contextId, ctx);
+        // Associates a callback conversation with this instance. Each time the scope container
+        // is asked to remove an object given a ontextId an associated conversation object will 
+        // have its conversationId reset to null. When the list of ids is empty the component instance
+        // will be removed from the scope container
+        private void addCallbackConversation(Conversation  conversation){
+            InstanceWrapper ctx =  getInstanceWrapper(clientConversationId);
+            callbackConversations.add((ConversationImpl)conversation);
+            wrappers.put(conversation.getConversationID(), ctx);
         }
         
         //
@@ -287,12 +311,36 @@
         {
           InstanceWrapper ctx =  getInstanceWrapper(contextId);            
           wrappers.remove(contextId);
-          instanceIds.remove(contextId);
           
-          // stop the component if its this removes the 
-          // last reference
-          if (instanceIds.isEmpty()) {
+          // find out if we are dealing with the original client conversation id
+          // and reset accordingly
+          if (clientConversationId.equals(contextId)){
+              clientConversationId = null;
+          } else {
+              // reset the conversationId in the conversation object if present 
+              // so that and ending callback causes the conversation in the originating
+              // service reference in the client to be reset
+              ConversationImpl conversation = null;
+              
+              for (ConversationImpl loopConversation : callbackConversations) {
+                  if (loopConversation.getConversationID().equals(contextId)) {
+                      conversation = loopConversation;
+                  }
+              }
+              if(conversation != null){
+                  conversation.setConversationID(null);
+                  callbackConversations.remove(conversation);
+              }
+          }
+         
+          
+          // stop the component if this removes the last reference
+          if (clientConversationId == null &&
+              callbackConversations.isEmpty()) {
               ctx.stop();
+              if (conversation != null) {
+                  ((ConversationImpl)conversation).setConversationID(null);
+              }
           }   
         }
         
@@ -333,9 +381,14 @@
                         // cycle through all the references to this instance and
                         // remove them from the underlying wrappers collection and
                         // from the lifecycle wrappers collection
-                        for(Object contextId : anInstanceLifeCycleWrapper.instanceIds ){
-                            anInstanceLifeCycleWrapper.removeInstanceWrapper(contextId);
-                            this.instanceLifecycleCollection.remove(contextId);
+                        for (ConversationImpl conversation : anInstanceLifeCycleWrapper.callbackConversations) {
+                            anInstanceLifeCycleWrapper.removeInstanceWrapper(conversation.getConversationID());
+                            this.instanceLifecycleCollection.remove(conversation.getConversationID());
+                        }
+                        
+                        if (anInstanceLifeCycleWrapper.clientConversationId != null){
+                            anInstanceLifeCycleWrapper.removeInstanceWrapper(anInstanceLifeCycleWrapper.clientConversationId);
+                            this.instanceLifecycleCollection.remove(anInstanceLifeCycleWrapper.clientConversationId);
                         }
                     } catch (Exception ex) {
                       // TODO - what to do with any asynchronous exceptions?



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message