summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-08 21:50:12 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-08 21:50:12 +0000
commitd8ba56c6764d782f22682189efce1416a3cf0d77 (patch)
tree92269b20a4570266146d4751a881408dd9693bef /java
parent6ebe0961b2ec3b32b261a0965515fb91a443a008 (diff)
Move EndpointRegistry from assembly to core-spi
Add EndpointListener git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@782804 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointRegistryImpl.java89
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java46
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java (renamed from java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointRegistry.java)24
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java238
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java228
-rw-r--r--java/sca/modules/endpoint/META-INF/MANIFEST.MF1
-rw-r--r--java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java172
-rw-r--r--java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java93
-rw-r--r--java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry (renamed from java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointRegistry)0
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java13
10 files changed, 484 insertions, 420 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointRegistryImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointRegistryImpl.java
deleted file mode 100644
index f5cc99d167..0000000000
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointRegistryImpl.java
+++ /dev/null
@@ -1,89 +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.assembly.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.ComponentService;
-import org.apache.tuscany.sca.assembly.Endpoint2;
-import org.apache.tuscany.sca.assembly.EndpointReference2;
-import org.apache.tuscany.sca.assembly.EndpointRegistry;
-
-public class EndpointRegistryImpl implements EndpointRegistry {
-
- public static final EndpointRegistryImpl INSTANCE = new EndpointRegistryImpl();
- public static EndpointRegistryImpl getInstance() {
- return INSTANCE;
- }
-
- List<Endpoint2> endpoints = new ArrayList<Endpoint2>();
- List<EndpointReference2> endpointreferences = new ArrayList<EndpointReference2>();
-
- private EndpointRegistryImpl() {
- }
-
- public void addEndpoint(Endpoint2 endpoint) {
- endpoints.add(endpoint);
- }
-
- public void addEndpointReference(EndpointReference2 endpointReference) {
- endpointreferences.add(endpointReference);
- }
-
- public List<Endpoint2> findEndpoint(EndpointReference2 endpointReference) {
- List<Endpoint2> foundEndpoints = new ArrayList<Endpoint2>();
- if (endpointReference.getReference() != null) {
- List<ComponentService> targets = endpointReference.getReference().getTargets();
- if (targets != null) {
- for (ComponentService targetService : targets) {
- for (Endpoint2 endpoint : endpoints) {
- // TODO: implement more complete matching
- if (endpoint.getComponent().getName().equals(targetService.getName())) {
- foundEndpoints.add(endpoint);
- }
- }
- }
- }
- }
- return foundEndpoints;
- }
-
- public List<EndpointReference2> findEndpointReference(Endpoint2 endpoint) {
- return null;
- }
-
- public void removeEndpoint(Endpoint2 endpoint) {
- endpoints.remove(endpoint);
- }
-
- public void removeEndpointReference(EndpointReference2 endpointReference) {
- endpointreferences.remove(endpointReference);
- }
-
- public List<EndpointReference2> getEndpointRefereneces() {
- return endpointreferences;
- }
-
- public List<Endpoint2> getEndpoints() {
- return endpoints;
- }
-
-}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java
new file mode 100644
index 0000000000..7de213fbc5
--- /dev/null
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java
@@ -0,0 +1,46 @@
+/*
+ * 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.runtime;
+
+import java.util.EventListener;
+
+import org.apache.tuscany.sca.assembly.Endpoint2;
+
+/**
+ * A listener for endpoint events
+ */
+public interface EndpointListener extends EventListener {
+ /**
+ * The method is invoked when a new endpoint is added to the registry
+ * @param endpoint
+ */
+ void endpointAdded(Endpoint2 endpoint);
+ /**
+ * The method is invoked when an endpoint is removed the registry
+ * @param endpoint
+ */
+ void endpointRemoved(Endpoint2 endpoint);
+ /**
+ * The method is invoked when an endpoint is updated in the registry
+ * @param oldEndpoint
+ * @param newEndpoint
+ */
+ void endpointUpdated(Endpoint2 oldEndpoint, Endpoint2 newEndpoint);
+}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointRegistry.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java
index ef63ac781a..a52ccaf7b7 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointRegistry.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java
@@ -6,31 +6,43 @@
* 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.
+ * under the License.
*/
-package org.apache.tuscany.sca.assembly;
+package org.apache.tuscany.sca.runtime;
import java.util.List;
import org.apache.tuscany.sca.assembly.Endpoint2;
import org.apache.tuscany.sca.assembly.EndpointReference2;
+/**
+ * The EndpointRegistry holds the active service endpoints for the SCA domain
+ */
public interface EndpointRegistry {
void addEndpoint(Endpoint2 endpoint);
void removeEndpoint(Endpoint2 endpoint);
+
+ Endpoint2 getEndpoint(String uri);
+ void updateEndpoint(String uri, Endpoint2 endpoint);
+ List<Endpoint2> findEndpoint(EndpointReference2 endpointReference);
+ List<Endpoint2> getEndpoints();
+
void addEndpointReference(EndpointReference2 endpointReference);
void removeEndpointReference(EndpointReference2 endpointReference);
- List<Endpoint2> findEndpoint(EndpointReference2 endpointReference);
List<EndpointReference2> findEndpointReference(Endpoint2 endpoint);
- List<Endpoint2> getEndpoints();
List<EndpointReference2> getEndpointRefereneces();
+
+ void addListener(EndpointListener listener);
+ void removeListener(EndpointListener listener);
+ List<EndpointListener> getListeners();
+
}
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 1d6b652402..d1087c1faf 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
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.core.assembly.impl;
@@ -33,7 +33,6 @@ 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.EndpointRegistry;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
@@ -68,6 +67,7 @@ import org.apache.tuscany.sca.provider.PolicyProviderFactory;
import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
@@ -104,7 +104,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
private final CompositeContext compositeContext;
private Composite domainComposite;
-
+
public CompositeActivatorImpl2(ExtensionPointRegistry extensionPoints) {
this.extensionPoints = extensionPoints;
this.compositeContext = new CompositeContextImpl(extensionPoints);
@@ -130,9 +130,9 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
//=========================================================================
// Activation
//=========================================================================
-
+
// Composite activation/deactivation
-
+
public void activate(Composite composite) throws ActivationException {
try {
if (logger.isLoggable(Level.FINE)) {
@@ -158,9 +158,9 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
throw new ActivationException(e);
}
}
-
+
// Component activation/deactivation
-
+
public void activateComponent(Component component)
throws ActivationException {
try {
@@ -190,7 +190,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
throw new ActivationException(e);
}
}
-
+
public void deactivateComponent(Component component)
throws ActivationException {
try {
@@ -217,10 +217,10 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
} catch (Exception e) {
throw new ActivationException(e);
}
- }
-
+ }
+
// add/remove artifacts required to get the implementation going
-
+
private void addImplementationProvider(RuntimeComponent component, Implementation implementation) {
ImplementationProviderFactory providerFactory =
(ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass());
@@ -241,14 +241,14 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
component.addPolicyProvider(policyProvider);
}
}
-
+
}
private void removeImplementationProvider(RuntimeComponent component) {
component.setImplementationProvider(null);
component.getPolicyProviders().clear();
}
-
+
private void addScopeContainer(Component component) {
if (!(component instanceof ScopedRuntimeComponent)) {
return;
@@ -269,13 +269,13 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
ScopeContainer scopeContainer = runtimeComponent.getScopeContainer();
if(scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) {
conversationManager.removeListener((ConversationalScopeContainer) scopeContainer);
- }
+ }
runtimeComponent.setScopeContainer(null);
}
-
-
+
+
// Service activation/deactivation
-
+
public void activate(RuntimeComponent component, RuntimeComponentService service) {
if (service.getService() == null) {
if (logger.isLoggable(Level.WARNING)) {
@@ -285,14 +285,14 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
return;
}
-
- /* TODO - EPR - activate services at all levels as promoted endpoin references are maintained
- * on the higher level services
+
+ /* TODO - EPR - activate services at all levels as promoted endpoin references are maintained
+ * on the higher level services
if (service.getService() instanceof CompositeService) {
return;
}
*/
-
+
if (logger.isLoggable(Level.FINE)) {
logger.fine("Activating component service: " + component.getURI() + "#" + service.getName());
}
@@ -312,7 +312,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
removeServiceBindingProvider(component, service, binding);
}
}
-
+
private ServiceBindingProvider addServiceBindingProvider(
RuntimeComponent component, RuntimeComponentService service,
Binding binding) {
@@ -358,18 +358,18 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
if (!(service instanceof RuntimeComponentService)) {
return;
}
-
+
RuntimeComponentService runtimeService = (RuntimeComponentService)service;
// Add a wire for each service Endpoint
for ( Endpoint2 endpoint : runtimeService.getEndpoints()){
-
+
// fluff up a fake endpoint reference as we are on the service side
// so we need to represent the reference that will call us
EndpointReference2 endpointReference = assemblyFactory.createEndpointReference();
endpointReference.setBinding(endpoint.getBinding());
endpointReference.setTargetEndpoint(endpoint);
-
+
// create the interface contract for the binding and service ends of the wire
// that are created as forward only contracts
// FIXME: [rfeng] We might need a better way to get the impl interface contract
@@ -379,30 +379,30 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
endpoint.setInterfaceContract(targetService.getInterfaceContract().makeUnidirectional(false));
endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding()));
-
+
// create the wire
RuntimeWire wire = new RuntimeWireImpl2(extensionPoints,
- false,
- endpointReference,
- endpoint,
- interfaceContractMapper,
- workScheduler,
+ false,
+ endpointReference,
+ endpoint,
+ interfaceContractMapper,
+ workScheduler,
wireProcessor,
- messageFactory,
+ messageFactory,
conversationManager);
-
+
runtimeService.getRuntimeWires().add(wire);
}
- }
-
+ }
+
private void removeServiceWires(ComponentService service) {
if (!(service instanceof RuntimeComponentService)) {
return;
}
RuntimeComponentService runtimeService = (RuntimeComponentService)service;
runtimeService.getRuntimeWires().clear();
- }
-
+ }
+
private InterfaceContract getServiceBindingInterfaceContract(ComponentService service, Binding binding) {
InterfaceContract interfaceContract = service.getInterfaceContract();
@@ -415,22 +415,22 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
return interfaceContract.makeUnidirectional(false);
}
-
+
// Reference activation/deactivation
-
+
public void activate(RuntimeComponent component, RuntimeComponentReference reference) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName());
}
-
- // set the parent component onto the reference. It's used at start time when the
+
+ // 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 reference) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Deactivating component reference: " + component.getURI() + "#" + reference.getName());
@@ -441,8 +441,8 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
removeReferenceBindingProvider(component, reference, endpointReference.getBinding());
}
}
- }
-/*
+ }
+/*
private ReferenceBindingProvider addReferenceBindingProvider(
RuntimeComponent component, RuntimeComponentReference reference,
Binding binding) {
@@ -475,7 +475,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
+ binding.getClass().getName());
}
}
-*/
+*/
private void removeReferenceBindingProvider(RuntimeComponent component,
RuntimeComponentReference reference, Binding binding) {
reference.setBindingProvider(binding, null);
@@ -486,24 +486,24 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
}
}
-
+
private void removeReferenceWires(ComponentReference reference) {
if (!(reference instanceof RuntimeComponentReference)) {
return;
}
-
+
// TODO - EPR 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
//=========================================================================
-
+
// Composite start/stop
-
+
public void start(Composite composite) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Starting composite: " + composite.getName());
@@ -521,9 +521,9 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
stop(component);
}
}
-
+
// Component start/stop
-
+
public void start(Component component) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Starting component: " + component.getURI());
@@ -532,9 +532,9 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
if(runtimeComponent.isStarted()) {
return;
}
-
+
configureComponentContext(runtimeComponent);
-
+
// Reference bindings aren't started until the wire is first used
for (ComponentService service : component.getServices()) {
@@ -547,13 +547,13 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding());
if (bindingProvider != null) {
// bindingProvider.start();
- // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
bindingProvider.start();
return null;
}
- });
+ });
}
}
}
@@ -593,13 +593,13 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
endpointRegistry.removeEndpoint(endpoint);
final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(endpoint.getBinding());
if (bindingProvider != null) {
- // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
bindingProvider.stop();
return null;
}
- });
+ });
}
}
}
@@ -608,19 +608,19 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
}
RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
-
+
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.
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
bindingProvider.stop();
return null;
}
- });
+ });
}
- }
+ }
}
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
@@ -628,19 +628,19 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
} else {
final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
if (implementationProvider != null) {
- // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
implementationProvider.stop();
return null;
}
- });
+ });
}
}
if (component instanceof ScopedRuntimeComponent) {
ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
- if (runtimeComponent.getScopeContainer() != null &&
+ if (runtimeComponent.getScopeContainer() != null &&
runtimeComponent.getScopeContainer().getLifecycleState() != ScopeContainer.STOPPED) {
runtimeComponent.getScopeContainer().stop();
}
@@ -648,79 +648,79 @@ 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 - EPR done as part of the component start above
-
+
// Reference start/stop
// Used by component context start
// TODO - EPR I don't know why reference wires don't get added until component start
-
+
public void start(RuntimeComponent component, RuntimeComponentReference componentReference) {
synchronized (componentReference) {
-
+
if (!(componentReference instanceof RuntimeComponentReference)) {
return;
}
-
- /* The way it was
+
+ /* The way it was
// create a wire for each endpoint reference. 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
+ // 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. This is apparently a repeat
// of previous configuration as self references are created
// on the fly and miss the previous point where providers are added
RuntimeComponentReference runtimeRef = (RuntimeComponentReference)componentReference;
-
+
if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
addReferenceBindingProvider(component, componentReference, endpointReference.getBinding());
}
-
- // start the binding provider
+
+ // start the binding provider
final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
-
+
if (bindingProvider != null) {
- // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ // 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);
}
- }
+ }
*/
-
- // create a wire for each endpoint reference. An endpoint reference says either that
+
+ // create a wire for each endpoint reference. An endpoint reference says either that
// - a target has been specified and hence the reference has been wired in some way.
// - an unwired binding ha been specified
// and endpoint reference representing a wired reference may not at this point
- // be resolved (the service to which it points may not be present in the
+ // be resolved (the service to which it points may not be present in the
// current composite). Endpoint reference resolution takes place when the wire
// is first used (when the chains are created)
for (EndpointReference2 endpointReference : componentReference.getEndpointReferences()){
addReferenceWire(component, componentReference, endpointReference);
endpointRegistry.addEndpointReference(endpointReference);
}
-
+
}
}
@@ -737,10 +737,10 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
}
}
-
+
private void addReferenceWire(Component component, ComponentReference reference, EndpointReference2 endpointReference) {
RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
-
+
// 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();
@@ -751,7 +751,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
} else {
sourceContract = componentTypeRef.getInterfaceContract();
}
-
+
// TODO - EPR - interface contract seems to be null in the implementation.web
// case. Not introspecting the CT properly?
if (sourceContract == null){
@@ -760,7 +760,7 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
sourceContract = endpointReference.getTargetEndpoint().getInterfaceContract();
reference.setInterfaceContract(sourceContract);
}
-
+
endpointReference.setInterfaceContract(sourceContract.makeUnidirectional(false));
/* TODO - EPR should have been done previously during matching
@@ -787,36 +787,36 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
*/
-/* TODO - EPR can't do this until the binding matches the EPR
+/* TODO - EPR can't do this until the binding matches the EPR
InterfaceContract bindingContract = getInterfaceContract(reference, endpointReference.getBinding());
Endpoint2 endpoint = endpointReference.getTargetEndpoint();
endpoint.setInterfaceContract(bindingContract);
*/
-
-/* TODO - EPR review in the light of new matching code
+
+/* TODO - EPR 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());
}
-*/
+*/
// create the wire
- // null endpoint passed in here as the endpoint reference may
+ // null endpoint passed in here as the endpoint reference may
// not be resolved yet
RuntimeWire wire = new RuntimeWireImpl2(extensionPoints,
- true,
- endpointReference,
- null,
- interfaceContractMapper,
- workScheduler,
+ true,
+ endpointReference,
+ null,
+ interfaceContractMapper,
+ workScheduler,
wireProcessor,
- messageFactory,
+ messageFactory,
conversationManager);
runtimeRef.getRuntimeWires().add(wire);
-
+
}
-
+
private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
InterfaceContract interfaceContract = reference.getInterfaceContract();
ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
@@ -827,13 +827,13 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
}
return interfaceContract.makeUnidirectional(false);
- }
-
-
-
+ }
+
+
+
// Utility functions
// TODO - can we get rid of these?
-
+
public CompositeContext getCompositeContext() {
return compositeContext;
}
@@ -872,5 +872,5 @@ public class CompositeActivatorImpl2 implements CompositeActivator {
}
return null;
}
-
+
}
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 ab03645182..ebe8c1b9ed 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
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.core.assembly.impl;
@@ -29,10 +29,11 @@ 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.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+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.builder.CompositeBuilder;
-import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint;
import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
@@ -49,7 +50,6 @@ 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.invocation.Phase;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.provider.BindingProviderFactory;
import org.apache.tuscany.sca.provider.ImplementationProvider;
import org.apache.tuscany.sca.provider.PolicyProvider;
@@ -73,9 +73,9 @@ import org.oasisopen.sca.ServiceRuntimeException;
* @version $Rev$ $Date$
*/
public class RuntimeWireImpl2 implements RuntimeWire {
-
+
private ExtensionPointRegistry extensionPoints;
-
+
private Boolean isReferenceWire = false;
private EndpointReference2 endpointReference;
private Endpoint2 endpoint;
@@ -96,18 +96,18 @@ public class RuntimeWireImpl2 implements RuntimeWire {
private List<InvocationChain> chains;
private InvocationChain bindingInvocationChain;
-
+
private EndpointReferenceBuilder endpointReferenceBuilder;
private final ProviderFactoryExtensionPoint providerFactories;
/**
* @param source
* @param target
- * @param interfaceContractMapper
- * @param workScheduler
- * @param wireProcessor
- * @param messageFactory
- * @param conversationManager
+ * @param interfaceContractMapper
+ * @param workScheduler
+ * @param wireProcessor
+ * @param messageFactory
+ * @param conversationManager
*/
public RuntimeWireImpl2(ExtensionPointRegistry extensionPoints,
boolean isReferenceWire,
@@ -129,7 +129,7 @@ public class RuntimeWireImpl2 implements RuntimeWire {
this.messageFactory = messageFactory;
this.conversationManager = conversationManager;
this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this);
-
+
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class);
this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
@@ -141,7 +141,7 @@ public class RuntimeWireImpl2 implements RuntimeWire {
}
return chains;
}
-
+
public synchronized InvocationChain getBindingInvocationChain() {
if (bindingInvocationChain == null) {
bindingInvocationChain = new InvocationChainImpl(null, null, isReferenceWire);
@@ -168,10 +168,10 @@ public class RuntimeWireImpl2 implements RuntimeWire {
}
return null;
}
-
+
public Object invoke(Message msg) throws InvocationTargetException {
return getBindingInvocationChain().getHeadInvoker().invoke(msg);
- }
+ }
public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
Message msg = messageFactory.createMessage();
@@ -184,18 +184,71 @@ public class RuntimeWireImpl2 implements RuntimeWire {
}
/**
+ * Navigate the component/componentType inheritence chain to find the leaf contract
+ * @param contract
+ * @return
+ */
+ private Contract getLeafContract(Contract contract) {
+ Contract prev = null;
+ Contract current = contract;
+ while (current != null) {
+ prev = current;
+ if (current instanceof ComponentReference) {
+ current = ((ComponentReference)current).getReference();
+ } else if (current instanceof CompositeReference) {
+ current = ((CompositeReference)current).getPromotedReferences().get(0);
+ } else if (current instanceof ComponentService) {
+ current = ((ComponentService)current).getService();
+ } else if (current instanceof CompositeService) {
+ current = ((CompositeService)current).getPromotedService();
+ } else {
+ break;
+ }
+ if (current == null) {
+ return prev;
+ }
+ }
+ return current;
+ }
+
+ private InterfaceContract getLeafInterfaceContract(EndpointReference2 epr) {
+ ComponentReference reference = epr.getReference();
+ if (reference == null) {
+ return epr.getInterfaceContract();
+ }
+ InterfaceContract interfaceContract = getLeafContract(reference).getInterfaceContract();
+ if (interfaceContract == null) {
+ interfaceContract = epr.getInterfaceContract();
+ }
+ return interfaceContract;
+ }
+
+ private InterfaceContract getLeafInterfaceContract(Endpoint2 ep) {
+ ComponentService service = ep.getService();
+ if (service == null) {
+ return ep.getInterfaceContract();
+ }
+ InterfaceContract interfaceContract = getLeafContract(service).getInterfaceContract();
+ if (interfaceContract == null) {
+ interfaceContract = ep.getInterfaceContract();
+ }
+ return interfaceContract;
+ }
+
+ /**
* Initialize the invocation chains
*/
private void initInvocationChains() {
-
chains = new ArrayList<InvocationChain>();
- InterfaceContract sourceContract = endpointReference.getInterfaceContract();
+ // InterfaceContract sourceContract = endpointReference.getInterfaceContract();
+ // InterfaceContract targetContract = endpoint.getInterfaceContract();
+ InterfaceContract sourceContract = getLeafInterfaceContract(endpointReference);
if (isReferenceWire) {
// It's the reference wire
resolveEndpointReference();
- InterfaceContract targetContract = endpoint.getInterfaceContract();
+ InterfaceContract targetContract = getLeafInterfaceContract(endpoint);
RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
Binding refBinding = endpointReference.getBinding();
for (Operation operation : sourceContract.getInterface().getOperations()) {
@@ -214,13 +267,13 @@ public class RuntimeWireImpl2 implements RuntimeWire {
addReferenceBindingInterceptor(reference, refBinding, chain, operation);
chains.add(chain);
}
-
+
} else {
// It's the service wire
- InterfaceContract targetContract = endpoint.getInterfaceContract();
RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
RuntimeComponent serviceComponent = (RuntimeComponent)endpoint.getComponent();
Binding serviceBinding = endpoint.getBinding();
+ InterfaceContract targetContract = getLeafInterfaceContract(endpoint);
for (Operation operation : sourceContract.getInterface().getOperations()) {
Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
if (targetOperation == null) {
@@ -238,48 +291,49 @@ public class RuntimeWireImpl2 implements RuntimeWire {
addImplementationInterceptor(serviceComponent, service, chain, targetOperation);
chains.add(chain);
}
-
+
}
wireProcessor.process(this);
}
-
+
+
/**
- * This code used to be in the activator but has moved here as
+ * This code used to be in the activator but has moved here as
* the endpoint reference may not now be resolved until the wire
* is first used
*/
private void resolveEndpointReference(){
endpointReferenceBuilder.build(endpointReference, null);
-
+
// set the endpoint based on the resolved endpoint
endpoint = endpointReference.getTargetEndpoint();
-
+
RuntimeComponentReference runtimeRef = (RuntimeComponentReference)endpointReference.getReference();
-
+
if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
- addReferenceBindingProvider((RuntimeComponent)endpointReference.getComponent(),
- runtimeRef,
+ addReferenceBindingProvider((RuntimeComponent)endpointReference.getComponent(),
+ runtimeRef,
endpointReference.getBinding());
}
-
- // start the binding provider
+
+ // start the binding provider
final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
-
+
if (bindingProvider != null) {
- // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
bindingProvider.start();
return null;
}
- });
+ });
}
-
+
InterfaceContract bindingContract = getInterfaceContract(endpointReference.getReference(), endpointReference.getBinding());
Endpoint2 endpoint = endpointReference.getTargetEndpoint();
endpoint.setInterfaceContract(bindingContract);
}
-
+
private ReferenceBindingProvider addReferenceBindingProvider(
RuntimeComponent component, RuntimeComponentReference reference,
Binding binding) {
@@ -311,8 +365,8 @@ public class RuntimeWireImpl2 implements RuntimeWire {
"Provider factory not found for class: "
+ binding.getClass().getName());
}
- }
-
+ }
+
private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
InterfaceContract interfaceContract = reference.getInterfaceContract();
if (interfaceContract == null) {
@@ -326,19 +380,18 @@ public class RuntimeWireImpl2 implements RuntimeWire {
}
}
return interfaceContract.makeUnidirectional(false);
- }
-
+ }
+
private void initReferenceBindingInvocationChains() {
RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
Binding referenceBinding = endpointReference.getBinding();
-
+
// add the binding interceptors to the reference binding wire
ReferenceBindingProvider provider = reference.getBindingProvider(referenceBinding);
- if ((provider != null) &&
- (provider instanceof ReferenceBindingProviderRRB)){
+ if ((provider != null) && (provider instanceof ReferenceBindingProviderRRB)) {
((ReferenceBindingProviderRRB)provider).configureBindingChain(this);
}
-
+
// add the policy interceptors to the service binding wire
// find out which policies are active
List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(referenceBinding);
@@ -351,20 +404,19 @@ public class RuntimeWireImpl2 implements RuntimeWire {
}
}
}
- }
- }
-
+ }
+ }
+
private void initServiceBindingInvocationChains() {
RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
Binding serviceBinding = endpoint.getBinding();
-
+
// add the binding interceptors to the service binding wire
ServiceBindingProvider provider = service.getBindingProvider(serviceBinding);
- if ((provider != null) &&
- (provider instanceof ServiceBindingProviderRRB)){
+ if ((provider != null) && (provider instanceof ServiceBindingProviderRRB)) {
((ServiceBindingProviderRRB)provider).configureBindingChain(this);
}
-
+
// add the policy interceptors to the service binding wire
List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(serviceBinding);
if (pps != null) {
@@ -376,59 +428,53 @@ public class RuntimeWireImpl2 implements RuntimeWire {
}
}
}
- }
-
-
- // TODO - add something on the end of the wire to invoke the
+ }
+
+ // TODO - add something on the end of the wire to invoke the
// invocation chain. Need to split out the runtime
// wire invoker into conversation, callback interceptors etc
bindingInvocationChain.addInvoker(invoker);
-
+
}
// ===============================================================
// TODO - EPR remove when we convert fully over to EndpointReference2
-
+
// TODO - remove. Just here during development
static EndpointReference epr;
-
+
public EndpointReference getSource() {
// TODO - EPR convert this into method that returns EndpointReference2
-
+
// convert the source info into old endpoint reference format
- epr = new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(),
- endpointReference.getReference(),
- endpointReference.getBinding(),
- endpointReference.getInterfaceContract());
-
- if (endpointReference.getCallbackEndpoint() != null){
+ epr =
+ new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(), endpointReference
+ .getReference(), endpointReference.getBinding(), endpointReference.getInterfaceContract());
+
+ if (endpointReference.getCallbackEndpoint() != null) {
// convert the source callback endpoint into old endpoint reference format
EndpointReference cepr;
- cepr = new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(),
- endpointReference.getCallbackEndpoint().getService(),
- endpointReference.getCallbackEndpoint().getBinding(),
- endpointReference.getCallbackEndpoint().getInterfaceContract());
+ cepr =
+ new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(), endpointReference
+ .getCallbackEndpoint().getService(), endpointReference.getCallbackEndpoint().getBinding(),
+ endpointReference.getCallbackEndpoint().getInterfaceContract());
epr.setCallbackEndpoint(cepr);
}
-
-
- // TODO - somtimes used to reset the interface contract so we
- // copy it back in in the rebuild method below
+
+ // TODO - somtimes used to reset the interface contract so we
+ // copy it back in in the rebuild method below
return epr;
}
-
-
public EndpointReference getTarget() {
// TODO - EPR convert this into method that returns Endpoint2
-
+
Endpoint2 endpoint = this.endpoint != null ? this.endpoint : endpointReference.getTargetEndpoint();
// convert the target info into old endpoint reference format
- EndpointReference epr = new EndpointReferenceImpl((RuntimeComponent)endpoint.getComponent(),
- endpoint.getService(),
- endpoint.getBinding(),
- endpoint.getInterfaceContract());
+ EndpointReference epr =
+ new EndpointReferenceImpl((RuntimeComponent)endpoint.getComponent(), endpoint.getService(), endpoint
+ .getBinding(), endpoint.getInterfaceContract());
return epr;
}
@@ -436,27 +482,27 @@ public class RuntimeWireImpl2 implements RuntimeWire {
// TODO - can we use the idea of setTarget to rebuild the wire?
}
-
+
// ===================================================================
public void rebuild() {
// TODO - can we use the idea of setTarget to rebuild the wire?
- // used at the moment by binding.sca when it resets the
+ // used at the moment by binding.sca when it resets the
// source interface contract for local wires
this.chains = null;
-
+
// TODO - cheating here as I fixed the RuntimeComponentService code
// to call this when it resets the interface contract
endpointReference.setInterfaceContract(epr.getInterfaceContract());
}
-
- public EndpointReference2 getEndpointReference(){
+
+ public EndpointReference2 getEndpointReference() {
return endpointReference;
}
/**
* Add the interceptor for a reference binding
- *
+ *
* @param reference
* @param binding
* @param chain
@@ -486,7 +532,7 @@ public class RuntimeWireImpl2 implements RuntimeWire {
/**
* Add the interceptor for a binding
- *
+ *
* @param reference
* @param binding
* @param chain
@@ -509,7 +555,7 @@ public class RuntimeWireImpl2 implements RuntimeWire {
/**
* Add a non-blocking interceptor if the reference binding needs it
- *
+ *
* @param reference
* @param binding
* @param chain
@@ -542,7 +588,7 @@ public class RuntimeWireImpl2 implements RuntimeWire {
/**
* Add the interceptor for a component implementation
- *
+ *
* @param component
* @param service
* @param chain
diff --git a/java/sca/modules/endpoint/META-INF/MANIFEST.MF b/java/sca/modules/endpoint/META-INF/MANIFEST.MF
index 834c83f297..dba4c562a8 100644
--- a/java/sca/modules/endpoint/META-INF/MANIFEST.MF
+++ b/java/sca/modules/endpoint/META-INF/MANIFEST.MF
@@ -21,6 +21,7 @@ Import-Package: javax.xml.stream;resolution:=optional,
org.apache.tuscany.sca.interfacedef;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.monitor;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.policy;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.runtime;version="2.0.0",
org.oasisopen.sca;version="2.0.0",
org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional
Bundle-SymbolicName: org.apache.tuscany.sca.endpoint
diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
index 327f674b38..7b34e988b0 100644
--- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
+++ b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
@@ -6,34 +6,27 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.endpoint.impl;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
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.Composite;
import org.apache.tuscany.sca.assembly.Endpoint2;
import org.apache.tuscany.sca.assembly.EndpointReference2;
-import org.apache.tuscany.sca.assembly.EndpointRegistry;
-import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
@@ -49,44 +42,45 @@ import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.oasisopen.sca.SCARuntimeException;
/**
- * An builder that takes endpoint references and resolves them. It either finds local
+ * An builder that takes endpoint references and resolves them. It either finds local
* service endpoints if they are available or asks the domain. The main function here
- * is to perform binding and policy matching.
+ * is to perform binding and policy matching.
* This is a separate builder in case it is required by undresolved endpoints
- * once the runtime has started.
- *
+ * once the runtime has started.
+ *
* @version $Rev$ $Date$
*/
public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointReferenceBuilder {
-
+
protected ExtensionPointRegistry extensionPoints;
protected AssemblyFactory assemblyFactory;
protected InterfaceContractMapper interfaceContractMapper;
protected EndpointRegistry endpointRegistry;
-
-
+
+
public EndpointReferenceBuilderImpl(ExtensionPointRegistry extensionPoints) {
this.extensionPoints = extensionPoints;
-
+
FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
-
+
UtilityExtensionPoint utils = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
this.interfaceContractMapper = utils.getUtility(InterfaceContractMapper.class);
-
+
this.endpointRegistry = utils.getUtility(EndpointRegistry.class);
}
public String getID() {
return "org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder";
}
-
+
/**
* Report a warning.
- *
+ *
* @param monitor
* @param problems
* @param message
@@ -98,10 +92,10 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
monitor.problem(problem);
}
}
-
+
/**
* Report a error.
- *
+ *
* @param monitor
* @param problems
* @param message
@@ -112,11 +106,11 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
Problem problem = monitor.createProblem(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
monitor.problem(problem);
}
- }
-
+ }
+
/**
* Report a exception.
- *
+ *
* @param problems
* @param message
* @param model
@@ -127,21 +121,21 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
problem = monitor.createProblem(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex);
monitor.problem(problem);
}
- }
+ }
/**
* Build all the endpoint references
- *
+ *
* @param composite
*/
- public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException
+ public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException
{
// Not used now
}
/*
private void populateEndpointRegistry(Composite composite, Monitor monitor) {
-
+
// register endpoints (and endpoint references) for each component
for (Component component : composite.getComponents()) {
// recurse for composite implementations
@@ -149,88 +143,88 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
if (implementation instanceof Composite) {
populateEndpointRegistry((Composite)implementation, monitor);
}
-
- // register endpoints
+
+ // register endpoints
for (ComponentService service : component.getServices()) {
for (Endpoint2 endpoint : service.getEndpoints()){
endpointRegistry.addEndpoint(endpoint);
}
}
-
- // register endpoint references
+
+ // register endpoint references
for (ComponentReference reference : component.getReferences()) {
for (EndpointReference2 endpointReference : reference.getEndpointReferences()){
endpointRegistry.addEndpointReference(endpointReference);
}
- }
+ }
}
}
*/
-
+
/**
* Build a single endpoint reference
- *
+ *
* @param endpoint
* @param monitor
*/
public void build(EndpointReference2 endpointReference, Monitor monitor) {
Endpoint2 endpoint = endpointReference.getTargetEndpoint();
-
+
if (endpoint == null){
// an error?
- } else {
+ } else {
if (endpoint.isUnresolved() == false){
// Wired - service resolved - binding matched
// The service is in the same composite
return;
}
-
- if (endpointReference.isUnresolved() == false ){
- // Wired - service resolved - binding not matched
+
+ if (endpointReference.isUnresolved() == false ){
+ // Wired - service resolved - binding not matched
// The service is in the same composite
// TODO - How do we get to here?
- matchForwardBinding(endpointReference,
+ matchForwardBinding(endpointReference,
monitor);
-
- matchCallbackBinding(endpointReference,
+
+ matchCallbackBinding(endpointReference,
monitor);
} else {
// Wired - service specified but unresolved
// The service is in a remote composite somewhere else in the domain
-
+
// find the service in the endpoint registry
List<Endpoint2> endpoints = endpointRegistry.findEndpoint(endpointReference);
-
- // TODO - do we exepect to find more than one endpoint in
+
+ // TODO - do we exepect to find more than one endpoint in
// anything other than the autowire case?
if (endpoints.size() == 0) {
throw new SCARuntimeException("No endpoints found for EndpointReference " + endpointReference.toString());
}
-
+
if (endpoints.size() > 1) {
throw new SCARuntimeException("More than one endpoint found for EndpointReference" + endpointReference.toString());
}
-
+
endpointReference.setTargetEndpoint(endpoints.get(0));
-
- matchForwardBinding(endpointReference,
+
+ matchForwardBinding(endpointReference,
monitor);
-
- matchCallbackBinding(endpointReference,
+
+ matchCallbackBinding(endpointReference,
monitor);
- }
- }
-
+ }
+ }
+
if (endpointReference.isUnresolved()){
throw new SCARuntimeException("EndpointReference can't be resolved");
}
}
-
- // TODO - EPR - In OASIS case there are no bindings to match with on the
- // reference side.
+
+ // TODO - EPR - In OASIS case there are no bindings to match with on the
+ // reference side.
private void matchForwardBinding(EndpointReference2 endpointReference,
Monitor monitor) {
-
+
Endpoint2 endpoint = endpointReference.getTargetEndpoint();
List<Binding> matchedReferenceBinding = new ArrayList<Binding>();
@@ -240,7 +234,7 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
for (Binding referenceBinding : endpointReference.getReference().getBindings()) {
for (Endpoint2 serviceEndpoint : endpoint.getService().getEndpoints()) {
- if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() &&
+ if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() &&
hasCompatiblePolicySets(referenceBinding, serviceEndpoint.getBinding())) {
matchedReferenceBinding.add(referenceBinding);
@@ -253,10 +247,10 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
// No matching binding
endpointReference.setBinding(null);
endpointReference.setUnresolved(true);
- warning(monitor,
- "NoMatchingBinding",
+ warning(monitor,
+ "NoMatchingBinding",
endpointReference.getReference(),
- endpointReference.getReference().getName(),
+ endpointReference.getReference().getName(),
endpoint.getService().getName());
return;
} else {
@@ -283,7 +277,7 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
if (referenceBinding.getURI() == null) {
clonedBinding.setURI(serviceEndpoint.getBinding().getURI());
}
-
+
// TODO - EPR can we remove this?
if (clonedBinding instanceof OptimizableBinding) {
OptimizableBinding optimizableBinding = (OptimizableBinding)clonedBinding;
@@ -293,9 +287,9 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
}
endpointReference.setBinding(clonedBinding);
-
+
Endpoint2 clonedEndpoint = (Endpoint2)serviceEndpoint.clone();
-
+
endpointReference.setTargetEndpoint(clonedEndpoint);
endpointReference.setUnresolved(false);
@@ -303,68 +297,68 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
// do nothing
}
}
- }
-
+ }
+
// TODO - EPR
// Find the callback endpoint for the endpoint reference by matching
// callback bindings between reference and service
- private void matchCallbackBinding(EndpointReference2 endpointReference,
+ private void matchCallbackBinding(EndpointReference2 endpointReference,
Monitor monitor) {
// if no callback on the interface or we are creating a self reference do nothing
- if (endpointReference.getReference().getInterfaceContract() == null ||
+ if (endpointReference.getReference().getInterfaceContract() == null ||
endpointReference.getReference().getInterfaceContract().getCallbackInterface() == null ||
endpointReference.getReference().getName().startsWith("$self$.")){
return;
}
-
+
Endpoint2 endpoint = endpointReference.getTargetEndpoint();
-
+
List<Endpoint2> callbackEndpoints = endpointReference.getReference().getCallbackService().getEndpoints();
List<EndpointReference2> callbackEndpointReferences = endpoint.getCallbackEndpointReferences();
-
+
List<Endpoint2> matchedEndpoint = new ArrayList<Endpoint2>();
-
+
if ((callbackEndpoints != null) && (callbackEndpointReferences != null)){
// Find the corresponding bindings from the service side
for (EndpointReference2 epr : callbackEndpointReferences) {
for (Endpoint2 ep : callbackEndpoints) {
-
+
if (epr.getBinding().getClass() == ep.getBinding().getClass() &&
hasCompatiblePolicySets(epr.getBinding(), ep.getBinding())) {
-
- matchedEndpoint.add(ep);
+
+ matchedEndpoint.add(ep);
}
}
}
}
-
+
if (matchedEndpoint.isEmpty()) {
// No matching binding
endpointReference.setCallbackEndpoint(null);
endpointReference.setUnresolved(true);
- warning(monitor,
- "NoMatchingCallbackBinding",
+ warning(monitor,
+ "NoMatchingCallbackBinding",
endpointReference.getReference(),
- endpointReference.getReference().getName(),
+ endpointReference.getReference().getName(),
endpoint.getService().getName());
return;
} else {
// default to using the first matched binding
int selectedEndpoint = 0;
-
+
for (int i = 0; i < matchedEndpoint.size(); i++){
// If binding.sca is present, use it
if (SCABinding.class.isInstance(matchedEndpoint.get(i).getBinding())) {
selectedEndpoint = i;
}
}
-
+
endpointReference.setCallbackEndpoint(matchedEndpoint.get(selectedEndpoint));
endpointReference.setUnresolved(false);
}
- }
-
+ }
+
private boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) {
boolean isCompatible = true;
if ( refBinding instanceof PolicySubject && svcBinding instanceof PolicySubject ) {
@@ -384,5 +378,5 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
}
}
return isCompatible;
- }
+ }
}
diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
index b7bf52183d..57cfc70d52 100644
--- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
+++ b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
@@ -6,68 +6,76 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.endpoint.impl;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Logger;
-import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Endpoint2;
import org.apache.tuscany.sca.assembly.EndpointReference2;
-import org.apache.tuscany.sca.assembly.EndpointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.runtime.EndpointListener;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
public class EndpointRegistryImpl implements EndpointRegistry {
-
+ private final Logger logger = Logger.getLogger(EndpointRegistryImpl.class.getName());
//public static final EndpointRegistryImpl INSTANCE = new EndpointRegistryImpl();
//public static EndpointRegistryImpl getInstance() {
// return INSTANCE;
//}
-
+
static List<Endpoint2> endpoints = new ArrayList<Endpoint2>();
static List<EndpointReference2> endpointreferences = new ArrayList<EndpointReference2>();
-
+
+ private List<EndpointListener> listeners = new CopyOnWriteArrayList<EndpointListener>();
+
public EndpointRegistryImpl(ExtensionPointRegistry extensionPoints) {
}
-
+
public void addEndpoint(Endpoint2 endpoint) {
endpoints.add(endpoint);
- System.out.println("EndpointRegistry: Add endpoint - " + endpoint.toString());
+ for (EndpointListener listener : listeners) {
+ listener.endpointAdded(endpoint);
+ }
+ logger.info("EndpointRegistry: Add endpoint - " + endpoint.toString());
}
public void addEndpointReference(EndpointReference2 endpointReference) {
endpointreferences.add(endpointReference);
- System.out.println("EndpointRegistry: Add endpoint reference - " + endpointReference.toString());
+ logger.info("EndpointRegistry: Add endpoint reference - " + endpointReference.toString());
}
public List<Endpoint2> findEndpoint(EndpointReference2 endpointReference) {
List<Endpoint2> foundEndpoints = new ArrayList<Endpoint2>();
-
- System.out.println("EndpointRegistry: Find endpoint for reference - " + endpointReference.toString());
-
+
+ logger.info("EndpointRegistry: Find endpoint for reference - " + endpointReference.toString());
+
if (endpointReference.getReference() != null) {
Endpoint2 targetEndpoint = endpointReference.getTargetEndpoint();
for (Endpoint2 endpoint : endpoints) {
// TODO: implement more complete matching
if (endpoint.getComponentName().equals(targetEndpoint.getComponentName())) {
- if ( (targetEndpoint.getServiceName() != null) &&
- (endpoint.getServiceName().equals(targetEndpoint.getServiceName())) ){
+ if ((targetEndpoint.getServiceName() != null) && (endpoint.getServiceName().equals(targetEndpoint
+ .getServiceName()))) {
foundEndpoints.add(endpoint);
- System.out.println("EndpointRegistry: Found endpoint with matching service - " + endpoint.toString());
+ logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint.toString());
} else if (targetEndpoint.getServiceName() == null) {
foundEndpoints.add(endpoint);
- System.out.println("EndpointRegistry: Found endpoint with matching component - " + endpoint.toString());
+ logger.info("EndpointRegistry: Found endpoint with matching component - " + endpoint
+ .toString());
}
// else the service name doesn't match
}
@@ -82,12 +90,15 @@ public class EndpointRegistryImpl implements EndpointRegistry {
public void removeEndpoint(Endpoint2 endpoint) {
endpoints.remove(endpoint);
- System.out.println("EndpointRegistry: Remove endpoint - " + endpoint.toString());
+ for (EndpointListener listener : listeners) {
+ listener.endpointRemoved(endpoint);
+ }
+ logger.info("EndpointRegistry: Remove endpoint - " + endpoint.toString());
}
public void removeEndpointReference(EndpointReference2 endpointReference) {
endpointreferences.remove(endpointReference);
- System.out.println("EndpointRegistry: Remove endpoint reference - " + endpointReference.toString());
+ logger.info("EndpointRegistry: Remove endpoint reference - " + endpointReference.toString());
}
public List<EndpointReference2> getEndpointRefereneces() {
@@ -98,4 +109,46 @@ public class EndpointRegistryImpl implements EndpointRegistry {
return endpoints;
}
+ public void addListener(EndpointListener listener) {
+ listeners.add(listener);
+ }
+
+ public List<EndpointListener> getListeners() {
+ return listeners;
+ }
+
+ public void removeListener(EndpointListener listener) {
+ listeners.remove(listener);
+ }
+
+ public Endpoint2 getEndpoint(String uri) {
+ for (Endpoint2 ep : endpoints) {
+ String epURI =
+ ep.getComponent().getURI() + "#" + ep.getService().getName() + "/" + ep.getBinding().getName();
+ if (epURI.equals(uri)) {
+ return ep;
+ }
+ if (ep.getBinding().getName() == null || ep.getBinding().getName().equals(ep.getService().getName())) {
+ epURI = ep.getComponent().getURI() + "#" + ep.getService().getName();
+ if (epURI.equals(uri)) {
+ return ep;
+ }
+ }
+ }
+ return null;
+
+ }
+
+ public void updateEndpoint(String uri, Endpoint2 endpoint) {
+ Endpoint2 oldEndpoint = getEndpoint(uri);
+ if (oldEndpoint == null) {
+ throw new IllegalArgumentException("Endpoint is not found: " + uri);
+ }
+ endpoints.remove(oldEndpoint);
+ addEndpoint(endpoint);
+ for (EndpointListener listener : listeners) {
+ listener.endpointUpdated(oldEndpoint, endpoint);
+ }
+ }
+
}
diff --git a/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointRegistry b/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
index 26ee8ce362..26ee8ce362 100644
--- a/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointRegistry
+++ b/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index 8b79fbbe5e..98d450210f 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -45,6 +45,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.oasisopen.sca.CallableReference;
import org.oasisopen.sca.ServiceReference;
import org.oasisopen.sca.ServiceRuntimeException;
+import org.oasisopen.sca.ServiceUnavailableException;
/**
* An SCA Node that is managed by the NodeManager
@@ -106,16 +107,16 @@ public class NodeImpl implements Node, Client {
if( compositeActivator.getDomainComposite() != null ) {
List<Composite> composites = compositeActivator.getDomainComposite().getIncludes();
for (Composite composite : composites) {
-
+
// Stop the composite
compositeActivator.stop(composite);
-
+
// Deactivate the composite
compositeActivator.deactivate(composite);
-
+
} // end for
composites.clear();
- } // end if
+ } // end if
manager.removeNode(configuration);
this.compositeActivator = null;
@@ -168,7 +169,7 @@ public class NodeImpl implements Node, Client {
}
if (component == null) {
- throw new ServiceRuntimeException("The service " + name + " has not been contributed to the domain");
+ throw new ServiceUnavailableException("The service " + name + " has not been contributed to the domain");
}
RuntimeComponentContext componentContext = null;
@@ -206,7 +207,7 @@ public class NodeImpl implements Node, Client {
public ExtensionPointRegistry getExtensionPoints() {
return manager.getExtensionPoints();
}
-
+
/**
* Get the service endpoints in this Node
* TODO: needs review, works for the very simple testcase but i expect there are