From 40b798dc0d401927f894555c13a3dab91cd452ed Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 22 Mar 2010 20:10:19 +0000 Subject: 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 --- .../tuscany/sca/binding/hazelcast/ReferenceInvoker.java | 17 ++++++++++++++++- .../sca/binding/hazelcast/HazelcastBindingTestCase.java | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'sca-java-2.x/trunk/modules/binding-hazelcast-runtime/src') 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 callable = new ServiceInvoker(serviceURI, operation.getName(), requestXML); FutureTask task = new DistributedTask(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 @@ -46,6 +46,16 @@ public class HazelcastBindingTestCase { clientNode.start(); } + @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"); -- cgit v1.2.3