diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-06 16:45:57 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-06 16:45:57 +0000 |
commit | 70a68422b6a3ea7a211c46d802307571e98a8a31 (patch) | |
tree | b0f14712576a383740c7938436b52e4d79d4a6a9 /sandbox | |
parent | 374f54d3f32e33e59ae74e7d2f4a48c2d6e4f86a (diff) |
Changes to enable consumers and producers to be connected via binding.sca
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@711904 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox')
8 files changed, 183 insertions, 3 deletions
diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Consumer.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Consumer.java index 1120e7ce87..a77e97bbe1 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Consumer.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Consumer.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.assembly; import java.util.List; +import java.util.Set; /** @@ -31,8 +32,24 @@ public interface Consumer extends EventTarget, Contract { List<EventSource> getSources(); - String getOperationName(); + // Operation related information + /** + * Adds an operation to the consumer along with a list of the accepted event types. + * If the event types are null, then any event type is accepted + */ + void addOperation( String operationName, String eventTypes ); - void setOperationName(String operationName); + /** + * Gets the operations for this consumer, by name + * @return + */ + Set<String> getOperations(); + + /** + * Returns the operation which handles a given event type for this consumer + * @param eventType - the event type name, which can be null (meaning "any event type") + * @return the operation which handles this event type - null if no operation handles the event type + */ + String getOperationByEventType( String eventType ); } diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java index 2eb1bf21b0..de6d3d7f7e 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java @@ -70,5 +70,24 @@ public interface Reference extends AbstractReference, Contract { * @return the targets of this reference. */ List<ComponentService> getTargets(); + + /** + * Allows this Reference to be set as a Producer + * @param aProducer - the producer to set for this Reference + */ + void setProducer( Producer aProducer ); + + /** + * Gets the producer for this Reference + * @return the Producer - null if no Producer is set + */ + Producer getProducer(); + + /** + * Returns whether this Reference is a Producer + * @return true if the Reference is a producer, false otherwise + */ + boolean isProducer(); + } diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java index 020870cd34..1436dbdeca 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java @@ -25,5 +25,23 @@ package org.apache.tuscany.sca.assembly; * @version $Rev$ $Date$ */ public interface Service extends AbstractService, Contract { + + /** + * Allows this Service to be set as a Consumer + * @param aConsumer - the consumer to set for this Service + */ + void setConsumer( Consumer aConsumer ); + + /** + * Gets the consumer for this Service + * @return the Consumer - null if no Consumer is set + */ + Consumer getConsumer(); + + /** + * Returns whether this Service is a Consumer + * @return true if the Service is a consumer, false otherwise + */ + boolean isConsumer(); } diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java index 5bbc547932..57c674d623 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java @@ -40,7 +40,9 @@ import org.apache.tuscany.sca.assembly.Consumer; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.EventBinding; import org.apache.tuscany.sca.assembly.EventBindingFactory; +import org.apache.tuscany.sca.assembly.EventTarget; import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Producer; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; @@ -1351,6 +1353,17 @@ public abstract class BaseConfigurationBuilderImpl { for (Producer producer : impl.getProducers()) { Reference reference = assemblyFactory.createReference(); reference.setName(producer.getName()); + // Add a pointer back to the Producer... Mike Edwards, 03/11/2008 + reference.setProducer(producer); + // For a Producer, the multiplicity is inherently 0..n Mike Edwards, 03/11/2008 + reference.setMultiplicity(Multiplicity.ONE_ONE); + // Copy through any target attribute Mike Edwards, 03/11/2008 + for( EventTarget target : producer.getTargets()) { + ComponentService targetService = assemblyFactory.createComponentService(); + targetService.setName( target.getName() ); + targetService.setUnresolved( true ); + reference.getTargets().add( targetService ); + } // end for reference.setInterfaceContract(producer.getInterfaceContract()); if (producer.getInterfaceContract() != null && producer.getInterfaceContract().getInterface() != null) producer.getInterfaceContract().getInterface().setRemotable(true); @@ -1370,6 +1383,8 @@ public abstract class BaseConfigurationBuilderImpl { for (Consumer consumer : impl.getConsumers()) { Service service = assemblyFactory.createService(); service.setName(consumer.getName()); + // Add a pointer back to the consumer... Mike Edwards, 03/11/2008 + service.setConsumer(consumer); service.setInterfaceContract(consumer.getInterfaceContract()); service.setType(consumer.getType()); service.getApplicablePolicySets().addAll(consumer.getApplicablePolicySets()); @@ -1388,6 +1403,18 @@ public abstract class BaseConfigurationBuilderImpl { for (Producer producer : component.getProducers()) { ComponentReference reference = assemblyFactory.createComponentReference(); reference.setName(producer.getName()); + // Add a pointer back to the Producer... Mike Edwards, 03/11/2008 + reference.setProducer(producer); + // For a Producer, the multiplicity is inherently 0..n Mike Edwards, 03/11/2008 + // FIXME (0..n implies an array in the implementation code - can't have this) + reference.setMultiplicity(Multiplicity.ONE_ONE); + // Copy through any target attribute Mike Edwards, 03/11/2008 + for( EventTarget target : producer.getTargets()) { + ComponentService targetService = assemblyFactory.createComponentService(); + targetService.setName( target.getName() ); + targetService.setUnresolved( true ); + reference.getTargets().add( targetService ); + } // end for reference.setInterfaceContract(producer.getInterfaceContract()); if (producer.getInterfaceContract() != null && producer.getInterfaceContract().getInterface() != null) producer.getInterfaceContract().getInterface().setRemotable(true); @@ -1408,6 +1435,8 @@ public abstract class BaseConfigurationBuilderImpl { for (Consumer consumer : component.getConsumers()) { ComponentService service = assemblyFactory.createComponentService(); service.setName(consumer.getName()); + // Add a pointer back to the consumer... Mike Edwards, 03/11/2008 + service.setConsumer(consumer); service.setInterfaceContract(consumer.getInterfaceContract()); service.setType(consumer.getType()); service.getApplicablePolicySets().addAll(consumer.getApplicablePolicySets()); diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java index b2f662918c..d0c3080da0 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java @@ -430,6 +430,9 @@ class BaseWireBuilderImpl { // Check that the target component service provides // a superset of the component reference interface if (componentReference.getInterfaceContract() == null || + // Handling for Producers and Consumers Mike Edwards, 03/11/2008 + // TODO - need to validate overlap of event types on producer and consumer + ( componentReference.isProducer() && targetComponentService.isConsumer() ) || interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { Endpoint endpoint = endpointFactory.createEndpoint(); @@ -685,7 +688,7 @@ class BaseWireBuilderImpl { // the result of calculating the endpoints is either that bindings have been // configured manually using a URI or that targets have been provided and the - // endpoint remains unresolved. So all endpoints should be either resved or uresolved. + // endpoint remains unresolved. So all endpoints should be either resolved or uresolved. boolean endpointsRequireAutomaticResolution = false; for(Endpoint endpoint : endpoints){ endpointsRequireAutomaticResolution = endpoint.isUnresolved(); diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConsumerImpl.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConsumerImpl.java index b2bf9f5059..cd8cc9c961 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConsumerImpl.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConsumerImpl.java @@ -20,6 +20,10 @@ package org.apache.tuscany.sca.assembly.impl; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.Map.Entry; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Callback; @@ -38,6 +42,7 @@ public class ConsumerImpl extends ContractImpl implements Consumer { private String name; private String theOperationName; + private Map< String, String > operations = new HashMap< String, String >(); private EventTypes theEventTypes = new EventTypesImpl(); private ArrayList<Binding> bindings = new ArrayList<Binding>(); private ArrayList<EventSource> sourceList = new ArrayList<EventSource>(); @@ -73,6 +78,42 @@ public class ConsumerImpl extends ContractImpl implements Consumer { return theEventTypes; } // end getEventType + // Operation related methods... + /** + * Adds an operation to the Consumer, with a list of the accepted event types + */ + public void addOperation( String operationName, String eventTypes ) { + operations.put(operationName, eventTypes); + } // end addOperation + + /** + * Returns the set of operations for this consumer + */ + public Set<String> getOperations() { + return operations.keySet(); + } // add operation + + /** + * Gets the name of the operation which handles a specific event type. + * Returns null if no operation handles the specified event type. + * eventType = null implies "handles any event type" + */ + public String getOperationByEventType( String eventType ) { + String anyOperation = null; + for( Entry<String, String> entry : operations.entrySet() ) { + String value = entry.getValue(); + if( value == null ) { + if( eventType == null ) return entry.getKey(); + // If the operation is marked as handling "any" event type, use this UNLESS there is another + // operation which specifically takes the requested event type... + anyOperation = entry.getKey(); + } else if( eventType != null ){ + if (value.contains(eventType)) return entry.getKey(); + } // end if + } // + return anyOperation; + } // end getOperationByEventType + public void setOperationName( String operationName ) { theOperationName = operationName; } // end setOperationName diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java index 1800222bfb..8f2a614083 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Callback; import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Producer; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.policy.PolicySet; @@ -42,6 +43,7 @@ public class ReferenceImpl extends AbstractReferenceImpl implements Reference, C private Callback callback; private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>(); private boolean promotionOverride; + private Producer theProducer = null; public List<PolicySet> getApplicablePolicySets() { return applicablePolicySets; @@ -129,5 +131,30 @@ public class ReferenceImpl extends AbstractReferenceImpl implements Reference, C public InterfaceContract getInterfaceContract(Binding binding){ return getInterfaceContract(); } + + /** + * Allows this Reference to be set as a Producer + * @param aProducer - the producer to set for this Reference + */ + public void setProducer( Producer aProducer ) { + theProducer = aProducer; + } // end setProducer + + /** + * Gets the producer for this Reference + * @return the Producer - null if no Producer is set + */ + public Producer getProducer() { + return theProducer; + } // end getProducer + + /** + * Returns whether this Reference is a Producer + * @return true if the Reference is a producer, false otherwise + */ + public boolean isProducer() { + return (!(theProducer == null )); + } // end isProducer + } diff --git a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java index 8d745cb7e1..c41a4cb3b7 100644 --- a/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java +++ b/sandbox/event/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Callback; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Consumer; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.policy.PolicySet; @@ -38,6 +39,7 @@ public class ServiceImpl extends AbstractServiceImpl implements Service, Cloneab private List<PolicySet> policySets = new ArrayList<PolicySet>(); private Callback callback; private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>(); + private Consumer theConsumer = null; public List<PolicySet> getApplicablePolicySets() { return applicablePolicySets; @@ -103,5 +105,29 @@ public class ServiceImpl extends AbstractServiceImpl implements Service, Cloneab public InterfaceContract getInterfaceContract(Binding binding){ return getInterfaceContract(); } + + /** + * Allows this Service to be set as a Consumer + * @param aConsumer - the consumer to set for this Service + */ + public void setConsumer( Consumer aConsumer ) { + theConsumer = aConsumer; + } // end setConsumer + + /** + * Gets the consumer for this Service + * @return the Consumer - null if no Consumer is set + */ + public Consumer getConsumer() { + return theConsumer; + } // end getConsumer + + /** + * Returns whether this Service is a Consumer + * @return true if the Service is a consumer, false otherwise + */ + public boolean isConsumer() { + return ( !( theConsumer == null ) ); + } // end isConsumer } |