diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-22 20:10:19 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-22 20:10:19 +0000 |
commit | 40b798dc0d401927f894555c13a3dab91cd452ed (patch) | |
tree | dd664ef398e640ede8d04e703d15a1fe3ffdbfc5 /sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src | |
parent | 75fd20d20f95279ceb44a5734d5e25f50c79b0da (diff) |
Update hazelcast binding to use a seperate ExecutorService for each nested invocation (ie a reference calling a service over binding.sca which invokes another reference over binding.sca)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@926303 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src')
2 files changed, 26 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java index cb01e8c34c..9bef453992 100644 --- a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/main/java/org/apache/tuscany/sca/binding/hazelcast/ReferenceInvoker.java @@ -74,7 +74,7 @@ public class ReferenceInvoker implements Invoker { String requestXML = getRequestXML(msg);
Callable<String> callable = new ServiceInvoker(serviceURI, operation.getName(), requestXML);
FutureTask<String> task = new DistributedTask<String>(callable, owningMember);
- ExecutorService executorService = hzRegistry.getHazelcastInstance().getExecutorService();
+ ExecutorService executorService = getExecutorService();
executorService.execute(task);
try {
return getResponseNode(task.get());
@@ -83,6 +83,21 @@ public class ReferenceInvoker implements Invoker { }
}
+ /**
+ * Hazelcast ExecutorService can't nest invocations so use a separate ExecutorService
+ * for nested calls. See http://groups.google.com/group/hazelcast/browse_thread/thread/1cc0b943716476e9
+ */
+ private ExecutorService getExecutorService() {
+ String threadName = Thread.currentThread().getName();
+ if (!threadName.startsWith("hz.executor.")) {
+ return hzRegistry.getHazelcastInstance().getExecutorService("binding.sca.1");
+ } else {
+ String oldName = threadName.substring(threadName.lastIndexOf("binding.sca."), threadName.lastIndexOf(".thread-"));
+ int x = Integer.parseInt(oldName.substring(oldName.lastIndexOf('.') + 1));
+ return hzRegistry.getHazelcastInstance().getExecutorService(oldName.substring(0, 12) + (x + 1));
+ }
+ }
+
private String getRequestXML(Message msg) {
Object[] args = msg.getBody();
String msgXML = domHelper.saveAsString((Node)args[0]);
diff --git a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java index 6a3fff0757..b6760f0902 100644 --- a/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src/test/java/org/apache/tuscany/sca/binding/hazelcast/HazelcastBindingTestCase.java @@ -47,6 +47,16 @@ public class HazelcastBindingTestCase { }
@Test
+ public void testNestedClient() throws Exception {
+ Node client2Node = NodeFactory.newInstance().createNode(URI.create("tuscany:HazelcastBindingTestCase"), "client2.composite", new String[]{"target/test-classes"});
+ client2Node.start();
+ TestService service = client2Node.getService(TestService.class, "TestServiceClient2");
+ assertNotNull(service);
+ assertEquals("Petra", service.echoString("Petra"));
+ client2Node.stop();
+ }
+
+ @Test
public void testEchoString() throws Exception {
TestService service = clientNode.getService(TestService.class, "TestServiceClient");
assertNotNull(service);
|