summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/endpoint/src/main
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/sca/modules/endpoint/src/main
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/sca/modules/endpoint/src/main')
-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
3 files changed, 156 insertions, 109 deletions
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