From abb2675bc0937b62e91448cfed0c7343ca00b850 Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 6 Dec 2010 12:47:39 +0000 Subject: TUSCANY-3801 - move chain tail location code into the chain implementation git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1042609 13f79535-47bb-0310-9956-ffa450edef68 --- .../testing/service/mocks/TestRuntimeWire.java | 2 +- .../provider/SCABindingAsyncResponseInvoker.java | 2 +- .../tuscany/sca/invocation/InvocationChain.java | 7 +++++ .../org/apache/tuscany/sca/runtime/Invocable.java | 2 +- .../core/assembly/impl/RuntimeEndpointImpl.java | 4 +-- .../impl/RuntimeEndpointReferenceImpl.java | 4 +-- .../sca/core/invocation/RuntimeInvoker.java | 35 ++-------------------- .../core/invocation/impl/InvocationChainImpl.java | 28 +++++++++++++++++ 8 files changed, 45 insertions(+), 39 deletions(-) (limited to 'sca-java-2.x/trunk/modules') diff --git a/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java b/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java index 756299696a..db0e571ef6 100644 --- a/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java +++ b/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java @@ -209,7 +209,7 @@ public class TestRuntimeWire implements RuntimeEndpoint { public void invokeAsync(Operation operation, Message msg) { } - public void invokeAsyncResponse(InvokerAsync tailInvoker, Message msg) { + public void invokeAsyncResponse(Message msg) { } public void unbind() { diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingAsyncResponseInvoker.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingAsyncResponseInvoker.java index 8072b70795..26707e8ebd 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingAsyncResponseInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingAsyncResponseInvoker.java @@ -39,7 +39,7 @@ public class SCABindingAsyncResponseInvoker implements Invoker { // TODO - this only works for the local case! public Message invoke(Message msg) { RuntimeEndpointReference epr = (RuntimeEndpointReference)msg.getFrom(); - epr.invokeAsyncResponse(null, msg); + epr.invokeAsyncResponse(msg); return null; } } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java index d10a5689d4..1d38ec7101 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java @@ -81,6 +81,13 @@ public interface InvocationChain { */ Invoker getHeadInvoker(); + /** + * Returns the last invoker in the chain. + * + * @return The last invoker in the chain + */ + Invoker getTailInvoker(); + /** * Get the first invoker that is on the same or later phase * @param phase diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java index cf9b8ac49e..7c7c104947 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java @@ -145,7 +145,7 @@ public interface Invocable { * @param tailInvoker the invoker at the end of the chain * @param msg The request message */ - void invokeAsyncResponse(InvokerAsync tailInvoker, Message msg); + void invokeAsyncResponse(Message msg); /** * Get a list of policy providers diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java index 32aa0c0646..d74ee4a8f9 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java @@ -293,8 +293,8 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint invoker.invokeAsync(msg); } - public void invokeAsyncResponse(InvokerAsync tailInvoker, Message msg){ - invoker.invokeAsyncResponse(tailInvoker, msg); + public void invokeAsyncResponse(Message msg){ + invoker.invokeAsyncResponse(msg); } /** diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java index 2aadf34295..b8ca59b214 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java @@ -245,8 +245,8 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen invoker.invokeAsync(msg); } - public void invokeAsyncResponse(InvokerAsync tailInvoker, Message msg){ - invoker.invokeAsyncResponse(tailInvoker, msg); + public void invokeAsyncResponse(Message msg){ + invoker.invokeAsyncResponse(msg); } /** diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeInvoker.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeInvoker.java index 7700eeb79c..e1ec899fa5 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeInvoker.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeInvoker.java @@ -176,39 +176,10 @@ public class RuntimeInvoker implements Invoker{ return; } - public void invokeAsyncResponse(InvokerAsync tailInvoker, Message msg) { + public void invokeAsyncResponse(Message msg) { - // TODO - I pass a tail invoker in as on the service side I have one handy - // but calculate it here if it's not passed in - if (tailInvoker == null){ - Operation operation = msg.getOperation(); - InvocationChain chain = invocable.getInvocationChain(operation); - - // find the tail invoker - Invoker next = chain.getHeadInvoker(); - Invoker tail = null; - while (next != null){ - tail = next; - if (next instanceof Interceptor){ - next = ((Interceptor)next).getNext(); - - // TODO - hack to get round SCA binding optimization - // On the refrence side this loop will go all the way - // across to the service invoker so stop the look if we find - // an invoker with no previous pointer. This will be the point - // where the SCA binding invoker points to the head of the - // service chain - - if (!(next instanceof InterceptorAsync) || - ((InterceptorAsync)next).getPrevious() == null){ - break; - } - } else { - next = null; - } - } - tailInvoker = (InvokerAsync)tail; - } + InvocationChain chain = invocable.getInvocationChain(msg.getOperation()); + InvokerAsync tailInvoker = (InvokerAsync)chain.getTailInvoker(); Message asyncResponseMsg = tailInvoker.invokeAsyncResponse(msg); diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java index 477f84e690..716379d141 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java @@ -91,6 +91,34 @@ public class InvocationChainImpl implements InvocationChain { return nodes.isEmpty() ? null : nodes.get(0).getInvoker(); } + public Invoker getTailInvoker() { + // find the tail invoker + Invoker next = getHeadInvoker(); + Invoker tail = null; + while (next != null){ + tail = next; + if (next instanceof Interceptor){ + next = ((Interceptor)next).getNext(); + + // TODO - hack to get round SCA binding optimization + // On the reference side this loop will go all the way + // across to the service invoker so stop looking if we find + // an invoker with no "previous" pointer. This will be the point + // where the SCA binding invoker points to the head of the + // service chain + + if (!(next instanceof InterceptorAsync) || + ((InterceptorAsync)next).getPrevious() == null){ + break; + } + } else { + next = null; + } + } + + return tail; + } + public Invoker getHeadInvoker(String phase) { int index = phaseManager.getAllPhases().indexOf(phase); if (index == -1) { -- cgit v1.2.3