summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-03-13 12:41:03 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-03-13 12:41:03 +0000
commitbe1ca467c11eee84715161105630a55706b5d73b (patch)
tree2ddb7fdecddbbb7e8824af3a3e6d25704df7a3cf /java
parent1a795d48e4fec8a97087589323d06dba30883feb (diff)
Bring up the EnpointRefence code. I've done as much as I can now without actually changing existing code. So I'll go ahead with those changes locally and post a summary of where I'm up to.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@753224 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java22
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java7
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java12
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java38
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java33
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java28
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java506
7 files changed, 208 insertions, 438 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java
index 78cb2487d5..99f6e08e82 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointReference2.java
@@ -85,14 +85,14 @@ public interface EndpointReference2 extends Base, PolicySubject, Cloneable {
*
* @return callbackBinding the reference callback binding
*/
- Binding getCallbackBinding();
+// Binding getCallbackBinding();
/**
* Set the reference callback binding
*
* @param callbackBinding the reference callback binding
*/
- void setCallbackBinding(Binding callbackBinding);
+// void setCallbackBinding(Binding callbackBinding);
/**
* Get the name of the target service that this endpoint reference refers to
@@ -136,6 +136,24 @@ public interface EndpointReference2 extends Base, PolicySubject, Cloneable {
*/
void setInterfaceContract(InterfaceContract interfaceContract);
+ /**
+ * Get the reference callback endpoint that
+ * represents that target endpoint to which callback
+ * messages will be directed
+ *
+ * @return callbackEndpoint the reference callback endpoint
+ */
+ Endpoint2 getCallbackEndpoint();
+
+ /**
+ * Set the reference callback endpoint
+ *
+ * @param callbackEndpoint the reference callback endpoint
+ */
+ void setCallbackEndpoint(Endpoint2 callbackEndpoint);
+
+
+
// not sure the methods below are required
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java
index ceeef8f983..10307ed3c3 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java
@@ -146,9 +146,12 @@ public abstract class BaseBuilderImpl implements CompositeBuilder {
*/
protected void indexServices(Composite composite,
Map<String, ComponentService> componentServices) {
- ComponentService nonCallbackService = null;
- int nonCallbackServiceCount = 0;
+
for (Component component : composite.getComponents()) {
+
+ ComponentService nonCallbackService = null;
+ int nonCallbackServiceCount = 0;
+
for (ComponentService componentService : component.getServices()) {
// Index component services by component name / service name
String uri = component.getName() + '/' + componentService.getName();
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
index 3fc0a0aa32..213c7d6ae7 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
@@ -225,12 +225,8 @@ public class CompositeBuilderImpl implements CompositeBuilder {
compositeServiceEndpointBuilder.build(composite, definitions, monitor);
// create reference enpointreference models
compositeReferenceEndpointReferenceBuilder.build(composite, definitions, monitor);
-
- // TODO this needs to be offloaded to a plugpoint
- // could be called upon when rebuilding wires
- // wire endpoint references to endpoints
- endpointReferenceBuilder.build(composite, definitions, monitor);
// ===============================================
+
// Wire the components
componentReferenceWireBuilder.build(composite, definitions, monitor);
@@ -244,6 +240,12 @@ public class CompositeBuilderImpl implements CompositeBuilder {
// Build component reference binding-related information
componentReferenceBindingBuilder.build(composite, definitions, monitor);
+ // ===============================================
+ // TODO this needs to be offloaded to a plugpoint
+ // could be called upon when rebuilding wires
+ // wire endpoint references to endpoints
+ endpointReferenceBuilder.build(composite, definitions, monitor);
+ // ===============================================
}
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java
index 28afd1d177..18083da779 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceEndpointReferenceBuilderImpl.java
@@ -326,41 +326,31 @@ public class CompositeReferenceEndpointReferenceBuilderImpl extends BaseBuilderI
continue;
}
- // user might have put a local target name in the uri so get
- // the path part and see if it refers to a target we know about
+ // user might have put a local target name in the uri
+ // see if it refers to a target we know about
// - if it does the reference binding will be matched with a
// service binding
// - if it doesn't it is assumed to be an external reference
Component targetComponent = null;
ComponentService targetComponentService = null;
- String path = null;
- try {
- path = URI.create(uri).getPath();
- } catch (Exception ex) {
- // just assume that no target is identified if
- // a URI related exception is thrown
- }
- if (path != null) {
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
+ if (uri.startsWith("/")) {
+ uri = uri.substring(1);
+ }
- // Resolve the target component and service
- targetComponentService = componentServices.get(path);
- int s = path.indexOf('/');
- if (s == -1) {
- targetComponent = components.get(path);
- } else {
- targetComponent = components.get(path.substring(0, s));
- }
+ // Resolve the target component and service
+ targetComponentService = componentServices.get(uri);
+ int s = uri.indexOf('/');
+ if (s == -1) {
+ targetComponent = components.get(uri);
+ } else {
+ targetComponent = components.get(uri.substring(0, s));
}
- // if the path of the binding URI matches a component in the
+ // if the binding URI matches a component in the
// composite then configure an endpoint reference with this component as
- // the target
- // if not then the binding URI will be assumed to reference an
+ // the target. If not then the binding URI will be assumed to reference an
// external service
if (targetComponentService != null) {
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java
index 595333ca41..ad724536c7 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java
@@ -107,7 +107,7 @@ public class EndpointReference2BuilderImpl extends BaseBuilderImpl implements Co
processComponentReferences((Composite)implementation, monitor);
}
- // create endpoint references to represent the component reference
+ // build endpoint references
for (ComponentReference reference : component.getReferences()) {
for (EndpointReference2 endpointReference : reference.getEndpointReferences()){
build(endpointReference, monitor);
@@ -255,8 +255,7 @@ public class EndpointReference2BuilderImpl extends BaseBuilderImpl implements Co
if (matchedReferenceBinding.isEmpty()) {
// No matching binding
- endpointReference.setBinding(null);
- endpointReference.setTargetEndpoint(null);
+ endpointReference.setCallbackEndpoint(null);
warning(monitor,
"NoMatchingCallbackBinding",
endpointReference.getReference(),
@@ -274,25 +273,19 @@ public class EndpointReference2BuilderImpl extends BaseBuilderImpl implements Co
}
}
- Binding referenceBinding = matchedReferenceBinding.get(selectedBinding);
- Binding serviceBinding = matchedServiceBinding.get(selectedBinding);
+ Binding selectedCallbackBinding = matchedReferenceBinding.get(selectedBinding);
+
+ ComponentService callbackService = endpointReference.getReference().getCallbackService();
- // populate the endpoint reference
- try {
-
- Binding cloned = (Binding)referenceBinding.clone();
-
- // Set the binding URI to the URI of the target service
- // that has been matched
- if (referenceBinding.getURI() == null) {
- cloned.setURI(serviceBinding.getURI());
+ if (callbackService != null) {
+ // find the callback endpoint that has the selected binding
+ for (Endpoint2 endpoint : callbackService.getEndpoints()){
+ if (endpoint.getBinding().getName().startsWith(selectedCallbackBinding.getName())){
+ endpointReference.setCallbackEndpoint(endpoint);
+ break;
+ }
}
-
- endpointReference.setCallbackBinding(referenceBinding);
-
- } catch (Exception ex) {
- // do nothing
- }
+ }
}
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java
index f59bf519f4..699d2e89f4 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointReference2Impl.java
@@ -39,18 +39,24 @@ import org.apache.tuscany.sca.policy.PolicySubject;
*/
public class EndpointReference2Impl implements EndpointReference2 {
+ // this endpoint reference
private Boolean unresolved = true;
private Component component;
private ComponentReference reference;
private Binding binding;
- private Binding callbackBinding;
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+
+ // the target of the endpoint reference
private String targetName;
private Endpoint2 targetEndpoint;
private InterfaceContract interfaceContract;
-// private String uri;
- private List<PolicySet> policySets = new ArrayList<PolicySet>();
- private List<Intent> requiredIntents = new ArrayList<Intent>();
-
+// private String uri;
+
+ // callback that messages across this reference
+ // will be directed toward
+ private Endpoint2 callbackEndpoint;
+
protected EndpointReference2Impl() {
}
@@ -91,6 +97,7 @@ public class EndpointReference2Impl implements EndpointReference2 {
this.binding = binding;
}
+/*
public Binding getCallbackBinding() {
return callbackBinding;
}
@@ -98,6 +105,7 @@ public class EndpointReference2Impl implements EndpointReference2 {
public void setCallbackBinding(Binding callbackBinding) {
this.callbackBinding = callbackBinding;
}
+*/
public String getTargetName() {
return targetName;
@@ -115,8 +123,6 @@ public class EndpointReference2Impl implements EndpointReference2 {
this.targetEndpoint = targetEndpoint;
}
-
-
public InterfaceContract getInterfaceContract() {
return interfaceContract;
}
@@ -153,4 +159,12 @@ public class EndpointReference2Impl implements EndpointReference2 {
public void setType(ExtensionType type) {
throw new UnsupportedOperationException();
}
+
+ public Endpoint2 getCallbackEndpoint() {
+ return callbackEndpoint;
+ }
+
+ public void setCallbackEndpoint(Endpoint2 callbackEndpoint) {
+ this.callbackEndpoint = callbackEndpoint;
+ }
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java
index a1c99c97fc..3f93bf7cdd 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java
@@ -296,8 +296,8 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
logger.fine("Activating component service: " + component.getURI() + "#" + service.getName());
}
- for (Binding binding : service.getBindings()) {
- addServiceBindingProvider(component, service, binding);
+ for (Endpoint2 endpoint : service.getEndpoints()) {
+ addServiceBindingProvider(component, service, endpoint.getBinding());
}
addServiceWires(component, service);
}
@@ -415,33 +415,36 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
// Reference activation/deactivation
- public void activate(RuntimeComponent component, RuntimeComponentReference ref) {
+ public void activate(RuntimeComponent component, RuntimeComponentReference reference) {
if (logger.isLoggable(Level.FINE)) {
- logger.fine("Activating component reference: " + component.getURI() + "#" + ref.getName());
+ logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName());
}
- resolveTargets(ref);
- for (Binding binding : ref.getBindings()) {
- addReferenceBindingProvider(component, ref, binding);
+
+ // TODO this may need to move into the code where we check that an endpoint is resolved
+ for (EndpointReference2 endpointReference : reference.getEndpointReferences()) {
+ if (endpointReference.getBinding() != null){
+ addReferenceBindingProvider(component, reference, endpointReference.getBinding());
+ }
}
- for (Endpoint endpoint : ref.getEndpoints()){
- // TODO - source component should be set in the builder but the
- // way the builder is written it's difficult to get at it
- endpoint.setSourceComponent(component);
-
- addEndpointResolver(component, ref, endpoint);
- }
+ // set the parent component onto the reference. It's used at start time when the
+ // reference is asked to return it's runtime wires. If there are none the reference
+ // asks the component context to start the reference which creates the wires
+ reference.setComponent(component);
+
+ // TODO reference wires are added at component start for some reason
}
- public void deactivate(RuntimeComponent component, RuntimeComponentReference ref) {
+ public void deactivate(RuntimeComponent component, RuntimeComponentReference reference) {
if (logger.isLoggable(Level.FINE)) {
- logger.fine("Deactivating component reference: " + component.getURI() + "#" + ref.getName());
+ logger.fine("Deactivating component reference: " + component.getURI() + "#" + reference.getName());
}
- removeReferenceWires(ref);
- for (Binding binding : ref.getBindings()) {
- removeReferenceBindingProvider(component, ref, binding);
+ removeReferenceWires(reference);
+ for (EndpointReference2 endpointReference : reference.getEndpointReferences()) {
+ if (endpointReference.getBinding() != null){
+ removeReferenceBindingProvider(component, reference, endpointReference.getBinding());
+ }
}
-
}
private ReferenceBindingProvider addReferenceBindingProvider(
@@ -488,6 +491,17 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
}
+ private void removeReferenceWires(ComponentReference reference) {
+ if (!(reference instanceof RuntimeComponentReference)) {
+ return;
+ }
+
+ // TODO - what is this all about?
+ // [rfeng] Comment out the following statements to avoid the on-demand activation
+ // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+ // runtimeRef.getRuntimeWires().clear();
+ }
+
//=========================================================================
// Start
//=========================================================================
@@ -525,6 +539,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
configureComponentContext(runtimeComponent);
+/* TODO - won't start until reference is actually started later
for (ComponentReference reference : component.getReferences()) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
@@ -532,19 +547,6 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
runtimeRef.setComponent(runtimeComponent);
- for (Endpoint endpoint : reference.getEndpoints()) {
- final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint);
- if (endpointResolver != null) {
- // Allow endpoint resolvers to do any startup reference manipulation
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- endpointResolver.start();
- return null;
- }
- });
- }
- }
-
for (Binding binding : reference.getBindings()) {
final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
if (bindingProvider != null) {
@@ -558,14 +560,15 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
}
}
+*/
for (ComponentService service : component.getServices()) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Starting component service: " + component.getURI() + "#" + service.getName());
}
RuntimeComponentService runtimeService = (RuntimeComponentService)service;
- for (Binding binding : service.getBindings()) {
- final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(binding);
+ for (Endpoint2 endpoint : service.getEndpoints()) {
+ final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding());
if (bindingProvider != null) {
// bindingProvider.start();
// Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
@@ -610,8 +613,8 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName());
}
- for (Binding binding : service.getBindings()) {
- final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(binding);
+ for (Endpoint2 endpoint : service.getEndpoints()) {
+ final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(endpoint.getBinding());
if (bindingProvider != null) {
// Allow bindings to read properties. Requires PropertyPermission read in security policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@@ -629,8 +632,8 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
- for (Binding binding : reference.getBindings()) {
- final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
+ for (EndpointReference2 endpointReference : reference.getEndpointReferences()) {
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
if (bindingProvider != null) {
// Allow bindings to read properties. Requires PropertyPermission read in security policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@@ -640,20 +643,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
});
}
- }
-
- for (Endpoint endpoint : reference.getEndpoints()) {
- final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint);
- if (endpointResolver != null) {
- // Allow endpoint resolvers to do any shutdown reference manipulation
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- endpointResolver.stop();
- return null;
- }
- });
- }
- }
+ }
}
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
@@ -682,32 +672,62 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
((RuntimeComponent)component).setStarted(false);
}
+ public void configureComponentContext(RuntimeComponent runtimeComponent) {
+ RuntimeComponentContext componentContext = (RuntimeComponentContext) componentContextFactory.createComponentContext(runtimeComponent);
+ runtimeComponent.setComponentContext(componentContext);
+ }
+
// Service start/stop
- // ????
+ // TODO - done as part of the component start above
// Reference start/stop
- // Used by component context?
+ // Used by component context start
+ // TODO - I don't know why reference wires don't get added until component start
- public void start(RuntimeComponent component, RuntimeComponentReference ref) {
- synchronized (ref) {
- resolveTargets(ref);
- for (Binding binding : ref.getBindings()) {
- ReferenceBindingProvider provider = ref.getBindingProvider(binding);
- if (provider == null) {
- provider = addReferenceBindingProvider(component, ref, binding);
- }
- if (provider != null) {
- provider.start();
- }
- addReferenceWire(component, ref, binding);
- }
+ public void start(RuntimeComponent component, RuntimeComponentReference componentReference) {
+ synchronized (componentReference) {
- // targets now have an endpoint representation. We can use this to
- // look for unresolved endpoints using dummy wires for late resolution
- for (Endpoint endpoint : ref.getEndpoints()){
- addReferenceEndpointWire(component, ref, endpoint);
+ if (!(componentReference instanceof RuntimeComponentReference)) {
+ return;
}
+
+ // create wire for all endpoint references. An endpoint reference says that a
+ // target has been specified and hence the reference has been wired in some way.
+ // The service may not have been found yet, depending on the way the composite
+ // is deployed, but it is expected to be found. In the case where the reference
+ // is unwired (a target has not been specified) there will be no endpoint
+ // reference and this will lead to null being injected
+
+ for (EndpointReference2 endpointReference : componentReference.getEndpointReferences()){
+
+ // if there is a binding an endpoint has been found for the endpoint reference
+ if (endpointReference.getBinding() != null){
+
+ // add the binding provider
+ RuntimeComponentReference runtimeRef = (RuntimeComponentReference)componentReference;
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
+
+/* TODO - Is this actually required
+ if (bindingProvider == null) {
+ bindingProvider = addReferenceBindingProvider(component, componentReference, endpointReference.getBinding());
+ }
+*/
+ // start the binding provider
+ if (bindingProvider != null) {
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.start();
+ return null;
+ }
+ });
+ }
+
+ // add the wire
+ addReferenceWire(component, componentReference, endpointReference);
+ }
+ }
}
}
@@ -716,221 +736,19 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName());
}
RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
- for (Binding binding : reference.getBindings()) {
- ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
+ for ( EndpointReference2 endpointReference : runtimeRef.getEndpointReferences()){
+ ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
if (bindingProvider != null) {
bindingProvider.stop();
}
}
}
-
-
-
-
-
-
- //========================================================
- //========================================================
- //========================================================
- //========================================================
-
-
-
-
-
-
-
- /**
- * @param component
- * @param reference
- * @param binding
- */
- private EndpointResolver addEndpointResolver(RuntimeComponent component,
- RuntimeComponentReference reference,
- Endpoint endpoint){
-
- // only create endpoint resolvers for unresolved endpoints currently
- // this will also prevent a wire from being created later
- if (!endpoint.isUnresolved()){
- return null;
- }
-
- // This souldn't happen as the endpoint resolver extension point is in core-spi but
- // just in case returning null here will mean that no wire is created and calling
- // the reference will fail with NPE
- if (endpointResolverFactories == null){
- return null;
- }
-
- EndpointResolverFactory<Endpoint> resolverFactory =
- (EndpointResolverFactory<Endpoint>)endpointResolverFactories.getEndpointResolverFactory(endpoint.getClass());
-
- if (resolverFactory != null) {
- EndpointResolver endpointResolver =
- resolverFactory.createEndpointResolver(endpoint, null);
- if (endpointResolver != null) {
- ((RuntimeComponentReference)reference).setEndpointResolver(endpoint, endpointResolver);
- }
-
- return endpointResolver;
- } else {
- // TODO - for the time being allow the lack of an endpoint provider to be the
- // switch to turn off endpoint processing
- return null;
- //throw new IllegalStateException("Endpoint provider factory not found for class: " + endpoint.getClass().getName());
- }
- }
-
- public void addReferenceBindingProviderForEndpoint(Endpoint endpoint){
- addReferenceBindingProvider((RuntimeComponent)endpoint.getSourceComponent(),
- (RuntimeComponentReference)endpoint.getSourceComponentReference(),
- endpoint.getSourceBinding());
- }
-
- /**
- * @param component
- * @param reference
- * @param binding
- */
-
-
- /**
- * @param reference
- */
- private void resolveTargets(RuntimeComponentReference reference) {
- // The code that used to be here to resolved unresolved targets is now
- // at the bottom of BaseWireBuilder.connectComponentReferences()
- }
-
- /**
- * Create the runtime wires for a reference endpoint. Currently this method
- * only deals with the late binding case and creates a dummy wire that
- * will use the Endpoint to resolve the target at the point when the
- * wire chains are created.
- *
- * @param component
- * @param reference
- * @param binding
- */
- private void addReferenceEndpointWire(Component component, ComponentReference reference, Endpoint endpoint) {
- // only deal with unresolved endpoints as, to prevent breaking changes, targets that are resolved
- // at build time are still represented as bindings in the binding list
- if (((RuntimeComponentReference)reference).getEndpointResolver(endpoint) == null){
- // no endpoint provider has previously been created so don't create the
- // wire
- return;
- }
-
- // TODO: TUSCANY-2580: avoid NPE if the InterfaceCOntract is null
- Reference ctref = endpoint.getSourceComponentReference().getReference();
- if (ctref != null && ctref.getInterfaceContract() == null) {
- ctref.setInterfaceContract(reference.getInterfaceContract());
- }
-
- RuntimeWire wire = new EndpointWireImpl(endpoint, this);
-
+ private void addReferenceWire(Component component, ComponentReference reference, EndpointReference2 endpointReference) {
RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
- runtimeRef.getRuntimeWires().add(wire);
- }
-
-
- /**
- * Create the runtime wires for a reference binding
- *
- * @param component
- * @param reference
- * @param binding
- */
- private void addReferenceWire(Component component, ComponentReference reference, Binding binding) {
- if (!(reference instanceof RuntimeComponentReference)) {
- return;
- }
- // create wire if binding has an endpoint
- Component targetComponent = null;
- ComponentService targetComponentService = null;
- Binding targetBinding = null;
-
- if (binding instanceof OptimizableBinding) {
- OptimizableBinding endpoint = (OptimizableBinding)binding;
- targetComponent = endpoint.getTargetComponent();
- targetComponentService = endpoint.getTargetComponentService();
- targetBinding = endpoint.getTargetBinding();
- // FIXME: TUSCANY-2136, For unresolved binding, don't add wire. Is it the right solution?
- if (!reference.isCallback() && binding.getURI() == null && targetComponentService == null) {
- return;
- }
- }
-
- // create a forward wire, either static or dynamic
- addReferenceWire(component, reference, binding, targetComponent, targetComponentService, targetBinding);
-
- /*
- // if static forward wire (not from self-reference), try to create a static callback wire
- if (targetComponentService != null && !reference.getName().startsWith("$self$.")) {
- ComponentReference callbackReference = targetComponentService.getCallbackReference();
- if (callbackReference != null) {
- Binding callbackBinding = null;
- Binding callbackServiceBinding = null;
- // select a service callback binding that can be wired back to this component
- for (Binding refBinding : callbackReference.getBindings()) {
- // first look for a callback binding whose name matches the target binding name
- if (refBinding.getName().equals(targetBinding.getName())) {
- callbackBinding = refBinding;
- break;
- }
- }
- // see if there is a matching reference callback binding
- if (callbackBinding != null) {
- callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
- }
- // if there isn't an end-to-end match, try again based on target binding type
- if (callbackBinding == null || callbackServiceBinding == null) {
- callbackBinding = callbackReference.getBinding(targetBinding.getClass());
- if (callbackBinding != null) {
- callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
- }
- }
- if (callbackBinding != null && callbackServiceBinding != null) {
- // end-to-end match, so create a static callback wire as well as the static forward wire
-
- addReferenceWire(targetComponent, callbackReference, callbackBinding, component, reference
- .getCallbackService(), callbackServiceBinding);
- } else {
- // no end-to-end match, so do not create a static callback wire
- }
- }
- }
- */
- }
-
- public void addReferenceWireForEndpoint(Endpoint endpoint){
- addReferenceWire(endpoint.getSourceComponent(),
- endpoint.getSourceComponentReference(),
- endpoint.getSourceBinding(),
- endpoint.getTargetComponent(),
- endpoint.getTargetComponentService(),
- endpoint.getTargetBinding());
- }
- /**
- * Create a reference wire for a forward call or a callback
- * @param reference
- * @param service
- * @param serviceBinding
- * @param component
- * @param referenceBinding
- */
- private RuntimeWire addReferenceWire(Component refComponent,
- ComponentReference reference,
- Binding refBinding,
- Component serviceComponent,
- ComponentService service,
- Binding serviceBinding) {
- RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
- InterfaceContract bindingContract = getInterfaceContract(reference, refBinding);
-
- // Use the interface contract of the reference on the component type
+ // Use the interface contract of the reference on the component type and if there
+ // isn't one then use the one from the reference itself
Reference componentTypeRef = reference.getReference();
InterfaceContract sourceContract;
@@ -939,18 +757,17 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
} else {
sourceContract = componentTypeRef.getInterfaceContract();
}
+
+ endpointReference.setInterfaceContract(sourceContract.makeUnidirectional(false));
- sourceContract = sourceContract.makeUnidirectional(false);
-
- EndpointReference wireSource =
- new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
+/* TODO - should have been done previously during matching
ComponentService callbackService = reference.getCallbackService();
if (callbackService != null) {
// select a reference callback binding to pass with invocations on this wire
Binding callbackBinding = null;
for (Binding binding : callbackService.getBindings()) {
// first look for a callback binding whose name matches the reference binding name
- if (refBinding.getName().startsWith(binding.getName())) {
+ if (refBinding.getName().startsWith(binding.getName())) {
callbackBinding = binding;
break;
}
@@ -965,59 +782,33 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
callbackContract);
wireSource.setCallbackEndpoint(callbackEndpoint);
}
+*/
- EndpointReference wireTarget =
- new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract);
-
+ InterfaceContract bindingContract = getInterfaceContract(reference, endpointReference.getBinding());
+ Endpoint2 endpoint = endpointReference.getTargetEndpoint();
+ endpoint.setInterfaceContract(bindingContract);
+
+/* TODO - review in the light of new matching code
// TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a
- // nested composite.
+ // nested composite.
if (serviceBinding != null) {
wireTarget.setURI(serviceBinding.getURI());
}
-
- RuntimeWire wire =
- new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor,
- messageFactory, conversationManager);
+*/
+
+ // create the wire
+ RuntimeWire wire = new RuntimeWireImpl2(false,
+ endpointReference,
+ endpoint,
+ interfaceContractMapper,
+ workScheduler,
+ wireProcessor,
+ messageFactory,
+ conversationManager);
runtimeRef.getRuntimeWires().add(wire);
-
- return wire;
- }
-
-
-
- /**
- * @param component
- * @param service
- * @param binding
- */
-
-
-
-
-
-
-
-
- /**
- * @param runtimeComponent
- */
- public void configureComponentContext(RuntimeComponent runtimeComponent) {
- RuntimeComponentContext componentContext = (RuntimeComponentContext) componentContextFactory.createComponentContext(runtimeComponent);
- runtimeComponent.setComponentContext(componentContext);
+
}
-
- /**
- * Stop a component
- */
-
-
- /**
- * Get the effective interface contract for a reference binding
- *
- * @param reference
- * @param binding
- * @return
- */
+
private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
InterfaceContract interfaceContract = reference.getInterfaceContract();
ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
@@ -1028,62 +819,21 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
}
return interfaceContract.makeUnidirectional(false);
- }
-
- /**
- * Remove the runtime wires for a reference binding
- * @param reference
- */
- private void removeReferenceWires(ComponentReference reference) {
- if (!(reference instanceof RuntimeComponentReference)) {
- return;
- }
- // [rfeng] Comment out the following statements to avoid the on-demand activation
- // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
- // runtimeRef.getRuntimeWires().clear();
- }
-
- /**
- * Get the effective interface contract for the service binding
- *
- * @param service
- * @param binding
- * @return
- */
-
-
- /**
- * Remove runtime wires for a service binding
- *
- * @param component
- * @param service
- */
-
-
-
-
-
-
-
-
-
- /**
- * @return the referenceHelper
- */
+ }
+
+
+
+ // Utility functions
+ // TODO - can we get rid of these?
+
public CompositeContext getCompositeContext() {
return compositeContext;
}
- /**
- * @return the domainComposite
- */
public Composite getDomainComposite() {
return domainComposite;
}
- /**
- * @param domainComposite the domainComposite to set
- */
public void setDomainComposite(Composite domainComposite) {
this.domainComposite = domainComposite;
}