Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 59 files changed
  • 0 commit comments
  • 5 contributors
Commits on Jan 16, 2012
@cunningt SWITCHYARD-591
Add a temporary suppression for BPMServicePlugin and the number of parameters
used there.    Once SWITCHYARD-619 is solved, then this temporary suppression
should be removed.
b184f1d
Commits on Feb 03, 2012
@rnc rnc SWITCHYARD-613 Refactor pom to use AS BOM aa25859
@errantepiphany errantepiphany SWITCHYARD-635: Provide implementation-agnostic way for users' applic…
…ations to control BPM tasks
132c0e4
Commits on Feb 08, 2012
@igarashitm igarashitm SWITCHYARD-574 HTTPMixIn improvements
- dump input/output message when _dumpMessages is true
- added request header processing and response header evaluating
b6174b9
@igarashitm igarashitm SWITCHYARD-620 insufficient error message from bean component 2071ba9
@rnc rnc SWITCHYARD-643 Upgrade JUnit to 4.10 and use version from AS7 449feb4
@kcbabo kcbabo SWITCHYARD-221 Introduce a way to lookup a ServiceReference eadfe11
Commits on Feb 10, 2012
@kcbabo kcbabo SWITCHYARD-226 Camel bindings need to support WSDL interface type 1ad3a84
Showing with 1,424 additions and 1,188 deletions.
  1. +61 −0 api/src/main/java/org/switchyard/Service.java
  2. +57 −45 api/src/main/java/org/switchyard/ServiceDomain.java
  3. +40 −6 api/src/main/java/org/switchyard/ServiceReference.java
  4. +13 −10 api/src/main/java/org/switchyard/metadata/BaseExchangeContract.java
  5. +2 −1  api/src/main/java/org/switchyard/metadata/BaseService.java
  6. +2 −0  build/src/main/resources/checkstyle/suppressions.xml
  7. +34 −18 bus/hornetq/pom.xml
  8. +3 −3 bus/hornetq/src/main/java/org/switchyard/bus/hornetq/HornetQBus.java
  9. +4 −4 bus/hornetq/src/main/java/org/switchyard/bus/hornetq/HornetQDispatcher.java
  10. +4 −4 bus/hornetq/src/test/java/org/switchyard/bus/hornetq/HornetQBusTest.java
  11. +5 −5 bus/hornetq/src/test/java/org/switchyard/bus/hornetq/HornetQDispatcherTest.java
  12. +21 −16 bus/hornetq/src/test/java/org/switchyard/bus/hornetq/{MockServiceReference.java → MockService.java}
  13. +21 −1 config/src/main/java/org/switchyard/config/model/composite/BindingModel.java
  14. +17 −1 config/src/main/java/org/switchyard/config/model/composite/v1/V1BindingModel.java
  15. +17 −0 config/src/test/java/org/switchyard/config/model/composite/CompositeModelTests.java
  16. +7 −0 deploy/base/pom.xml
  17. +2 −1  deploy/base/src/main/java/org/switchyard/SwitchYard.java
  18. +38 −24 deploy/base/src/main/java/org/switchyard/deploy/Activator.java
  19. +30 −0 deploy/base/src/main/java/org/switchyard/deploy/BaseActivator.java
  20. +39 −0 deploy/base/src/main/java/org/switchyard/deploy/BaseServiceHandler.java
  21. +0 −119 deploy/base/src/main/java/org/switchyard/deploy/DomainProxy.java
  22. +9 −113 deploy/base/src/main/java/org/switchyard/deploy/ServiceDomainManager.java
  23. +40 −0 deploy/base/src/main/java/org/switchyard/deploy/ServiceHandler.java
  24. +138 −128 deploy/base/src/main/java/org/switchyard/deploy/internal/Deployment.java
  25. +0 −22 deploy/base/src/test/java/org/switchyard/deploy/BaseActivatorTest.java
  26. +1 −47 deploy/base/src/test/java/org/switchyard/deploy/ServiceDomainManagerTest.java
  27. +51 −25 deploy/base/src/test/java/org/switchyard/deploy/components/MockActivator.java
  28. +18 −15 deploy/base/src/test/java/org/switchyard/deploy/internal/DeploymentTest.java
  29. +1 −1  deploy/cdi/src/main/java/org/switchyard/deploy/cdi/SwitchYardCDIDeployer.java
  30. +16 −0 runtime/pom.xml
  31. +9 −1 runtime/src/main/java/org/switchyard/internal/DefaultHandlerChain.java
  32. +10 −14 runtime/src/main/java/org/switchyard/internal/DefaultServiceRegistry.java
  33. +130 −38 runtime/src/main/java/org/switchyard/internal/DomainImpl.java
  34. +6 −6 runtime/src/main/java/org/switchyard/internal/LocalExchangeBus.java
  35. +94 −0 runtime/src/main/java/org/switchyard/internal/ServiceImpl.java
  36. +54 −19 runtime/src/main/java/org/switchyard/internal/ServiceReferenceImpl.java
  37. +0 −78 runtime/src/main/java/org/switchyard/internal/ServiceRegistration.java
  38. +2 −2 runtime/src/main/java/org/switchyard/spi/Dispatcher.java
  39. +4 −4 runtime/src/main/java/org/switchyard/spi/ExchangeBus.java
  40. +0 −54 runtime/src/main/java/org/switchyard/spi/Service.java
  41. +4 −4 runtime/src/main/java/org/switchyard/spi/ServiceRegistry.java
  42. +33 −1 runtime/src/test/java/org/switchyard/MockDomain.java
  43. +8 −11 runtime/src/test/java/org/switchyard/handlers/MessageTraceTest.java
  44. +5 −6 runtime/src/test/java/org/switchyard/internal/DefaultServiceRegistryTest.java
  45. +27 −26 runtime/src/test/java/org/switchyard/internal/DomainImplTest.java
  46. +26 −81 runtime/src/test/java/org/switchyard/internal/ExchangeImplTest.java
  47. +56 −0 runtime/src/test/java/org/switchyard/internal/ServiceImplTest.java
  48. +5 −4 runtime/src/test/java/org/switchyard/internal/io/ExchangeSerializationTests.java
  49. +5 −8 runtime/src/test/java/org/switchyard/tests/InOnlyTest.java
  50. +6 −11 runtime/src/test/java/org/switchyard/tests/InOutTest.java
  51. +5 −9 runtime/src/test/java/org/switchyard/tests/TransformationTest.java
  52. +5 −12 runtime/src/test/java/org/switchyard/tests/ValidationTest.java
  53. +1 −1  test/pom.xml
  54. +13 −57 test/src/main/java/org/switchyard/test/Invoker.java
  55. +7 −6 test/src/main/java/org/switchyard/test/SwitchYardTestKit.java
  56. +103 −118 test/src/main/java/org/switchyard/test/mixins/BPMMixIn.java
  57. +3 −3 test/src/main/java/org/switchyard/test/mixins/CDIMixIn.java
  58. +111 −5 test/src/main/java/org/switchyard/test/mixins/HTTPMixIn.java
  59. +1 −0  transform/src/main/resources/META-INF/switchyard/transforms.xml
