From 0300e06525a3bf34bdf3cd27675a25968b433b4e Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 11 Jun 2009 07:39:44 +0000 Subject: TUSCANY-3082 TUSCANY-3090 - Remove references to the old EndpointReference and replace with EndpointReference2 and Endpoint2 as appropriate. You'll see that some of the changes have left more commented out code as the old EndpointReference has code to support callback/conversation function not required by OASIS. I've also disabled some itests for this reason. Note that callbacks over web services won't work yet as work on EndpointReference2 is still ongoing. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@783664 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/core/assembly/RuntimeAssemblyFactory.java | 13 +- .../core/assembly/impl/EndpointReferenceImpl.java | 186 --------------------- .../assembly/impl/ReferenceParametersImpl.java | 8 +- .../impl/RuntimeComponentReferenceImpl.java | 2 +- .../assembly/impl/RuntimeComponentServiceImpl.java | 10 +- .../sca/core/assembly/impl/RuntimeWireImpl2.java | 19 ++- .../sca/core/context/CallableReferenceExt.java | 4 +- .../tuscany/sca/core/context/CompositeContext.java | 6 +- .../core/context/impl/CallableReferenceImpl.java | 34 +++- .../core/context/impl/CompositeContextImpl.java | 7 +- .../sca/core/context/impl/RequestContextImpl.java | 32 ++-- .../core/context/impl/ServiceReferenceImpl.java | 3 +- .../invocation/CallbackInterfaceInterceptor.java | 5 + .../core/invocation/NonBlockingInterceptor.java | 13 +- .../sca/core/invocation/RuntimeWireInvoker.java | 44 +++-- .../sca/core/invocation/ThreadMessageContext.java | 4 +- .../invocation/impl/CallbackReferenceImpl.java | 109 ++++++------ .../impl/JDKCallbackInvocationHandler.java | 5 +- .../core/invocation/impl/JDKInvocationHandler.java | 60 ++++--- .../sca/core/invocation/impl/MessageImpl.java | 23 +-- .../scope/impl/ConversationalScopeContainer.java | 3 +- 21 files changed, 248 insertions(+), 342 deletions(-) delete mode 100644 java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointReferenceImpl.java (limited to 'java/sca/modules/core') diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java index 27845b445c..8b03ea7a02 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java @@ -20,25 +20,19 @@ package org.apache.tuscany.sca.core.assembly; import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; + import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl; -import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl; -import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentReferenceImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentServiceImpl; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.ReferenceParameters; -import org.apache.tuscany.sca.runtime.RuntimeComponent; + /** * The runtime version of assembly factory @@ -65,6 +59,7 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As return new RuntimeComponentServiceImpl(); } + /* TODO - EPR - remove now // FIXME: [rfeng] We need to find a more consistent story to deal with EPR, EP and CallableReference public EndpointReference createEndpointReference(String uri) { return new EndpointReferenceImpl(uri); @@ -76,10 +71,12 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As InterfaceContract interfaceContract) { return new EndpointReferenceImpl(component, contract, binding, interfaceContract); } + public ReferenceParameters createReferenceParameters() { return new ReferenceParametersImpl(); } + */ @Override public Endpoint2 createEndpoint() { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointReferenceImpl.java deleted file mode 100644 index 022cac398a..0000000000 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointReferenceImpl.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.assembly.impl; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.ReferenceParameters; -import org.apache.tuscany.sca.runtime.RuntimeComponent; - -/** - * @version $Rev$ $Date$ - */ -public class EndpointReferenceImpl implements EndpointReference { - private RuntimeComponent component; - private Contract contract; - private Binding binding; - private InterfaceContract interfaceContract; - private String uri; - private EndpointReference callbackEndpoint; - private ReferenceParameters parameters = new ReferenceParametersImpl(); - - /** - * @param component - * @param contract - * @param binding - * @param interfaceContract - */ - public EndpointReferenceImpl(RuntimeComponent component, - Contract contract, - Binding binding, - InterfaceContract interfaceContract) { - super(); - this.component = component; - this.contract = contract; - this.binding = binding; - this.interfaceContract = interfaceContract; - this.uri = (component != null ? component.getURI() : "") + '/' + - (contract != null ? contract.getName() : ""); - } - - /** - * @param uri - */ - public EndpointReferenceImpl(String uri) { - super(); - this.uri = uri; - } - - public Binding getBinding() { - return binding; - } - - public void setBinding(Binding binding) { - this.binding = binding; - } - - public RuntimeComponent getComponent() { - return component; - } - - public void setComponent(RuntimeComponent component) { - this.component = component; - } - - public Contract getContract() { - return contract; - } - - public void setContract(Contract contract) { - this.contract = contract; - } - - public InterfaceContract getInterfaceContract() { - return interfaceContract; - } - - public void setInterfaceContract(InterfaceContract interfaceContract) { - this.interfaceContract = interfaceContract; - } - - public String getURI() { - return uri; - } - - public void setURI(String uri) { - this.uri = uri; - } - - public EndpointReference getCallbackEndpoint() { - return callbackEndpoint; - } - - public void setCallbackEndpoint(EndpointReference callbackEndpoint) { - this.callbackEndpoint = callbackEndpoint; - } - - @Override - public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((uri == null) ? 0 : uri.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final EndpointReferenceImpl other = (EndpointReferenceImpl)obj; - if (uri == null) { - if (other.uri != null) { - return false; - } - } else if (!uri.equals(other.uri)) { - return false; - } - return true; - } - - /** - * @see java.lang.Object#clone() - */ - @Override - public Object clone() throws CloneNotSupportedException { - EndpointReferenceImpl copy = (EndpointReferenceImpl)super.clone(); - /* [nash] no need to copy callback endpoint - if (callbackEndpoint != null) { - copy.callbackEndpoint = (EndpointReference)callbackEndpoint.clone(); - } - */ - if (parameters != null) { - copy.parameters = (ReferenceParameters)parameters.clone(); - } - return copy; - } - - /** - * @return the parameters - */ - public ReferenceParameters getReferenceParameters() { - return parameters; - } - - /** - * @param parameters the parameters to set - */ - public void setReferenceParameters(ReferenceParameters parameters) { - this.parameters = parameters; - } - - public void mergeEndpoint(EndpointReference epr) { - this.component = epr.getComponent(); - this.contract = epr.getContract(); - this.binding = epr.getBinding(); - this.interfaceContract = epr.getInterfaceContract(); - this.uri = epr.getURI(); - this.callbackEndpoint = epr.getCallbackEndpoint(); - } - -} diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java index 0170af54fc..4413bae39c 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParametersImpl.java @@ -19,7 +19,7 @@ package org.apache.tuscany.sca.core.assembly.impl; -import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.runtime.ReferenceParameters; /** @@ -28,7 +28,7 @@ import org.apache.tuscany.sca.runtime.ReferenceParameters; public class ReferenceParametersImpl implements ReferenceParameters { private Object callbackID; private Object conversationID; - private EndpointReference callbackReference; + private EndpointReference2 callbackReference; private Object callbackObjectID; /** @@ -59,13 +59,13 @@ public class ReferenceParametersImpl implements ReferenceParameters { /** * @see org.apache.tuscany.sca.runtime.ReferenceParameters#getCallbackReference() */ - public EndpointReference getCallbackReference() { + public EndpointReference2 getCallbackReference() { return callbackReference; } /** * @see org.apache.tuscany.sca.runtime.ReferenceParameters#setCallback(java.lang.Object) */ - public void setCallbackReference(EndpointReference callback) { + public void setCallbackReference(EndpointReference2 callback) { this.callbackReference = callback; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java index dbdba54dc0..2026754f57 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java @@ -63,7 +63,7 @@ public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implem // TODO - EPR - shouldn't rely on this anymore public RuntimeWire getRuntimeWire(Binding binding) { for (RuntimeWire wire : getRuntimeWires()) { - if (wire.getSource().getBinding() == binding) { + if (wire.getEndpointReference().getBinding() == binding) { return wire; } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java index 2cbd72f218..776d35327d 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java @@ -56,7 +56,7 @@ public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements public RuntimeWire getRuntimeWire(Binding binding) { for (RuntimeWire wire : wires) { - if (wire.getTarget().getBinding() == binding) { + if (wire.getEndpoint().getBinding() == binding) { return wire; } } @@ -68,11 +68,11 @@ public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements if (wire == null) { return null; } - if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) { + if (interfaceContract != null && interfaceContract != wire.getEndpointReference().getInterfaceContract()) { try { // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts wire = (RuntimeWire)wire.clone(); - wire.getSource().setInterfaceContract(interfaceContract); + wire.getEndpointReference().setInterfaceContract(interfaceContract); wire.rebuild(); } catch (CloneNotSupportedException e) { throw new ServiceRuntimeException(e); @@ -112,11 +112,11 @@ public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements if (wire == null) { return null; } - if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) { + if (interfaceContract != null && interfaceContract != wire.getEndpointReference().getInterfaceContract()) { try { // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts wire = (RuntimeWire)wire.clone(); - wire.getSource().setInterfaceContract(interfaceContract); + wire.getEndpointReference().setInterfaceContract(interfaceContract); wire.rebuild(); } catch (CloneNotSupportedException e) { throw new ServiceRuntimeException(e); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java index ebe8c1b9ed..6f521686f2 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java @@ -60,7 +60,6 @@ import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -89,7 +88,7 @@ public class RuntimeWireImpl2 implements RuntimeWire { // the following is a very simple cache that avoids re-cloning a wire // when consecutive callbacks to the same endpoint are made - private EndpointReference lastCallback; + private Endpoint2 lastCallback; private RuntimeWire cachedWire; private boolean wireReserved; private RuntimeWireImpl2 clonedFrom; @@ -441,6 +440,7 @@ public class RuntimeWireImpl2 implements RuntimeWire { // TODO - EPR remove when we convert fully over to EndpointReference2 // TODO - remove. Just here during development +/* static EndpointReference epr; public EndpointReference getSource() { @@ -482,6 +482,7 @@ public class RuntimeWireImpl2 implements RuntimeWire { // TODO - can we use the idea of setTarget to rebuild the wire? } +*/ // =================================================================== @@ -493,12 +494,16 @@ public class RuntimeWireImpl2 implements RuntimeWire { // TODO - cheating here as I fixed the RuntimeComponentService code // to call this when it resets the interface contract - endpointReference.setInterfaceContract(epr.getInterfaceContract()); + //endpointReference.setInterfaceContract(epr.getInterfaceContract()); } public EndpointReference2 getEndpointReference() { return endpointReference; } + + public Endpoint2 getEndpoint() { + return endpoint; + } /** * Add the interceptor for a reference binding @@ -635,8 +640,10 @@ public class RuntimeWireImpl2 implements RuntimeWire { return conversationManager; } - public synchronized RuntimeWire lookupCache(EndpointReference callback) { - if (lastCallback != null && callback.getURI().equals(lastCallback.getURI()) && !wireReserved) { + public synchronized RuntimeWire lookupCache(Endpoint2 callback) { + if (lastCallback != null && + callback.getURI().equals(lastCallback.getURI()) && + !wireReserved) { wireReserved = true; return cachedWire; } else { @@ -644,7 +651,7 @@ public class RuntimeWireImpl2 implements RuntimeWire { } } - public synchronized void addToCache(EndpointReference callback, RuntimeWire clonedWire) { + public synchronized void addToCache(Endpoint2 callback, RuntimeWire clonedWire) { ((RuntimeWireImpl2)clonedWire).setClonedFrom(this); lastCallback = callback; cachedWire = clonedWire; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java index c0217e7336..c0464cc153 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java @@ -24,8 +24,8 @@ import java.io.IOException; import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.conversation.ConversationExt; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeWire; import org.oasisopen.sca.CallableReference; @@ -58,7 +58,7 @@ public interface CallableReferenceExt extends CallableReference, Externali /** * @return */ - EndpointReference getEndpointReference(); + EndpointReference2 getEndpointReference(); /** * @return diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CompositeContext.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CompositeContext.java index 29c4dfd362..e67872567c 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CompositeContext.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CompositeContext.java @@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.conversation.ConversationManager; @@ -38,7 +39,6 @@ import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -146,11 +146,11 @@ public abstract class CompositeContext { public static RuntimeComponent getCurrentComponent() { Message message = ThreadMessageContext.getMessageContext(); if (message != null) { - EndpointReference to = message.getTo(); + Endpoint2 to = message.getTo(); if (to == null) { return null; } - RuntimeComponent component = message.getTo().getComponent(); + RuntimeComponent component = (RuntimeComponent) message.getTo().getComponent(); return component; } return null; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java index e0ef3d5c97..b39cbe6d17 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java @@ -27,19 +27,23 @@ import java.util.UUID; import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; import org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl2; -import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl; import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl; import org.apache.tuscany.sca.core.context.CallableReferenceExt; import org.apache.tuscany.sca.core.context.ComponentContextExt; @@ -52,7 +56,6 @@ import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; @@ -88,6 +91,9 @@ public class CallableReferenceImpl implements CallableReferenceExt { private transient RuntimeComponentReference clonedRef; private transient ReferenceParameters refParams; private transient XMLStreamReader xmlReader; + + private FactoryExtensionPoint modelFactories; + protected RuntimeAssemblyFactory assemblyFactory; /* * Public constructor for Externalizable serialization/deserialization @@ -116,6 +122,11 @@ public class CallableReferenceImpl implements CallableReferenceExt { this.reference = reference; this.endpointReference = endpointReference; + ExtensionPointRegistry registry = compositeActivator.getCompositeContext().getExtensionPointRegistry(); + this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + + // FIXME: The SCA Specification is not clear how we should handle multiplicity // for CallableReference if (this.endpointReference == null) { @@ -164,8 +175,8 @@ public class CallableReferenceImpl implements CallableReferenceExt { protected void bind(RuntimeWire wire) { if (wire != null) { - this.component = wire.getSource().getComponent(); - this.reference = (RuntimeComponentReference)wire.getSource().getContract(); + this.component = (RuntimeComponent)wire.getEndpointReference().getComponent(); + this.reference = (RuntimeComponentReference)wire.getEndpointReference().getReference(); this.endpointReference = wire.getEndpointReference(); this.compositeActivator = ((ComponentContextExt)component.getComponentContext()).getCompositeActivator(); this.conversationManager = this.compositeActivator.getCompositeContext().getConversationManager(); @@ -508,7 +519,7 @@ public class CallableReferenceImpl implements CallableReferenceExt { } // TODO - EPR - needs sorting out for new endpoint references - public EndpointReference getEndpointReference() { + public EndpointReference2 getEndpointReference() { try { resolve(); @@ -517,9 +528,16 @@ public class CallableReferenceImpl implements CallableReferenceExt { InterfaceContract sourceContract = componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract(); sourceContract = sourceContract.makeUnidirectional(false); - EndpointReference epr = new EndpointReferenceImpl(component, reference, null /*binding*/, sourceContract); - ReferenceParameters parameters = getReferenceParameters(); - epr.setReferenceParameters(parameters); + + EndpointReference2 epr = assemblyFactory.createEndpointReference(); + epr.setComponent(component); + epr.setReference(reference); + //epr.setBinding(binding); + epr.setInterfaceContract(sourceContract); + + Endpoint2 endpoint = assemblyFactory.createEndpoint(); + epr.setTargetEndpoint(endpoint); + return epr; } catch (Exception e) { throw new ServiceRuntimeException(e); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java index 72789b72a1..de0ea04fad 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CompositeContextImpl.java @@ -39,6 +39,8 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint2; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Reference; @@ -61,7 +63,6 @@ import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -274,11 +275,11 @@ public class CompositeContextImpl extends CompositeContext { public static RuntimeComponent getCurrentComponent() { Message message = ThreadMessageContext.getMessageContext(); if (message != null) { - EndpointReference to = message.getTo(); + Endpoint2 to = message.getTo(); if (to == null) { return null; } - RuntimeComponent component = message.getTo().getComponent(); + RuntimeComponent component = (RuntimeComponent) message.getTo().getComponent(); return component; } return null; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java index 015c80c6fa..a701bd50b4 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java @@ -22,6 +22,7 @@ import java.util.List; import javax.security.auth.Subject; +import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.context.CallableReferenceExt; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; @@ -31,7 +32,6 @@ import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; import org.apache.tuscany.sca.core.invocation.impl.CallbackReferenceImpl; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; @@ -65,20 +65,23 @@ public class RequestContextImpl implements RequestContext { } public String getServiceName() { - return ThreadMessageContext.getMessageContext().getTo().getContract().getName(); + return ThreadMessageContext.getMessageContext().getTo().getService().getName(); } public CallableReference getServiceReference() { Message msgContext = ThreadMessageContext.getMessageContext(); // FIXME: [rfeng] Is this the service reference matching the caller side? - EndpointReference to = msgContext.getTo(); - RuntimeComponentService service = (RuntimeComponentService) to.getContract(); + Endpoint2 to = msgContext.getTo(); + RuntimeComponentService service = (RuntimeComponentService) to.getService(); RuntimeComponent component = (RuntimeComponent) to.getComponent(); CallableReference callableReference = component.getComponentContext().getCallableReference(null, component, service); - ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters(); - ((CallableReferenceExt) callableReference).attachCallbackID(parameters.getCallbackID()); - ((CallableReferenceExt) callableReference).attachConversation(parameters.getConversationID()); + + //TODO - EPR - not required for OASIS + //ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters(); + //((CallableReferenceExt) callableReference).attachCallbackID(parameters.getCallbackID()); + //((CallableReferenceExt) callableReference).attachConversation(parameters.getConversationID()); + return callableReference; } @@ -93,8 +96,8 @@ public class RequestContextImpl implements RequestContext { @SuppressWarnings("unchecked") public CallableReference getCallbackReference() { Message msgContext = ThreadMessageContext.getMessageContext(); - EndpointReference to = msgContext.getTo(); - RuntimeComponentService service = (RuntimeComponentService) to.getContract(); + Endpoint2 to = msgContext.getTo(); + RuntimeComponentService service = (RuntimeComponentService) to.getService(); RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference(); if (callbackReference == null) { return null; @@ -106,11 +109,12 @@ public class RequestContextImpl implements RequestContext { CallbackReferenceImpl ref = CallbackReferenceImpl.newInstance(javaClass, proxyFactory, wires); if (ref != null) { //ref.resolveTarget(); - ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters(); - ref.attachCallbackID(parameters.getCallbackID()); - if (ref.getConversation() != null) { - ref.attachConversationID(parameters.getConversationID()); - } + // TODO - EPR - not required for OASIS + //ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters(); + //ref.attachCallbackID(parameters.getCallbackID()); + //if (ref.getConversation() != null) { + // ref.attachConversationID(parameters.getConversationID()); + //} } return ref; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java index 52f506c6cd..265b08ed12 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java @@ -27,7 +27,6 @@ import org.apache.tuscany.sca.core.context.CallableReferenceExt; import org.apache.tuscany.sca.core.context.ServiceReferenceExt; import org.apache.tuscany.sca.core.conversation.ConversationState; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; @@ -118,6 +117,7 @@ public class ServiceReferenceImpl extends CallableReferenceImpl implements this.callback = callback; } +/* TODO - EPR - not required in OASIS @Override protected ReferenceParameters getReferenceParameters() { ReferenceParameters parameters = super.getReferenceParameters(); @@ -133,4 +133,5 @@ public class ServiceReferenceImpl extends CallableReferenceImpl implements } return parameters; } +*/ } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java index 1ee922144f..e6bee6b8d9 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java @@ -37,13 +37,18 @@ public class CallbackInterfaceInterceptor implements Interceptor { } public Message invoke(Message msg) { + + /* TODO - EPR - not required for OASIS ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); if (parameters.getCallbackObjectID() != null || parameters.getCallbackReference() != msg.getFrom() .getCallbackEndpoint()) { + */ return next.invoke(msg); + /* } else { throw new NoRegisteredCallbackException("Callback target does not implement the callback interface"); } + */ } public void setNext(Invoker next) { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java index 494cb93d97..0af48a9add 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java @@ -24,11 +24,12 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.tuscany.sca.assembly.Endpoint2; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeWire; import org.apache.tuscany.sca.work.WorkScheduler; import org.oasisopen.sca.ServiceRuntimeException; @@ -151,19 +152,19 @@ public class NonBlockingInterceptor implements Interceptor { throw new UnsupportedOperationException(); } - public EndpointReference getFrom() { + public EndpointReference2 getFrom() { return null; } - public EndpointReference getTo() { + public Endpoint2 getTo() { return null; } - public void setFrom(EndpointReference from) { + public void setFrom(EndpointReference2 from) { throw new UnsupportedOperationException(); } - public void setTo(EndpointReference to) { + public void setTo(Endpoint2 to) { throw new UnsupportedOperationException(); } @@ -178,7 +179,7 @@ public class NonBlockingInterceptor implements Interceptor { /** * @see org.apache.tuscany.sca.invocation.Message#getReplyTo() */ - public EndpointReference getReplyTo() { + public EndpointReference2 getReplyTo() { return null; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java index 831bb62bd8..649942f923 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.core.invocation; import java.lang.reflect.InvocationTargetException; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.conversation.ConversationExt; import org.apache.tuscany.sca.core.conversation.ConversationManager; import org.apache.tuscany.sca.core.conversation.ConversationState; @@ -37,7 +38,6 @@ import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeWire; @@ -61,11 +61,13 @@ public class RuntimeWireInvoker implements Invoker{ this.messageFactory = messageFactory; this.wire = wire; this.conversationManager = conversationManager; - init(wire); + //init(wire); } + /* TODO - EPR - not required for OASIS protected void init(RuntimeWire wire) { if (wire != null) { + ReferenceParameters parameters = wire.getSource().getReferenceParameters(); this.callbackID = parameters.getCallbackID(); this.callbackObject = parameters.getCallbackReference(); @@ -74,6 +76,7 @@ public class RuntimeWireInvoker implements Invoker{ this.conversational = contract.getInterface().isConversational(); } } + */ /* * TODO - Introduced to allow the RuntimeWireInvoker to sit on the end of the @@ -105,25 +108,35 @@ public class RuntimeWireInvoker implements Invoker{ } protected Object invoke(InvocationChain chain, Message msg, RuntimeWire wire) throws InvocationTargetException { - EndpointReference from = msg.getFrom(); - EndpointReference epFrom = wire.getSource(); + EndpointReference2 from = msg.getFrom(); + EndpointReference2 epFrom = wire.getEndpointReference(); if (from != null) { - from.mergeEndpoint(epFrom); + from.setComponent(epFrom.getComponent()); + from.setReference(epFrom.getReference()); + from.setBinding(epFrom.getBinding()); + from.setInterfaceContract(epFrom.getInterfaceContract()); + from.setTargetEndpoint(epFrom.getTargetEndpoint()); + from.setCallbackEndpoint(epFrom.getCallbackEndpoint()); + + // TODO - EPR - what's going on here? + //from.mergeEndpoint(epFrom); } else { msg.setFrom(epFrom); } - msg.setTo(wire.getTarget()); + msg.setTo(wire.getEndpoint()); Invoker headInvoker = chain.getHeadInvoker(); Operation operation = chain.getTargetOperation(); msg.setOperation(operation); Message msgContext = ThreadMessageContext.getMessageContext(); - Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID(); + // TODO - EPR - no required for OASIS + //Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID(); ThreadMessageContext.setMessageContext(msg); try { - conversationPreinvoke(msg); + // TODO - EPR - no required for OASIS + //conversationPreinvoke(msg); // handleCallback(msg, currentConversationID); // dispatch the wire down the chain and get the response Message resp = headInvoker.invoke(msg); @@ -138,9 +151,10 @@ public class RuntimeWireInvoker implements Invoker{ throw new ServiceRuntimeException(e); } finally { try { - conversationPostInvoke(msg); - } catch (TargetDestructionException e) { - throw new ServiceRuntimeException(e); + // TODO - EPR - no required for OASIS + //conversationPostInvoke(msg); + //} catch (TargetDestructionException e) { + // throw new ServiceRuntimeException(e); } finally { ThreadMessageContext.setMessageContext(msgContext); } @@ -150,16 +164,19 @@ public class RuntimeWireInvoker implements Invoker{ /** * @param msgContext */ + /* TODO - EPR - no required for OASIS protected EndpointReference getCallbackEndpoint(Message msgContext) { EndpointReference from = msgContext.getFrom(); return from == null ? null : from.getReferenceParameters().getCallbackReference(); } + */ /** * Pre-invoke for the conversation handling * @param msg * @throws TargetResolutionException */ + /* TODO - EPR - no required for OASIS private void conversationPreinvoke(Message msg) { if (conversational) { ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); @@ -185,6 +202,7 @@ public class RuntimeWireInvoker implements Invoker{ parameters.setConversationID(conversation.getConversationID()); } } + */ /** * Post-invoke for the conversation handling @@ -192,6 +210,7 @@ public class RuntimeWireInvoker implements Invoker{ * @param operation * @throws TargetDestructionException */ + /* TODO - EPR - no required for OASIS @SuppressWarnings("unchecked") private void conversationPostInvoke(Message msg) throws TargetDestructionException { if (conversational) { @@ -222,7 +241,7 @@ public class RuntimeWireInvoker implements Invoker{ private ScopeContainer getConversationalScopeContainer(Message msg) { ScopeContainer scopeContainer = null; - RuntimeComponent component = msg.getTo().getComponent(); + RuntimeComponent component = (RuntimeComponent) msg.getTo().getComponent(); if (component instanceof ScopedRuntimeComponent) { ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component; @@ -235,6 +254,7 @@ public class RuntimeWireInvoker implements Invoker{ return scopeContainer; } + */ /** diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java index 5ae4a24b36..f81e17c49b 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java @@ -18,7 +18,6 @@ */ package org.apache.tuscany.sca.core.invocation; -import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl; import org.apache.tuscany.sca.core.invocation.impl.MessageImpl; import org.apache.tuscany.sca.invocation.Message; @@ -33,7 +32,8 @@ public final class ThreadMessageContext { @Override protected synchronized Message initialValue() { Message msg = new MessageImpl(); - msg.setFrom(new EndpointReferenceImpl("/")); + // TODO - EPR - What to set as default? + //msg.setFrom(new EndpointReferenceImpl("/")); return msg; } }; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java index 5071a7ef94..fea1f4216b 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java @@ -27,9 +27,9 @@ import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.OptimizableBinding; -import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentReferenceImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeWireImpl2; import org.apache.tuscany.sca.core.context.CompositeContext; @@ -39,7 +39,6 @@ import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -53,13 +52,13 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; public class CallbackReferenceImpl extends CallableReferenceImpl { private RuntimeWire wire; private List wires; - private EndpointReference resolvedEndpoint; + private Endpoint2 resolvedEndpoint; private Object convID; public static CallbackReferenceImpl newInstance(Class interfaze, ProxyFactory proxyFactory, List wires) { - if (getCallbackEndpoint(ThreadMessageContext.getMessageContext()) != null) { + if (ThreadMessageContext.getMessageContext().getFrom().getCallbackEndpoint() != null) { return new CallbackReferenceImpl(interfaze, proxyFactory, wires); } else { return null; @@ -84,11 +83,14 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { wire = selectCallbackWire(msgContext); if (wire == null) { //FIXME: need better exception - throw new RuntimeException("No callback binding found for " + msgContext.getTo().getURI()); + throw new RuntimeException("No callback binding found for " + msgContext.getTo().toString()); } - resolvedEndpoint = getCallbackEndpoint(msgContext); + resolvedEndpoint = msgContext.getFrom().getCallbackEndpoint(); + + /* TODO - EPR - not required for OASIS convID = msgContext.getFrom().getReferenceParameters().getConversationID(); callbackID = msgContext.getFrom().getReferenceParameters().getCallbackID(); + */ } @Override @@ -108,26 +110,26 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { return convID; } - protected EndpointReference getResolvedEndpoint() { + protected Endpoint2 getResolvedEndpoint() { return resolvedEndpoint; } private RuntimeWire selectCallbackWire(Message msgContext) { // look for callback binding with same name as service binding - EndpointReference to = msgContext.getTo(); + Endpoint2 to = msgContext.getTo(); if (to == null) { //FIXME: need better exception throw new RuntimeException("Destination for forward call is not available"); } for (RuntimeWire wire : wires) { - if (wire.getSource().getBinding().getName().equals(to.getBinding().getName())) { + if (wire.getEndpointReference().getBinding().getName().equals(to.getBinding().getName())) { return wire; } } // if no match, look for callback binding with same type as service binding for (RuntimeWire wire : wires) { - if (wire.getSource().getBinding().getClass() == to.getBinding().getClass()) { + if (wire.getEndpointReference().getBinding().getClass() == to.getBinding().getClass()) { return wire; } } @@ -136,20 +138,6 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { return null; } - /** - * Gets the endpoint reference from the incoming message that points - * back to the callback service - * - * @param msgContext - */ - private static EndpointReference getCallbackEndpoint(Message msgContext) { - EndpointReference from = msgContext.getFrom(); - if (from == null) { - return null; - } - return from.getReferenceParameters().getCallbackReference(); - } - private RuntimeWire cloneAndBind(RuntimeWire wire) { RuntimeWire boundWire = null; if (resolvedEndpoint != null) { @@ -158,7 +146,20 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { return boundWire; } try { - Contract contract = resolvedEndpoint.getContract(); + // TODO - EPR - is this correct? + + // Fluff up a new response wire based on the callback endpoint + RuntimeComponentReference ref = + bind((RuntimeComponentReference)wire.getEndpointReference().getReference(), + resolvedEndpoint); + + boundWire = ref.getRuntimeWires().get(0); + + Binding binding = wire.getEndpointReference().getBinding(); + binding.setURI(resolvedEndpoint.getBinding().getURI()); + +/* TODO - EPR - remove as there are no callback objects now + * Contract contract = resolvedEndpoint.getContract(); RuntimeComponentReference ref = null; if (contract == null) { //TODO - EPR - does it ever go through here? @@ -177,24 +178,27 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { // TODO - EPR - get the wire from the reference that matches the // injected callback reference wire. We don't have bindings yet as the // callback object wire hasn't been initialized -/* - for (RuntimeWire runtimeWire : ref.getRuntimeWires()){ - if (runtimeWire.getEndpointReference().getBinding().getName().equals(wire.getEndpointReference().getBinding().getName())){ - boundWire = runtimeWire; - break; - } - } -*/ + +// for (RuntimeWire runtimeWire : ref.getRuntimeWires()){ +// if (runtimeWire.getEndpointReference().getBinding().getName().equals(wire.getEndpointReference().getBinding().getName())){ +// boundWire = runtimeWire; +// break; +// } +// } + // just get the first one for now boundWire = ref.getRuntimeWires().get(0); } else { // contract instanceof RuntimeComponentService //TODO - EPR - I think it does this if no callback object has been set explicitly - ref = bind((RuntimeComponentReference)wire.getSource().getContract(), + ref = bind((RuntimeComponentReference)wire.getEndpointReference().getReference(), resolvedEndpoint); boundWire = ref.getRuntimeWires().get(0); } + configureWire(boundWire); +*/ + ((RuntimeWireImpl2)wire).addToCache(resolvedEndpoint, boundWire); } catch (CloneNotSupportedException e) { // will not happen @@ -205,13 +209,15 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { // TODO - EPR - why static & convert to ne endpoint reference private static RuntimeComponentReference bind(RuntimeComponentReference reference, - EndpointReference resolvedEndpoint) throws CloneNotSupportedException { - RuntimeComponent component = resolvedEndpoint.getComponent(); - RuntimeComponentService service = (RuntimeComponentService)resolvedEndpoint.getContract(); + Endpoint2 resolvedEndpoint) throws CloneNotSupportedException { + RuntimeComponent component = (RuntimeComponent)resolvedEndpoint.getComponent(); + RuntimeComponentService service = (RuntimeComponentService)resolvedEndpoint.getService(); RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone(); ref.getTargets().add(service); ref.getBindings().clear(); + + /* TODO - EPR - don't think this is require now we have endpoint references for (Binding binding : service.getBindings()) { if (binding instanceof OptimizableBinding) { OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone(); @@ -223,6 +229,7 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { ref.getBindings().add(binding); } } + */ ref.getEndpointReferences().clear(); @@ -230,10 +237,10 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { EndpointReference2 clone = (EndpointReference2)endpointReference.clone(); clone.setReference(ref); - clone.getBinding().setURI(resolvedEndpoint.getURI()); + clone.getBinding().setURI(resolvedEndpoint.getBinding().getURI()); clone.getTargetEndpoint().setComponent(resolvedEndpoint.getComponent()); - clone.getTargetEndpoint().setService((ComponentService)resolvedEndpoint.getContract()); + clone.getTargetEndpoint().setService((ComponentService)resolvedEndpoint.getService()); clone.getTargetEndpoint().setBinding(resolvedEndpoint.getBinding()); ref.getEndpointReferences().add(clone); @@ -242,27 +249,29 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { return ref; } + /* TODO - EPR - remove private void configureWire(RuntimeWire wire ) { - // TODO - EPR - do we actiually need this code? Combine with bind? + // TODO - EPR - do we actually need this code? Combine with bind? // need to set the endpoint on the binding also so that when the chains are created next // the sca binding can decide whether to provide local or remote invokers. // TODO - there is a problem here though in that I'm setting a target on a // binding that may possibly be trying to point at two things in the multi threaded // case. Need to confirm the general model here and how the clone and bind part // is intended to work - Binding binding = wire.getSource().getBinding(); - binding.setURI(resolvedEndpoint.getURI()); + Binding binding = wire.getEndpointReference().getBinding(); + binding.setURI(resolvedEndpoint.getBinding().getURI()); // set the target contract as it varies for the sca binding depending on // whether it is local or remote - RuntimeComponentReference ref = (RuntimeComponentReference)wire.getSource().getContract(); + RuntimeComponentReference ref = (RuntimeComponentReference)wire.getEndpointReference().getReference(); // TODO - EPR // needs to be set after the chains have been created for the first time // as now the binding provider won't be created until that time //wire.getEndpointReference().getTargetEndpoint().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract()); } + */ /** * {@inheritDoc} @@ -282,9 +291,10 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { final InterfaceContract targetServiceIfaceContract = targetService.getInterfaceContract(); // Re-create the resolved Endpoint - this.resolvedEndpoint = new EndpointReferenceImpl( - (RuntimeComponent) targetComponent, targetService, null, - targetServiceIfaceContract); + this.resolvedEndpoint = assemblyFactory.createEndpoint(); + this.resolvedEndpoint.setComponent(targetComponent); + this.resolvedEndpoint.setService(targetService); + this.resolvedEndpoint.setInterfaceContract(targetServiceIfaceContract); // Copy the Java Interface from the Service final JavaInterface ji = (JavaInterface) targetServiceIfaceContract.getInterface(); @@ -300,11 +310,12 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { throw new IOException(e.toString()); } + // TODO - EPR - This doesn't sound right to me. // Setup the reference on the cloned wire final RuntimeComponentReference ref = new RuntimeComponentReferenceImpl(); ref.setComponent((RuntimeComponent) targetComponent); ref.setInterfaceContract(targetServiceIfaceContract); - ((EndpointReferenceImpl) this.wire.getSource()).setContract(ref); + ((EndpointReference2) this.wire.getEndpointReference()).setReference(ref); } /** @@ -315,6 +326,8 @@ public class CallbackReferenceImpl extends CallableReferenceImpl { super.writeExternal(out); out.writeObject(this.callbackID); out.writeObject(this.convID); - out.writeUTF(this.resolvedEndpoint.getURI()); + + // TODO - EPR - What to do about URI? + out.writeUTF(this.resolvedEndpoint.getBinding().getURI()); } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java index 9a0540915a..460df7b007 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java @@ -60,7 +60,8 @@ public class JDKCallbackInvocationHandler extends JDKInvocationHandler { // set the conversational state based on the interface that // is specified for the reference that this wire belongs to - initConversational(wire); + // TODO - EPR - not required for OASIS + //initConversational(wire); // set the conversation id into the conversation object. This is // a special case for callbacks as, unless otherwise set manually, @@ -94,7 +95,7 @@ public class JDKCallbackInvocationHandler extends JDKInvocationHandler { } try { - return invoke(chain, args, wire, wire.getSource()); + return invoke(chain, args, wire, wire.getEndpointReference()); } catch (InvocationTargetException e) { Throwable t = e.getCause(); if (t instanceof NoRegisteredCallbackException) { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java index a4a2d8c99a..06d9d7aa77 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import org.apache.tuscany.sca.assembly.Endpoint2; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.core.assembly.impl.RuntimeWireImpl2; import org.apache.tuscany.sca.core.context.CallableReferenceExt; import org.apache.tuscany.sca.core.context.impl.CallableReferenceImpl; @@ -51,7 +53,6 @@ import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeWire; @@ -69,8 +70,8 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { protected boolean conversational; protected ConversationExt conversation; protected MessageFactory messageFactory; - protected EndpointReference source; - protected EndpointReference target; + protected EndpointReference2 source; + protected Endpoint2 target; protected RuntimeWire wire; protected CallableReference callableReference; protected Class businessInterface; @@ -100,7 +101,8 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { } protected void init(RuntimeWire wire) { - // TODO - EPR needs fixing when we remove the old EndpointReference + // TODO - EPR not required for OASIS + /* if (wire != null) { try { // Clone the endpoint reference so that reference parameters can be changed @@ -110,12 +112,15 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { } initConversational(wire); } + */ } + /* TODO - EPR - not required for OASIS protected void initConversational(RuntimeWire wire) { InterfaceContract contract = wire.getSource().getInterfaceContract(); this.conversational = contract.getInterface().isConversational(); } + */ protected Object getCallbackID() { if (callableReference != null) { @@ -156,7 +161,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { // The EndpointReference is not now resolved until the invocation chain // is first created so reset the source here - source = wire.getSource(); + source = wire.getEndpointReference(); // send the invocation down the wire Object result = invoke(chain, args, wire, source); @@ -265,18 +270,18 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { return found; } - protected void setEndpoint(EndpointReference endpoint) { + protected void setEndpoint(Endpoint2 endpoint) { this.target = endpoint; } - protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire, EndpointReference source) + protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire, EndpointReference2 source) throws Throwable { Message msg = messageFactory.createMessage(); msg.setFrom(source); if (target != null) { msg.setTo(target); } else { - msg.setTo(wire.getTarget()); + msg.setTo(wire.getEndpoint()); } Invoker headInvoker = chain.getHeadInvoker(); Operation operation = chain.getTargetOperation(); @@ -284,10 +289,12 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { msg.setBody(args); Message msgContext = ThreadMessageContext.getMessageContext(); - Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID(); - - conversationPreinvoke(msg, wire); - handleCallback(msg, wire, currentConversationID); + + // TODO - EPR - not required for OASIS + //Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID(); + //conversationPreinvoke(msg, wire); + + handleCallback(msg, wire); ThreadMessageContext.setMessageContext(msg); boolean abnormalEndConversation = false; try { @@ -295,6 +302,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { Message resp = headInvoker.invoke(msg); Object body = resp.getBody(); if (resp.isFault()) { + /* TODO - EPR - not required in OASIS // mark the conversation as ended if the exception is not a business exception if (currentConversationID != null ){ try { @@ -315,11 +323,12 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { // a system exception in the middle of a business exception } } + */ throw (Throwable)body; } return body; } finally { - conversationPostInvoke(msg, wire, abnormalEndConversation); + //conversationPostInvoke(msg, wire, abnormalEndConversation); ThreadMessageContext.setMessageContext(msgContext); } } @@ -330,14 +339,17 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { * @param interfaze * @throws TargetResolutionException */ - private void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID) + private void handleCallback(Message msg, RuntimeWire wire) throws TargetResolutionException { - ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); - parameters.setCallbackID(getCallbackID()); + + //ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + //parameters.setCallbackID(getCallbackID()); + if (msg.getFrom() == null || msg.getFrom().getCallbackEndpoint() == null) { return; } + /* TODO - EPR - not required for OASIS parameters.setCallbackReference(msg.getFrom().getCallbackEndpoint()); // If we are passing out a callback target @@ -386,6 +398,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { } } } + */ } /** @@ -393,6 +406,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { * @param msg * @throws TargetResolutionException */ + /* TODO - EPR - not required for OASIS private void conversationPreinvoke(Message msg, RuntimeWire wire) { if (!conversational) { // Not conversational or the conversation has been started @@ -407,8 +421,8 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { // if this is a local wire then set up the conversation timeouts here based on the // parameters from the component - if (wire.getTarget().getComponent() != null){ - conversation.initializeConversationAttributes(wire.getTarget().getComponent()); + if (wire.getEndpoint().getComponent() != null){ + conversation.initializeConversationAttributes((RuntimeComponent)wire.getEndpoint().getComponent()); } // connect the conversation to the CallableReference so it can be retrieve in the future @@ -422,13 +436,14 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { // if this is a local wire then schedule conversation timeouts based on the timeout // parameters from the service implementation. If this isn't a local wire then // the RuntimeWireInvoker will take care of this - if (wire.getTarget().getComponent() != null){ + if (wire.getEndpoint().getComponent() != null){ conversation.updateLastReferencedTime(); } msg.getFrom().getReferenceParameters().setConversationID(conversation.getConversationID()); } + */ /** * Post-invoke for the conversation handling @@ -436,6 +451,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { * @param operation * @throws TargetDestructionException */ + /* TODO - not required for OASIS @SuppressWarnings("unchecked") private void conversationPostInvoke(Message msg, RuntimeWire wire, boolean abnormalEndConversation) throws TargetDestructionException { @@ -457,11 +473,12 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { conversation.end(); } } + private ScopeContainer getConversationalScopeContainer(RuntimeWire wire) { ScopeContainer scopeContainer = null; - RuntimeComponent runtimeComponent = wire.getSource().getComponent(); + RuntimeComponent runtimeComponent = (RuntimeComponent)wire.getEndpointReference().getComponent(); if (runtimeComponent instanceof ScopedRuntimeComponent) { ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)runtimeComponent; @@ -474,12 +491,14 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { return scopeContainer; } + */ /** * Creates a new conversation id * * @return the conversation id */ + /* TODO - EPR - not required for OASIS private Object createConversationID() { if (getConversationID() != null) { return getConversationID(); @@ -487,6 +506,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { return UUID.randomUUID().toString(); } } + */ /** * @return the callableReference diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/MessageImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/MessageImpl.java index e81e5a2f31..bd7b9dcb8f 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/MessageImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/MessageImpl.java @@ -21,10 +21,10 @@ package org.apache.tuscany.sca.core.invocation.impl; import java.util.ArrayList; import java.util.List; -import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl; +import org.apache.tuscany.sca.assembly.Endpoint2; +import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.EndpointReference; /** * The default implementation of a message flowed through a wire during an invocation @@ -38,12 +38,15 @@ public class MessageImpl implements Message { private boolean isFault; private Operation operation; - private EndpointReference from; - private EndpointReference to; + private EndpointReference2 from; + private Endpoint2 to; public MessageImpl() { - this.from = new EndpointReferenceImpl("/"); - this.to = new EndpointReferenceImpl("/"); + // TODO - EPR - What to do by default? + //this.from = new EndpointReferenceImpl("/"); + //this.to = new EndpointReferenceImpl("/"); + this.from = null; + this.to = null; } @SuppressWarnings("unchecked") @@ -73,19 +76,19 @@ public class MessageImpl implements Message { this.body = fault; } - public EndpointReference getFrom() { + public EndpointReference2 getFrom() { return from; } - public void setFrom(EndpointReference from) { + public void setFrom(EndpointReference2 from) { this.from = from; } - public EndpointReference getTo() { + public Endpoint2 getTo() { return to; } - public void setTo(EndpointReference to) { + public void setTo(Endpoint2 to) { this.to = to; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/impl/ConversationalScopeContainer.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/impl/ConversationalScopeContainer.java index 1ae7bd58e1..8dfe77f61b 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/impl/ConversationalScopeContainer.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/impl/ConversationalScopeContainer.java @@ -72,7 +72,8 @@ public class ConversationalScopeContainer extends AbstractScopeContainer Message msgContext = ThreadMessageContext.getMessageContext(); if (msgContext != null) { - msgContext.getFrom().getReferenceParameters().setConversationID(contextId); + // TODO - EPR - not required for OASIS + //msgContext.getFrom().getReferenceParameters().setConversationID(contextId); } } -- cgit v1.2.3