You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2011/01/12 17:01:37 UTC
svn commit: r1058211 -
/tuscany/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java
Author: edwardsmj
Date: Wed Jan 12 16:01:37 2011
New Revision: 1058211
URL: http://svn.apache.org/viewvc?rev=1058211&view=rev
Log:
Fix for the problem in Callback-SeparateThread iTest identified in TUSCANY-3816
Modified:
tuscany/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java
Modified: tuscany/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java?rev=1058211&r1=1058210&r2=1058211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/callback-separatethread/src/main/java/org/apache/tuscany/sca/itest/EventProcessorServiceImpl.java Wed Jan 12 16:01:37 2011
@@ -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.Serv
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 i
*/
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