summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/testing/itest/callback-separatethread
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2011-01-12 16:01:37 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2011-01-12 16:01:37 +0000
commitf7cb4b3bd7480ae28360ca5ab830a560e4b0a8c5 (patch)
tree1a3b1e0e2a660d59280ce60a09083c1976ce33c6 /sca-java-2.x/trunk/testing/itest/callback-separatethread
parent839bdcb142c31191ff41e7913a6458c562f26f78 (diff)
Fix for the problem in Callback-SeparateThread iTest identified in TUSCANY-3816
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1058211 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/testing/itest/callback-separatethread')
-rw-r--r--sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java32
1 files changed, 27 insertions, 5 deletions
diff --git a/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java b/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java
index bec98a49c9..0805b96875 100644
--- a/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java
+++ b/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java
@@ -25,8 +25,11 @@ import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import org.oasisopen.sca.ComponentContext;
+import org.oasisopen.sca.RequestContext;
import org.oasisopen.sca.ServiceReference;
import org.oasisopen.sca.annotation.Callback;
+import org.oasisopen.sca.annotation.Context;
import org.oasisopen.sca.annotation.Destroy;
import org.oasisopen.sca.annotation.Scope;
import org.oasisopen.sca.annotation.Service;
@@ -39,10 +42,21 @@ import org.oasisopen.sca.annotation.Service;
public class EventProcessorServiceImpl implements EventProcessorService {
/**
- * Reference to the call back
+ * Reference to the callback
+ *
+ * **NB** This test makes the *DANGEROUS* assumption that there is only one client to
+ * this component and thus only one callback location. For a "real" COMPOSITE component,
+ * each client would need to be uniquely identified - this would need to be done using something
+ * like an ID on the service methods, which could be set by the client and used to identify
+ * a "session"
+ */
+ private ServiceReference<EventProcessorCallBack> clientCallback = null;
+
+ /**
+ * Component context (injected)
*/
- @Callback
- protected ServiceReference<EventProcessorCallBack> clientCallback;
+ @Context
+ protected ComponentContext componentContext;
/**
* This map contains the call backs for each of the registered Event names
@@ -73,13 +87,21 @@ public class EventProcessorServiceImpl implements EventProcessorService {
*/
public void registerForEvent(String aEventName) {
// Register for the Event
- eventListeners.put(aEventName, clientCallback);
+ eventListeners.put(aEventName, getClientCallback());
// Send the "register" started event to the client
receiveEvent(aEventName, "SameThread: Registered to receive notifications for " + aEventName);
}
- /**
+ private ServiceReference<EventProcessorCallBack> getClientCallback() {
+ if(clientCallback == null) {
+ RequestContext requestContext = componentContext.getRequestContext();
+ clientCallback = requestContext.getCallbackReference();
+ }
+ return clientCallback;
+ } // end method getClientCallback
+
+ /**
* Unregisters the client so it no longer receives notifications for the specified event
*
* @param aEventName The name of the Event to unregister