View
61 api/src/main/java/org/switchyard/Service.java
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.switchyard;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.switchyard.metadata.ServiceInterface;
+import org.switchyard.policy.Policy;
+
+/**
+ * A service registered with the SwitchYard runtime.
+ */
+public interface Service {
+ /**
+ * Qualified name of the service.
+ * @return service name
+ */
+ QName getName();
+ /**
+ * Interface metadata for the registered service.
+ * @return the service interface
+ */
+ ServiceInterface getInterface();
+
+ /**
+ * Unregisters this service from the domain it's registered in.
+ */
+ void unregister();
+
+
+ /**
+ * The domain in which this service reference is registered.
+ * @return service domain which created this service reference
+ */
+ ServiceDomain getDomain();
+
+ /**
+ * Returns a list of required policies for this service.
+ * @return list of required policy
+ */
+ List<Policy> getRequiredPolicy();
+}
View
102 api/src/main/java/org/switchyard/ServiceDomain.java
@@ -23,7 +23,6 @@
import javax.xml.namespace.QName;
-import org.switchyard.metadata.ExchangeContract;
import org.switchyard.metadata.ServiceInterface;
import org.switchyard.policy.Policy;
import org.switchyard.transform.TransformerRegistry;
@@ -32,7 +31,7 @@
/**
* A ServiceDomain represents a collection of services with a shared set of
* resources, configuration, and policy definitions. The ServiceDomain
- * interface is used by software components to provide and/or consume
+ * interface is used by software components to provide and/or consume
* services. These software components include protocol gateways, service
* containers, translation engines, adapters, orchestration and routing
* engines.
@@ -46,69 +45,82 @@
QName getName();
/**
- * Return a service instance bound to the specified name.
- * @param serviceName name of the service
- * @return service instance or null if no such service was found
- */
- ServiceReference getService(QName serviceName);
-
- /**
- * Creates a new Exchange to invoke service with the specified exchange
- * pattern.
- * @param service the service to invoke
- * @param contract the exchange contract to use
- * @return a new Exchange instance
- */
- Exchange createExchange(ServiceReference service, ExchangeContract contract);
- /**
- * Creates a new Exchange to invoke service with the specified exchange
- * pattern. The supplied ExchangeHandler is used to handle any faults or
- * reply messages that are generated as part of the message exchange.
- * @param service the service to invoke
- * @param contract the exchange contract to use
- * @param handler used to process response and fault messages
- * @return a new Exchange instance
- */
- Exchange createExchange(ServiceReference service, ExchangeContract contract,
- ExchangeHandler handler);
-
- /**
* Register a service with the domain.
* @param serviceName the name of the service
* @param handler the handler to use to process exchanges directed at this
* service
- * @return a reference to the registered service that can be used to
- * unregister when required
+ * @param metadata service interface details
+ * @return the registered service
*/
- ServiceReference registerService(QName serviceName, ExchangeHandler handler);
-
+ Service registerService(QName serviceName,
+ ServiceInterface metadata,
+ ExchangeHandler handler);
+
/**
* Register a service with the domain.
* @param serviceName the name of the service
* @param handler the handler to use to process exchanges directed at this
* service
* @param metadata service interface details
+ * @param requires policy requirements for the service
+ * @return the registered service
+ */
+ Service registerService(QName serviceName,
+ ServiceInterface metadata,
+ ExchangeHandler handler,
+ List<Policy> requires);
+
+ /**
+ * Register a service reference with the domain.
+ * @param serviceName the name of the reference
+ * @param metadata service consumer contract
* @return a reference to the registered service that can be used to
* unregister when required
*/
- ServiceReference registerService(QName serviceName,
- ExchangeHandler handler,
- ServiceInterface metadata);
+ ServiceReference registerServiceReference(QName serviceName, ServiceInterface metadata);
/**
- * Register a service with the domain.
- * @param serviceName the name of the service
- * @param handler the handler to use to process exchanges directed at this
- * service
- * @param metadata service interface details
- * @param requires policy requirements for the service
+ * Register a service reference with the domain.
+ * @param serviceName the name of the reference
+ * @param metadata service consumer contract
+ * @param handler the handler to use to process replies from the service
* @return a reference to the registered service that can be used to
* unregister when required
*/
- ServiceReference registerService(QName serviceName,
- ExchangeHandler handler,
+ ServiceReference registerServiceReference(QName serviceName,
ServiceInterface metadata,
- List<Policy> requires);
+ ExchangeHandler handler);
+
+ /**
+ * Register a service reference with the domain.
+ * @param serviceName the name of the reference
+ * @param metadata service consumer contract
+ * @param handler the handler to use to process replies from the service
+ * @param provides policies provided by the reference
+ * @return a reference to the registered service that can be used to
+ * unregister when required
+ */
+ ServiceReference registerServiceReference(QName serviceName,
+ ServiceInterface metadata,
+ ExchangeHandler handler,
+ List<Policy> provides);
+
+ /**
+ * Fetches a registered service reference for the specified name.
+ * @param serviceName name of the service reference
+ * @return registered service reference, or null if no references have
+ * been registered with the specified name.
+ */
+ ServiceReference getServiceReference(QName serviceName);
+
+ /**
+ * Wire a service reference to a registered service. The default wiring
+ * of a reference maps it to a service with the same name. This method
+ * can be used to map references to services with a different name.
+ * @param reference service reference
+ * @param service service provider
+ */
+ void wireReference(ServiceReference reference, Service service);
/**
* Returns a references to the transformer registry for this domain.
View
46 api/src/main/java/org/switchyard/ServiceReference.java
@@ -19,11 +19,13 @@
package org.switchyard;
-import org.switchyard.metadata.ExchangeContract;
-import org.switchyard.metadata.ServiceInterface;
+import java.util.List;
import javax.xml.namespace.QName;
+import org.switchyard.metadata.ServiceInterface;
+import org.switchyard.policy.Policy;
+
/**
* A service registered with the SwitchYard runtime.
*/
@@ -33,25 +35,57 @@
* @return service name
*/
QName getName();
+
/**
* Interface metadata for the registered service.
* @return the service interface
*/
ServiceInterface getInterface();
+
+ /**
+ * Creates a new Exchange to invoke this service. Since this method does
+ * not accept an operation name, it should only be used when the service
+ * interface contains a single operation.
+ * @return a new Exchange instance
+ */
+ Exchange createExchange();
+
+ /**
+ * Creates a new Exchange to invoke this service, with replies handled by
+ * the specified ExchangeHandler. Since this method does
+ * not accept an operation name, it should only be used when the service
+ * interface contains a single operation.
+ * @param handler used to process reply messages
+ * @return a new Exchange instance
+ */
+ Exchange createExchange(ExchangeHandler handler);
+
/**
* Creates a new Exchange to invoke this service with the specified exchange
* pattern.
- * @param contract the exchange contract to use
+ * @param operation the operation to invoke
* @return a new Exchange instance
*/
- Exchange createExchange(ExchangeContract contract);
+ Exchange createExchange(String operation);
+
/**
* Creates a new Exchange to invoke this service with the specified exchange
* pattern. The supplied ExchangeHandler is used to handle any faults or
* reply messages that are generated as part of the message exchange.
- * @param contract the exchange contract to use
+ * @param operation the operation to invoke
* @param handler used to process response and fault messages
* @return a new Exchange instance
*/
- Exchange createExchange(ExchangeContract contract, ExchangeHandler handler);
+ Exchange createExchange(String operation, ExchangeHandler handler);
+
+ /**
+ * Returns a list of policies provided by this service reference.
+ * @return list of provided policy
+ */
+ List<Policy> getProvidedPolicy();
+
+ /**
+ * Unregisters this service reference from the domain it's registered in.
+ */
+ void unregister();
}
View
23 api/src/main/java/org/switchyard/metadata/BaseExchangeContract.java
@@ -31,22 +31,25 @@
public class BaseExchangeContract implements ExchangeContract {
private ServiceOperation _operation;
- private BaseInvocationContract _invokerInvocationMetadata = new BaseInvocationContract();
-
+ private InvocationContract _invoker;
+
/**
- * Public constructor.
- * @param operation The target service operation.
+ * Create a new BaseExchangeContract with the specified invocation contract.
+ * @param operation contract for the service provider
+ * @param invoker contract for the service consumer
*/
- public BaseExchangeContract(ServiceOperation operation) {
- if (operation == null) {
- throw new IllegalArgumentException("null 'operation' arg.");
+ public BaseExchangeContract(ServiceOperation operation, ServiceOperation invoker) {
+ if (operation == null || invoker == null) {
+ throw new IllegalArgumentException(
+ "BaseExchangeContract: operation and invoker parameters required");
}
- this._operation = operation;
+ _operation = operation;
+ _invoker = invoker;
}
@Override
- public BaseInvocationContract getInvokerInvocationMetaData() {
- return _invokerInvocationMetadata;
+ public InvocationContract getInvokerInvocationMetaData() {
+ return _invoker;
}
@Override
View
3  api/src/main/java/org/switchyard/metadata/BaseService.java
@@ -82,7 +82,8 @@ public BaseService(Set<ServiceOperation> operations, String type) {
public ServiceOperation getOperation(String name) {
ServiceOperation operation = null;
for (ServiceOperation op : _operations) {
- if (op.getName().equals(name)) {
+ // the '==' covers null equality
+ if (op.getName() == name || op.getName().equals(name)) {
operation = op;
break;
}
View
2  build/src/main/resources/checkstyle/suppressions.xml
@@ -12,4 +12,6 @@
choking and throwing an Exception -->
<suppress checks="[a-zA-Z0-9]*"
files="org/switchyard/tools/maven/plugins/switchyard/ConfigureMojo.java"/>
+ <suppress checks="ParameterNumber"
+ files="org/switchyard/tools/forge/bpm/BPMServicePlugin.java"/>
</suppressions>
View
52 bus/hornetq/pom.xml
@@ -35,12 +35,42 @@
<description>Bus provider using HornetQ Core</description>
<url>http://switchyard.org/</url>
- <!-- overriding hornetq version as the newer version is incompatible -->
- <properties>
- <version.hornetq>2.1.1.Final</version.hornetq>
- </properties>
+ <!-- overriding hornetq version as the newer version is incompatible -->
+ <properties>
+ <version.hornetq>2.1.1.Final</version.hornetq>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-core</artifactId>
+ <version>${version.hornetq}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-core-client</artifactId>
+ <version>${version.hornetq}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-core-client</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.netty</groupId>
+ <artifactId>netty</artifactId>
+ </dependency>
+
<!-- internal dependencies -->
<dependency>
<groupId>org.switchyard</groupId>
@@ -55,20 +85,6 @@
<artifactId>switchyard-test</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.hornetq</groupId>
- <artifactId>hornetq-core</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.netty</groupId>
- <artifactId>netty</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hornetq</groupId>
- <artifactId>hornetq-core-client</artifactId>
- <scope>compile</scope>
- </dependency>
<!-- N/A -->
<!-- external dependencies -->
<dependency>
View
6 bus/hornetq/src/main/java/org/switchyard/bus/hornetq/HornetQBus.java
@@ -40,7 +40,7 @@
import org.hornetq.core.server.HornetQServers;
import org.hornetq.core.server.JournalType;
import org.switchyard.HandlerChain;
-import org.switchyard.ServiceReference;
+import org.switchyard.Service;
import org.switchyard.exception.SwitchYardException;
import org.switchyard.spi.Dispatcher;
import org.switchyard.spi.ExchangeBus;
@@ -126,13 +126,13 @@ public synchronized void stop() {
}
@Override
- public Dispatcher getDispatcher(ServiceReference service) {
+ public Dispatcher getDispatcher(Service service) {
return _dispatchers.get(service.getName());
}
@Override
public synchronized Dispatcher createDispatcher(
- ServiceReference service, HandlerChain handlerChain, TransformerRegistry transformerRegistry) {
+ Service service, HandlerChain handlerChain, TransformerRegistry transformerRegistry) {
HornetQDispatcher endpoint = new HornetQDispatcher(service, _clientFactory, handlerChain, transformerRegistry);
_dispatchers.put(service.getName(), endpoint);
endpoint.start();
View
8 bus/hornetq/src/main/java/org/switchyard/bus/hornetq/HornetQDispatcher.java
@@ -40,7 +40,7 @@
import org.switchyard.ExchangePhase;
import org.switchyard.HandlerChain;
import org.switchyard.Scope;
-import org.switchyard.ServiceReference;
+import org.switchyard.Service;
import org.switchyard.common.type.reflect.FieldAccess;
import org.switchyard.exception.SwitchYardException;
import org.switchyard.internal.DefaultMessage;
@@ -61,7 +61,7 @@
private static final Serializer SERIALIZER = SerializerType.DEFAULT.instance();
- private ServiceReference _service;
+ private Service _service;
private DispatchQueue _inQueue;
private DispatchQueue _outQueue;
private ClientSessionFactory _sessionFactory;
@@ -76,7 +76,7 @@
* @param inputHandler the exchange handler used to process exchanges for the service
* @param transformerRegistry The {@link TransformerRegistry}.
*/
- public HornetQDispatcher(ServiceReference service,
+ public HornetQDispatcher(Service service,
ClientSessionFactory sessionFactory,
HandlerChain inputHandler, TransformerRegistry transformerRegistry) {
_service = service;
@@ -86,7 +86,7 @@ public HornetQDispatcher(ServiceReference service,
}
@Override
- public ServiceReference getService() {
+ public Service getService() {
return _service;
}
View
8 bus/hornetq/src/test/java/org/switchyard/bus/hornetq/HornetQBusTest.java
@@ -31,7 +31,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.switchyard.ServiceReference;
+import org.switchyard.Service;
import org.switchyard.internal.DefaultHandlerChain;
import org.switchyard.metadata.InOnlyService;
import org.switchyard.metadata.InOutService;
@@ -58,18 +58,18 @@ public void tearDown() throws Exception {
public void testCreateDispatcher() throws Exception {
// verify that dispatchers can be created for an InOnly service
_provider.createDispatcher(
- new MockServiceReference(new QName("inOnly"), new InOnlyService()),
+ new MockService(new QName("inOnly"), new InOnlyService()),
new DefaultHandlerChain(), null);
// verify that dispatchers can be created for an InOut service
_provider.createDispatcher(
- new MockServiceReference(new QName("inOut"), new InOutService()),
+ new MockService(new QName("inOut"), new InOutService()),
new DefaultHandlerChain(), null);
}
@Test
public void testGetDispatcher() throws Exception {
- ServiceReference service = new MockServiceReference(new QName("testGetDispatcher"));
+ Service service = new MockService(new QName("testGetDispatcher"));
Dispatcher dispatch = _provider.createDispatcher(service, new DefaultHandlerChain(), null);
Assert.assertEquals(dispatch, _provider.getDispatcher(service));
View
10 bus/hornetq/src/test/java/org/switchyard/bus/hornetq/HornetQDispatcherTest.java
@@ -36,7 +36,7 @@
import org.switchyard.HandlerChain;
import org.switchyard.HandlerException;
import org.switchyard.Scope;
-import org.switchyard.ServiceReference;
+import org.switchyard.Service;
import org.switchyard.internal.DefaultHandlerChain;
import org.switchyard.internal.ExchangeImpl;
import org.switchyard.metadata.ExchangeContract;
@@ -63,8 +63,8 @@ public void tearDown() throws Exception {
@Test
public void testDispatchInOnly() throws Exception {
- ServiceReference service = new MockServiceReference(
- new QName("testDispatchInOnly"),new InOnlyService());
+ Service service = new MockService(
+ new QName("testDispatchInOnly"), new InOnlyService());
HandlerChain inHandlers = new DefaultHandlerChain();
ExchangeSink sink = new ExchangeSink();
inHandlers.addLast("in", sink);
@@ -82,8 +82,8 @@ public void testDispatchInOnly() throws Exception {
@Test
public void testDispatchInOut() throws Exception {
- ServiceReference service = new MockServiceReference(
- new QName("testDispatchInOut"),new InOutService());
+ Service service = new MockService(
+ new QName("testDispatchInOut"), new InOutService());
// provider handlers
HandlerChain inHandlers = new DefaultHandlerChain();
ExchangeSink inHandler = new ExchangeSink(true);
View
37 .../switchyard/bus/hornetq/MockServiceReference.java → .../java/org/switchyard/bus/hornetq/MockService.java
@@ -19,48 +19,53 @@
package org.switchyard.bus.hornetq;
+import java.util.List;
+
import javax.xml.namespace.QName;
-import org.switchyard.Exchange;
-import org.switchyard.ExchangeHandler;
-import org.switchyard.ServiceReference;
-import org.switchyard.metadata.ExchangeContract;
+import org.switchyard.Service;
+import org.switchyard.ServiceDomain;
import org.switchyard.metadata.InOnlyService;
import org.switchyard.metadata.ServiceInterface;
+import org.switchyard.policy.Policy;
-public class MockServiceReference implements ServiceReference {
+public class MockService implements Service {
private QName _serviceName;
private ServiceInterface _serviceInterface;
- public MockServiceReference(QName serviceName) {
+ public MockService(QName serviceName) {
this(serviceName, new InOnlyService());
}
- public MockServiceReference(QName serviceName, ServiceInterface serviceInterface) {
+ public MockService(QName serviceName, ServiceInterface serviceInterface) {
_serviceName = serviceName;
_serviceInterface = serviceInterface;
}
@Override
- public Exchange createExchange(ExchangeContract contract) {
- return null;
+ public ServiceInterface getInterface() {
+ return _serviceInterface;
}
@Override
- public Exchange createExchange(ExchangeContract contract,
- ExchangeHandler handler) {
- return null;
+ public QName getName() {
+ return _serviceName;
}
@Override
- public ServiceInterface getInterface() {
- return _serviceInterface;
+ public void unregister() {
+
}
@Override
- public QName getName() {
- return _serviceName;
+ public ServiceDomain getDomain() {
+ return null;
+ }
+
+ @Override
+ public List<Policy> getRequiredPolicy() {
+ return null;
}
}
View
22 config/src/main/java/org/switchyard/config/model/composite/BindingModel.java
@@ -34,10 +34,30 @@
public static final String BINDING = "binding";
/**
- * Gets the parent composite model.
+ * Gets the parent service model. This method will return null if
+ * the binding model is attached to a reference instead of a service.
* @return the parent composite model
*/
public CompositeServiceModel getService();
+
+ /**
+ * Gets the parent reference model. This method will return null if
+ * the binding model is attached to a service instead of a reference.
+ * @return the parent composite model
+ */
+ public CompositeReferenceModel getReference();
+
+ /**
+ * Is this binding attached to a service?
+ * @return true if this is a service binding, false if it's a reference binding.
+ */
+ public boolean isServiceBinding();
+
+ /**
+ * Is this binding attached to a reference?
+ * @return true if this is a reference binding, false if it's a service binding.
+ */
+ public boolean isReferenceBinding();
/**
* Gets the child context mapper model.
View
18 config/src/main/java/org/switchyard/config/model/composite/v1/V1BindingModel.java
@@ -33,6 +33,7 @@
import org.switchyard.config.model.composer.MessageComposerModel;
import org.switchyard.config.model.composite.BindingModel;
import org.switchyard.config.model.composite.CompositeModel;
+import org.switchyard.config.model.composite.CompositeReferenceModel;
import org.switchyard.config.model.composite.CompositeServiceModel;
/**
@@ -91,7 +92,12 @@ protected final Model setModelChildrenOrder(String... childrenOrder) {
*/
@Override
public CompositeServiceModel getService() {
- return (CompositeServiceModel)getModelParent();
+ return isServiceBinding() ? (CompositeServiceModel)getModelParent() : null;
+ }
+
+ @Override
+ public CompositeReferenceModel getReference() {
+ return isReferenceBinding() ? (CompositeReferenceModel)getModelParent() : null;
}
/**
@@ -116,4 +122,14 @@ public MessageComposerModel getMessageComposer() {
return _messageComposer;
}
+ @Override
+ public boolean isServiceBinding() {
+ return (getModelParent() instanceof CompositeServiceModel);
+ }
+
+ @Override
+ public boolean isReferenceBinding() {
+ return (getModelParent() instanceof CompositeReferenceModel);
+ }
+
}
View
17 config/src/test/java/org/switchyard/config/model/composite/CompositeModelTests.java
@@ -160,6 +160,23 @@ public void testReadComplete() throws Exception {
Assert.assertEquals("java", interface3.getType());
Assert.assertEquals("org.switchyard.example.m1app.AnotherService", interface3.getInterface());
}
+
+ @Test
+ public void testBindingModel() throws Exception {
+ CompositeModel composite = _puller.pull(COMPLETE_XML, getClass());
+ // Test service binding
+ BindingModel serviceBinding = composite.getServices().get(0).getBindings().get(0);
+ Assert.assertTrue(serviceBinding.isServiceBinding());
+ Assert.assertFalse(serviceBinding.isReferenceBinding());
+ Assert.assertNotNull(serviceBinding.getService());
+ Assert.assertNull(serviceBinding.getReference());
+ // Test reference binding
+ BindingModel referenceBinding = composite.getReferences().get(0).getBindings().get(0);
+ Assert.assertTrue(referenceBinding.isReferenceBinding());
+ Assert.assertFalse(referenceBinding.isServiceBinding());
+ Assert.assertNotNull(referenceBinding.getReference());
+ Assert.assertNull(referenceBinding.getService());
+ }
@Test
public void testWriteComplete() throws Exception {
View
7 deploy/base/pom.xml
@@ -78,5 +78,12 @@
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.switchyard</groupId>
+ <artifactId>switchyard-runtime</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
View
3  deploy/base/src/main/java/org/switchyard/SwitchYard.java
@@ -57,7 +57,8 @@ public SwitchYard(InputStream config) throws IOException {
*/
public void start() {
_logger.debug("Starting SwitchYard application '" + _deployment.getConfig().getQName() + "'.");
- ServiceDomain serviceDomain = ServiceDomainManager.createDomain(_deployment.getConfig().getQName(), _deployment.getConfig());
+ ServiceDomain serviceDomain = new ServiceDomainManager().createDomain(
+ _deployment.getConfig().getQName(), _deployment.getConfig());
_deployment.init(serviceDomain, ActivatorLoader.createActivators(serviceDomain));
_deployment.start();
_logger.debug("SwitchYard application '" + _deployment.getConfig().getQName() + "' started.");
View
62 deploy/base/src/main/java/org/switchyard/deploy/Activator.java
@@ -23,9 +23,8 @@
import javax.xml.namespace.QName;
-import org.switchyard.ExchangeHandler;
-import org.switchyard.ServiceReference;
-import org.switchyard.config.model.Model;
+import org.switchyard.config.model.composite.BindingModel;
+import org.switchyard.config.model.composite.ComponentModel;
/**
* Activators allow components to participate in the deployment lifecycle of
@@ -37,37 +36,52 @@
* in the appropriate order.
*/
public interface Activator {
+
/**
- * Initialize a service or service reference based on the supplied
- * configuration. Activator instances should attempt to validate
- * configuration, policy, and any runtime constraints during init and fail
- * fast if there is a problem.
+ * Activate a reference or service binding. This is equivalent to a
+ * create/init for the binding and it's configuration. Validation errors
+ * with config should be reported from this method.
* @param name name of the service or reference
- * @param config switchyard configuration for the service or reference
- * @return exchange handler to use for the service or reference. In the case
- * of a reference, the handler will be used as the default callback handler
- * for all exchanges.
+ * @param config binding configuration
+ * @return a lifecycle-aware service handler used to process exchanges
*/
- ExchangeHandler init(QName name, Model config);
+ ServiceHandler activateBinding(QName name, BindingModel config);
/**
- * Start the specified service or reference.
- * @param service service to start
+ * Activate a service implementation. This is equivalent to a
+ * create/init for the service implementation and it's configuration.
+ * Validation errors with config should be reported from this method. Note
+ * that if a service component declares multiple services for a single
+ * implementation, this method will be called once for each service on
+ * that implementation.
+ * @param name name of the service
+ * @param config component configuration
+ * @return a lifecycle-aware service handler used to process exchanges
*/
- void start(ServiceReference service);
+ ServiceHandler activateService(QName name, ComponentModel config);
+
/**
- * Stop the specified service or reference.
- * @param service service to stop
+ * Deactivate a binding. This is equivalent to remove/destroy for the
+ * binding. The handler that was returned from activateBinding() is
+ * passed as a parameter in case it's needed for callback purposes.
+ * @param name name of the service or reference binding
+ * @param handler the handler returned from activateBinding
*/
- void stop(ServiceReference service);
+ void deactivateBinding(QName name, ServiceHandler handler);
+
/**
- * Destroy the specified service or reference. Once destroyed, the activator
- * should be capable of launching a clean instance of this service or
- * reference through an init() call (e.g. application redeployment).
- * @param service service to destroy
+ * Deactivate a service. This is equivalent to remove/destroy for the
+ * service. The handler that was returned from activateService() is
+ * passed as a parameter in case it's needed for callback purposes. Note
+ * that if a service component declares multiple services for a single
+ * implementation, this method will be called once for each service on
+ * that implementation.
+ * @param name name of the service
+ * @param handler the handler returned from activateService
*/
- void destroy(ServiceReference service);
+ void deactivateService(QName name, ServiceHandler handler);
+
/**
- * An Activator can handle activation of certain types.
+ * Whether the activator can handle a given .
* @param type activation type
* @return true If this Activator can activate the passed-in type.
*/
View
30 deploy/base/src/main/java/org/switchyard/deploy/BaseActivator.java
@@ -25,7 +25,11 @@
import java.util.LinkedList;
import java.util.List;
+import javax.xml.namespace.QName;
+
import org.switchyard.ServiceDomain;
+import org.switchyard.config.model.composite.BindingModel;
+import org.switchyard.config.model.composite.ComponentModel;
/**
* Base implementation of Activator which provides a convenience implementation
@@ -41,6 +45,32 @@ protected BaseActivator(String ... types) {
_activationTypes.addAll(Arrays.asList(types));
}
}
+
+ @Override
+ public ServiceHandler activateBinding(QName name, BindingModel config) {
+ throw new UnsupportedOperationException(
+ "activateBinding() not supported by " + getClass());
+ }
+
+ @Override
+ public ServiceHandler activateService(QName name, ComponentModel config) {
+ throw new UnsupportedOperationException(
+ "deactivateService() not supported by " + getClass());
+ }
+
+
+ @Override
+ public void deactivateBinding(QName name, ServiceHandler handler) {
+ throw new UnsupportedOperationException(
+ "deactivateBinding() not supported by " + getClass());
+ }
+
+ @Override
+ public void deactivateService(QName name, ServiceHandler handler) {
+ throw new UnsupportedOperationException(
+ "deactivateService() not supported by " + getClass());
+ }
+
/**
* Sets the service domain instance of this activator.
View
39 deploy/base/src/main/java/org/switchyard/deploy/BaseServiceHandler.java
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.switchyard.deploy;
+
+import org.switchyard.BaseHandler;
+
+/**
+ * NOP implementation of ServiceHandler.
+ */
+public class BaseServiceHandler extends BaseHandler implements ServiceHandler {
+
+ @Override
+ public void start() {
+ // NOP
+ }
+
+ @Override
+ public void stop() {
+ // NOP
+ }
+
+}
View
119 deploy/base/src/main/java/org/switchyard/deploy/DomainProxy.java
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
- * as indicated by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-
-package org.switchyard.deploy;
-
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.switchyard.Exchange;
-import org.switchyard.ExchangeHandler;
-import org.switchyard.HandlerChain;
-import org.switchyard.ServiceDomain;
-import org.switchyard.ServiceReference;
-import org.switchyard.metadata.ExchangeContract;
-import org.switchyard.metadata.ServiceInterface;
-import org.switchyard.policy.Policy;
-import org.switchyard.transform.TransformerRegistry;
-import org.switchyard.validate.ValidatorRegistry;
-
-/**
- * Domain Proxy class.
- * <p/>
- * This class ensures that Services are searched for across all Service Domains (1 domain/app),
- * while Transformer lookup only happens on within the application's ServiceDomain i.e. it
- * ensures that Transformers are scoped around the application.
- *
- * @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
- */
-class DomainProxy implements ServiceDomain {
-
- private ServiceDomain _domain;
- private ServiceDomainManager _domainManager;
-
- public DomainProxy(ServiceDomain domain, ServiceDomainManager domainManager) {
- this._domain = domain;
- this._domainManager = domainManager;
- }
-
- @Override
- public QName getName() {
- return _domain.getName();
- }
-
- /**
- * Get the proxied ServiceDomain.
- * @return The proxied service domain.
- */
- public ServiceDomain getDomain() {
- return _domain;
- }
-
- @Override
- public ServiceReference getService(QName serviceName) {
- ServiceReference service = _domain.getService(serviceName);
- if (service == null) {
- // Look for the service across the other domains, excluding the domain
- // associated with this proxy...
- service = _domainManager.findService(serviceName, _domain);
- }
- return service;
- }
-
- @Override
- public Exchange createExchange(ServiceReference service, ExchangeContract contract) {
- return _domain.createExchange(service, contract);
- }
-
- @Override
- public Exchange createExchange(ServiceReference service, ExchangeContract contract, ExchangeHandler handler) {
- return _domain.createExchange(service, contract, handler);
- }
-
- @Override
- public ServiceReference registerService(QName serviceName, ExchangeHandler handler) {
- return _domain.registerService(serviceName, handler);
- }
-
- @Override
- public ServiceReference registerService(QName serviceName, ExchangeHandler handler, ServiceInterface metadata) {
- return _domain.registerService(serviceName, handler, metadata);
- }
-
- @Override
- public ServiceReference registerService(QName serviceName, ExchangeHandler handler, ServiceInterface metadata, List<Policy> requires) {
- return _domain.registerService(serviceName, handler, metadata, requires);
- }
-
- @Override
- public TransformerRegistry getTransformerRegistry() {
- return _domain.getTransformerRegistry();
- }
-
- @Override
- public ValidatorRegistry getValidatorRegistry() {
- return _domain.getValidatorRegistry();
- }
-
- @Override
- public HandlerChain getHandlerChain() {
- return _domain.getHandlerChain();
- }
-}
View
122 deploy/base/src/main/java/org/switchyard/deploy/ServiceDomainManager.java
@@ -19,16 +19,10 @@
package org.switchyard.deploy;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.ServiceLoader;
-
import javax.xml.namespace.QName;
import org.switchyard.ExchangeHandler;
import org.switchyard.ServiceDomain;
-import org.switchyard.ServiceReference;
import org.switchyard.common.type.Classes;
import org.switchyard.config.model.domain.HandlerModel;
import org.switchyard.config.model.switchyard.SwitchYardModel;
@@ -70,29 +64,10 @@
*/
public static final String REGISTRY_CLASS_NAME = "registryProvider";
- private List<ServiceDomain> _activeApplicationServiceDomains = Collections.synchronizedList(new ArrayList<ServiceDomain>());
-
- /**
- * Find the named service across all service being managed by this manager instance.
- * @param serviceName The service name.
- * @param excludeDomain The domain to be excluded from the search.
- * @return The service reference instance, or null if the service was not located.
- */
- public ServiceReference findService(QName serviceName, ServiceDomain excludeDomain) {
- if (excludeDomain instanceof DomainProxy) {
- excludeDomain = ((DomainProxy) excludeDomain).getDomain();
- }
-
- for (ServiceDomain domain : _activeApplicationServiceDomains) {
- if (domain != excludeDomain) {
- ServiceReference service = domain.getService(serviceName);
- if (service != null) {
- return service;
- }
- }
- }
- return null;
- }
+ // Share the same service registry and bus across domains to give visibility
+ // to registered services across application domains
+ private ServiceRegistry _registry = new DefaultServiceRegistry();
+ private ExchangeBus _bus = new LocalExchangeBus();
/**
* Create a ServiceDomain instance.
@@ -100,7 +75,7 @@ public ServiceReference findService(QName serviceName, ServiceDomain excludeDoma
* Uses {@link #ROOT_DOMAIN} as the domain name.
* @return The ServiceDomain instance.
*/
- public static ServiceDomain createDomain() {
+ public ServiceDomain createDomain() {
return createDomain(ROOT_DOMAIN, null);
}
@@ -110,13 +85,12 @@ public static ServiceDomain createDomain() {
* @param switchyardConfig The SwitchYard configuration.
* @return The ServiceDomain instance.
*/
- public static ServiceDomain createDomain(QName domainName, SwitchYardModel switchyardConfig) {
- ServiceRegistry registry = getRegistry(DefaultServiceRegistry.class.getName());
- ExchangeBus endpointProvider = getEndpointProvider(LocalExchangeBus.class.getName());
+ public ServiceDomain createDomain(QName domainName, SwitchYardModel switchyardConfig) {
BaseTransformerRegistry transformerRegistry = new BaseTransformerRegistry();
BaseValidatorRegistry validatorRegistry = new BaseValidatorRegistry();
- DomainImpl domain = new DomainImpl(domainName, registry, endpointProvider, transformerRegistry, validatorRegistry);
+ DomainImpl domain = new DomainImpl(
+ domainName, _registry, _bus, transformerRegistry, validatorRegistry);
// add appropriate domain config
if (switchyardConfig != null) {
addHandlersToDomain(domain, switchyardConfig);
@@ -126,88 +100,10 @@ public static ServiceDomain createDomain(QName domainName, SwitchYardModel switc
}
/**
- * Add a new ServiceDomain for the specified application.
- * @param applicationName The application name.
- * @return The ServiceDomain for the application.
- */
- public ServiceDomain addApplicationServiceDomain(QName applicationName) {
- return addApplicationServiceDomain(applicationName, null);
- }
-
- /**
- * Add a new ServiceDomain for the specified application.
- * @param applicationName The application name.
- * @param switchyardConfig The SwitchYard configuration.
- * @return The ServiceDomain for the application.
- */
- public ServiceDomain addApplicationServiceDomain(QName applicationName, SwitchYardModel switchyardConfig) {
- ServiceDomain serviceDomain = createDomain(applicationName, switchyardConfig);
- _activeApplicationServiceDomains.add(serviceDomain);
- return new DomainProxy(serviceDomain, this);
- }
-
- /**
- * Remove the specified application ServiceDomain.
- * @param applicationDomain The ServiceDomain for the application.
- */
- public void removeApplicationServiceDomain(ServiceDomain applicationDomain) {
- if (applicationDomain instanceof DomainProxy) {
- _activeApplicationServiceDomains.remove(((DomainProxy) applicationDomain).getDomain());
- } else {
- _activeApplicationServiceDomains.remove(applicationDomain);
- }
- }
-
- /**
- * Returns an instance of the ServiceRegistry.
- * @param registryClass class name of the serviceregistry
- * @return ServiceRegistry
- */
- private static ServiceRegistry getRegistry(final String registryClass) {
- ServiceRegistry registry = null;
- ServiceLoader<ServiceRegistry> registryServices = ServiceLoader.load(ServiceRegistry.class);
-
- for (ServiceRegistry serviceRegistry : registryServices) {
- if (registryClass.equals(serviceRegistry.getClass().getName())) {
- registry = serviceRegistry;
- break;
- }
- }
-
- if (registry != null) {
- return registry;
- } else {
- throw new SwitchYardException("Unable to load registry provider: " + registryClass);
- }
- }
-
- /**
- * Returns an instance of the EndpointProvider.
- * @param providerClass class name of the endpointprovider implementation
- * @return EndpointProvider
- */
- private static ExchangeBus getEndpointProvider(final String providerClass) {
- ServiceLoader<ExchangeBus> providerServices = ServiceLoader.load(ExchangeBus.class);
- ExchangeBus bus = null;
-
- for (ExchangeBus provider : providerServices) {
- if (providerClass.equals(provider.getClass().getName())) {
- return provider;
- }
- }
-
- if (bus != null) {
- return bus;
- } else {
- throw new SwitchYardException("Unable to load exchange bus provider: " + providerClass);
- }
- }
-
- /**
* Looks for handler definitions in the switchyard config and attempts to
* create and add them to the domain's global handler chain.
*/
- private static void addHandlersToDomain(ServiceDomain domain, SwitchYardModel config) {
+ private void addHandlersToDomain(ServiceDomain domain, SwitchYardModel config) {
if (config.getDomain() != null && config.getDomain().getHandlers() != null) {
for (HandlerModel handlerConfig : config.getDomain().getHandlers().getHandlers()) {
Class<?> handlerClass = Classes.forName(handlerConfig.getClassName());
View
40 deploy/base/src/main/java/org/switchyard/deploy/ServiceHandler.java
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.switchyard.deploy;
+
+import org.switchyard.ExchangeHandler;
+
+/**
+ * Lifecycle-aware version of ExchangeHandler. The deployer will invoke
+ * start() and stop() in accordance with the deployment's lifecycle.
+ */
+public interface ServiceHandler extends ExchangeHandler {
+
+ /**
+ * Start processing.
+ */
+ void start();
+
+ /**
+ * Stop processing.
+ */
+ void stop();
+
+}
View
266 deploy/base/src/main/java/org/switchyard/deploy/internal/Deployment.java
@@ -32,7 +32,7 @@
import javax.xml.namespace.QName;
import org.apache.log4j.Logger;
-import org.switchyard.ExchangeHandler;
+import org.switchyard.Service;
import org.switchyard.ServiceReference;
import org.switchyard.common.type.Classes;
import org.switchyard.config.model.ModelPuller;
@@ -47,6 +47,7 @@
import org.switchyard.config.model.transform.TransformsModel;
import org.switchyard.config.model.validate.ValidatesModel;
import org.switchyard.deploy.Activator;
+import org.switchyard.deploy.ServiceHandler;
import org.switchyard.exception.SwitchYardException;
import org.switchyard.extensions.wsdl.WSDLReaderException;
import org.switchyard.extensions.wsdl.WSDLService;
@@ -77,9 +78,8 @@
private Map<String, Activator> _activators = new HashMap<String, Activator>();
private List<Activation> _services = new LinkedList<Activation>();
private List<Activation> _serviceBindings = new LinkedList<Activation>();
- private List<Activation> _references = new LinkedList<Activation>();
private List<Activation> _referenceBindings = new LinkedList<Activation>();
-
+
/**
* Create a new instance of Deployer from a configuration stream.
* @param configStream stream containing switchyard config
@@ -130,10 +130,8 @@ protected void doStart() {
// ordered startup lifecycle
try {
deployReferenceBindings();
- deployServices();
- deployReferences();
+ deployImplementations();
deployServiceBindings();
- deployAutoRegisteredTransformers();
} catch (RuntimeException e1) {
// Undo partial deployment...
_log.debug("Undeploying partially deployed artifacts of failed deployment " + getConfig().getQName());
@@ -155,8 +153,7 @@ protected void doStart() {
protected void doStop() {
_log.debug("Stopping deployment " + getName());
undeployServiceBindings();
- undeployServices();
- undeployReferences();
+ undeployImplementations();
undeployReferenceBindings();
undeployAutoRegisteredTransformers();
}
@@ -167,12 +164,9 @@ protected void doStop() {
protected void doDestroy() {
_log.debug("Destroying deployment " + getName());
- destroyDomain();
-
// Clean up our list of activations, just in case something's left
- _services.clear();
_serviceBindings.clear();
- _references.clear();
+ _services.clear();
_referenceBindings.clear();
getValidatorRegistryLoader().unregisterValidators();
@@ -230,30 +224,26 @@ private void deployReferenceBindings() {
for (CompositeReferenceModel reference : getConfig().getComposite().getReferences()) {
for (BindingModel binding : reference.getBindings()) {
QName refQName = reference.getQName();
- _log.debug("Deploying binding " + binding.getType() + " for reference " + reference.getQName() + " for deployment " + getName());
+ _log.debug("Deploying binding " + binding.getType() + " for reference "
+ + reference.getQName() + " for deployment " + getName());
Activator activator = findActivator(binding.getType());
-
if (activator == null) {
continue;
}
- ExchangeHandler handler = activator.init(refQName, reference);
-
- ServiceInterface si = getReferenceInterface(reference);
- ServiceReference serviceRef = si != null
- ? getDomain().registerService(refQName, handler, si)
- : getDomain().registerService(refQName, handler);
-
- Activation activation = new Activation(serviceRef, activator);
- activation.start();
-
+ ServiceHandler handler = activator.activateBinding(reference.getQName(), binding);
+ Activation activation = new Activation(activator, reference.getQName(), handler);
+ ServiceInterface si = getCompositeReferenceInterface(reference);
+ activation.addService(getDomain().registerService(refQName, si, handler));
_referenceBindings.add(activation);
+
+ handler.start();
}
}
}
- private ServiceInterface getReferenceInterface(CompositeReferenceModel compositeRefModel) {
+ private ServiceInterface getCompositeReferenceInterface(CompositeReferenceModel compositeRefModel) {
ServiceInterface serviceInterface = null;
if (hasCompositeReferenceInterface(compositeRefModel)) {
@@ -264,6 +254,17 @@ private ServiceInterface getReferenceInterface(CompositeReferenceModel composite
return serviceInterface;
}
+ private ServiceInterface getCompositeServiceInterface(CompositeServiceModel compositeServiceModel) {
+ ServiceInterface serviceInterface = null;
+
+ if (hasCompositeServiceInterface(compositeServiceModel)) {
+ serviceInterface = loadServiceInterface(compositeServiceModel.getInterface());
+ } else if (hasComponentServiceInterface(compositeServiceModel.getComponentService())) {
+ serviceInterface = loadServiceInterface(compositeServiceModel.getComponentService().getInterface());
+ }
+ return serviceInterface;
+ }
+
private boolean hasComponentReferenceInterface(ComponentReferenceModel componentRef) {
return componentRef != null && componentRef.getInterface() != null;
}
@@ -272,6 +273,23 @@ private boolean hasCompositeReferenceInterface(CompositeReferenceModel composite
return compositeRef != null && compositeRef.getInterface() != null;
}
+ private boolean hasComponentServiceInterface(ComponentServiceModel componentService) {
+ return componentService != null && componentService.getInterface() != null;
+ }
+
+ private boolean hasCompositeServiceInterface(CompositeServiceModel compositeService) {
+ return compositeService != null && compositeService.getInterface() != null;
+ }
+
+ private ServiceInterface getComponentReferenceInterface(ComponentReferenceModel reference) {
+ ServiceInterface referenceInterface = null;
+
+ if (reference != null && reference.getInterface() != null) {
+ referenceInterface = loadServiceInterface(reference.getInterface());
+ }
+ return referenceInterface;
+ }
+
private ServiceInterface getComponentServiceInterface(ComponentServiceModel service) {
ServiceInterface serviceInterface = null;
@@ -309,74 +327,59 @@ private ServiceInterface loadServiceInterface(InterfaceModel intfModel) {
private boolean isJavaInterface(final String type) {
return type.equals(JAVA_INTERFACE);
}
-
- private void deployServices() {
- _log.debug("Deploying services for deployment " + getName());
+
+ private void deployImplementations() {
// discover any service promotions
- Map<ComponentServiceModel,CompositeServiceModel> servicePromotions = new HashMap<ComponentServiceModel,CompositeServiceModel>();
+ Map<ComponentServiceModel,CompositeServiceModel> servicePromotions =
+ new HashMap<ComponentServiceModel,CompositeServiceModel>();
for (CompositeServiceModel compositeService : getConfig().getComposite().getServices()) {
ComponentServiceModel componentService = compositeService.getComponentService();
if (componentService != null) {
servicePromotions.put(componentService, compositeService);
}
}
- // deploy services to each implementation found in the application
+
for (ComponentModel component : getConfig().getComposite().getComponents()) {
Activator activator = findActivator(component);
if (activator == null) {
continue;
}
+
+ List<ServiceReference> references = new LinkedList<ServiceReference>();
+
+ // register a reference for each one declared in the component
+ for (ComponentReferenceModel reference : component.getReferences()) {
+ _log.debug("Registering reference " + reference.getQName()
+ + " for component " + component.getImplementation().getType() + " for deployment " + getName());
+ ServiceInterface refIntf = getComponentReferenceInterface(reference);
+ deployAutoRegisteredTransformers(refIntf);
+ references.add(getDomain().registerServiceReference(reference.getQName(), refIntf));
+ }
+
// register a service for each one declared in the component
for (ComponentServiceModel service : component.getServices()) {
_log.debug("Registering service " + service.getQName()
+ " for component " + component.getImplementation().getType() + " for deployment " + getName());
- ExchangeHandler handler = activator.init(service.getQName(), service);
+
+ ServiceHandler handler = activator.activateService(service.getQName(), component);
+ Activation activation = new Activation(activator, service.getQName(), handler);
ServiceInterface serviceIntf = getComponentServiceInterface(service);
+ deployAutoRegisteredTransformers(serviceIntf);
List<Policy> requires = getPolicyRequirements(service);
- ServiceReference serviceRef = serviceIntf != null
- ? getDomain().registerService(service.getQName(), handler, serviceIntf, requires)
- : getDomain().registerService(service.getQName(), handler);
+ activation.addService(getDomain().registerService(service.getQName(), serviceIntf, handler, requires));
+ activation.addReferences(references);
+
// register any service promotions, avoiding duplicate service names
CompositeServiceModel promotion = servicePromotions.get(service);
if (promotion != null && !promotion.getQName().equals(service.getQName())) {
- if (serviceIntf != null) {
- getDomain().registerService(promotion.getQName(), handler, serviceIntf);
- } else {
- getDomain().registerService(promotion.getQName(), handler);
- }
+ getDomain().registerService(promotion.getQName(), serviceIntf, handler);
}
- Activation activation = new Activation(serviceRef, activator);
- activation.start();
+
_services.add(activation);
- fireComponentDeployed(component);
- }
- }
-
- }
-
- private void deployReferences() {
- _log.debug("Deploying references for deployment " + getName());
- for (ComponentModel component : getConfig().getComposite().getComponents()) {
- Activator activator = findActivator(component);
-
- if (activator == null) {
- continue;
- }
-
- // register a service for each one declared in the component
- for (ComponentReferenceModel reference : component.getReferences()) {
- _log.debug("Registering reference " + reference.getQName()
- + " for component " + component.getImplementation().getType() + " for deployment " + getName());
- ServiceReference service = getDomain().getService(reference.getQName());
- if (service == null) {
- throw new SwitchYardException("Unable to activate reference, service not found: "
- + reference.getQName());
- }
- activator.init(reference.getQName(), reference);
- Activation activation = new Activation(service, activator);
- activation.start();
- _references.add(activation);
+ handler.start();
}
+
+ fireComponentDeployed(component);
}
}
@@ -386,34 +389,36 @@ private void deployServiceBindings() {
for (CompositeServiceModel service : getConfig().getComposite().getServices()) {
for (BindingModel binding : service.getBindings()) {
_log.debug("Deploying binding " + binding.getType() + " for service " + service.getQName() + " for deployment " + getName());
+
Activator activator = findActivator(binding.getType());
-
if (activator == null) {
continue;
}
- ServiceReference serviceRef = getDomain().getService(service.getQName());
- if (serviceRef == null) {
- throw new SwitchYardException("Unable to activate binding, service not found: "
- + service.getQName());
- }
- activator.init(serviceRef.getName(), service);
- Activation activation = new Activation(serviceRef, activator);
- activation.start();
+ ServiceHandler handler = activator.activateBinding(service.getQName(), binding);
+ Activation activation = new Activation(activator, service.getQName(), handler);
+ activation.addReference(
+ getDomain().registerServiceReference(service.getQName(), getCompositeServiceInterface(service)));
_serviceBindings.add(activation);
+
+ handler.start();
}
fireServiceDeployed(service);
}
}
private void undeployServiceBindings() {
- _log.debug("Undeploying reference bindings for deployment " + getName());
+ _log.debug("Undeploying service bindings for deployment " + getName());
Set<QName> undeployedServiceNames = new LinkedHashSet<QName>();
try {
for (Activation activation : _serviceBindings) {
- activation.stop();
- activation.destroy();
- undeployedServiceNames.add(activation.getService().getName());
+ activation.getHandler().stop();
+ activation.getActivator().deactivateBinding(
+ activation.getName(), activation.getHandler());
+
+ for (ServiceReference reference : activation.getReferences()) {
+ reference.unregister();
+ }
}
} finally {
_serviceBindings.clear();
@@ -424,13 +429,22 @@ private void undeployServiceBindings() {
}
}
- private void undeployServices() {
+ private void undeployImplementations() {
_log.debug("Undeploying services for deployment " + getName());
Set<QName> undeployedServiceNames = new LinkedHashSet<QName>();
try {
for (Activation activation : _services) {
- activation.stop();
- activation.destroy();
+ activation.getHandler().stop();
+ activation.getActivator().deactivateService(
+ activation.getName(), activation.getHandler());
+
+ for (Service service : activation.getServices()) {
+ service.unregister();
+ }
+
+ for (ServiceReference reference : activation.getReferences()) {
+ reference.unregister();
+ }
}
} finally {
_services.clear();
@@ -441,46 +455,23 @@ private void undeployServices() {
}
}
- private void undeployReferences() {
- _log.debug("Undeploying references for deployment " + getName());
- try {
- for (Activation activation : _references) {
- activation.stop();
- activation.destroy();
- }
- } finally {
- _references.clear();
- }
- }
-
private void undeployReferenceBindings() {
_log.debug("Undeploying reference bindings for deployment " + getName());
try {
for (Activation activation : _referenceBindings) {
- activation.stop();
- activation.destroy();
+ activation.getHandler().stop();
+ activation.getActivator().deactivateBinding(
+ activation.getName(), activation.getHandler());
+
+ for (Service service : activation.getServices()) {
+ service.unregister();
+ }
}
} finally {
_referenceBindings.clear();
}
}
- private void deployAutoRegisteredTransformers() {
- deployAutoRegisteredTransformers(_services);
- deployAutoRegisteredTransformers(_references);
- }
-
- private void deployAutoRegisteredTransformers(List<Activation> activationList) {
- for (Activation activation : activationList) {
- ServiceInterface serviceInterface = activation.getService().getInterface();
- deployAutoRegisteredTransformers(serviceInterface);
- }
- }
-
- private void destroyDomain() {
-
- }
-
private Class<?> loadClass(String className) {
return Classes.forName(className, getClass());
}
@@ -512,31 +503,50 @@ public String toString() {
}
class Activation {
- private ServiceReference _service;
private Activator _activator;
+ private QName _name;
+ private ServiceHandler _handler;
+ private List<Service> _services = new LinkedList<Service>();
+ private List<ServiceReference> _references = new LinkedList<ServiceReference>();
- Activation(ServiceReference service, Activator activator) {
- _service = service;
+ Activation(Activator activator, QName name, ServiceHandler handler) {
_activator = activator;
+ _name = name;
+ _handler = handler;
}
- void start() {
- _activator.start(_service);
+ Activator getActivator() {
+ return _activator;
}
- void stop() {
- _activator.stop(_service);
+ QName getName() {
+ return _name;
}
- void destroy() {
- _activator.destroy(_service);
+ ServiceHandler getHandler() {
+ return _handler;
}
- ServiceReference getService() {
- return _service;
+ Activation addService(Service service) {
+ _services.add(service);
+ return this;
}
- Activator getActivator() {
- return _activator;
+ Activation addReferences(List<ServiceReference> references) {
+ _references.addAll(references);
+ return this;
+ }
+
+ Activation addReference(ServiceReference reference) {
+ _references.add(reference);
+ return this;
+ }
+
+ List<ServiceReference> getReferences() {
+ return _references;
+ }
+
+ List <Service> getServices() {
+ return _services;
}
}
View
22 deploy/base/src/test/java/org/switchyard/deploy/BaseActivatorTest.java
@@ -20,14 +20,9 @@
package org.switchyard.deploy;
-import javax.xml.namespace.QName;
-
import junit.framework.Assert;
import org.junit.Test;
-import org.switchyard.ExchangeHandler;
-import org.switchyard.ServiceReference;
-import org.switchyard.config.model.Model;
public class BaseActivatorTest {
@@ -61,22 +56,5 @@ public void testMultipleActivationTypes() {
SimpleActivator(String ... types) {
super(types);
}
-
- @Override
- public void destroy(ServiceReference service) {
- }
-
- @Override
- public ExchangeHandler init(QName name, Model config) {
- return null;
- }
-
- @Override
- public void start(ServiceReference service) {
- }
-
- @Override
- public void stop(ServiceReference service) {
- }
}
View
48 deploy/base/src/test/java/org/switchyard/deploy/ServiceDomainManagerTest.java
@@ -19,18 +19,13 @@
package org.switchyard.deploy;
-import java.io.InputStream;
-
import javax.xml.namespace.QName;
import org.junit.Assert;
import org.junit.Test;
-import org.switchyard.BaseHandler;
import org.switchyard.ServiceDomain;
-import org.switchyard.common.type.Classes;
import org.switchyard.config.model.ModelPuller;
import org.switchyard.config.model.switchyard.SwitchYardModel;
-import org.switchyard.deploy.internal.Deployment;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
@@ -38,52 +33,11 @@
public class ServiceDomainManagerTest {
@Test
- public void test() {
- ServiceDomainManager domainManager = new ServiceDomainManager();
-
- ServiceDomain d1 = domainManager.addApplicationServiceDomain(new QName("D1"));
- ServiceDomain d2 = domainManager.addApplicationServiceDomain(new QName("D2"));
-
- QName s1 = new QName("S1");
- QName s2 = new QName("S2");
- QName s3 = new QName("S3");
- QName s4 = new QName("S4");
- QName unknown = new QName("unknown");
-
- d1.registerService(s1, new BaseHandler());
- d2.registerService(s2, new BaseHandler());
- d1.registerService(s3, new BaseHandler());
- d2.registerService(s4, new BaseHandler());
-
- // Test that any of the services can be found through either of the
- // ServiceDomain instances
- Assert.assertNotNull(d1.getService(s1));
- Assert.assertNotNull(d1.getService(s2));
- Assert.assertNotNull(d1.getService(s3));
- Assert.assertNotNull(d1.getService(s4));
- Assert.assertNotNull(d2.getService(s1));
- Assert.assertNotNull(d2.getService(s2));
- Assert.assertNotNull(d2.getService(s3));
- Assert.assertNotNull(d2.getService(s4));
-
- Assert.assertNull(d1.getService(unknown));
- Assert.assertNull(d2.getService(unknown));
-
- // Test that exclude works on findService...
- Assert.assertNotNull(domainManager.findService(s1, d2));
- Assert.assertNull(domainManager.findService(s1, d1));
-
- // Test that lookup fails after removing the domain ala undeploy...
- domainManager.removeApplicationServiceDomain(d1);
- Assert.assertNull(domainManager.findService(s1, d2));
- }
-
- @Test
public void testHandlerRegistration() throws Exception {
SwitchYardModel switchyard = new ModelPuller<SwitchYardModel>().pull(
"/switchyard-config-handler-01.xml", getClass());
- ServiceDomain domain = ServiceDomainManager.createDomain(
+ ServiceDomain domain = new ServiceDomainManager().createDomain(
new QName("test"), switchyard);
Assert.assertEquals(8, domain.getHandlerChain().getHandlers().size());
View
76 deploy/base/src/test/java/org/switchyard/deploy/components/MockActivator.java
@@ -21,54 +21,52 @@
import javax.xml.namespace.QName;
-import org.switchyard.BaseHandler;
-import org.switchyard.ExchangeHandler;
-import org.switchyard.ServiceReference;
-import org.switchyard.config.model.Model;
+import org.switchyard.config.model.composite.BindingModel;
+import org.switchyard.config.model.composite.ComponentModel;
import org.switchyard.deploy.BaseActivator;
+import org.switchyard.deploy.BaseServiceHandler;
+import org.switchyard.deploy.ServiceHandler;
public class MockActivator extends BaseActivator {
public static final String ACTIVATION_TYPE = "mock";
- private boolean _destroyCalled;
- private boolean _initCalled;