summaryrefslogtreecommitdiffstats
path: root/sandbox/event/modules/binding-event
diff options
context:
space:
mode:
authorrsivaram <rsivaram@13f79535-47bb-0310-9956-ffa450edef68>2008-11-12 13:16:06 +0000
committerrsivaram <rsivaram@13f79535-47bb-0310-9956-ffa450edef68>2008-11-12 13:16:06 +0000
commitaf0cfc49958afa2ef6c44384cb5d5d8ca4c516da (patch)
treed6d049845ae04a9f21d67513bde2ee5edf4cf363 /sandbox/event/modules/binding-event
parent29f3940a57d823817db96b41ccd1e9c7a88c4adc (diff)
Event prototype: event binding with JMS-based default binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@713362 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/event/modules/binding-event')
-rw-r--r--sandbox/event/modules/binding-event/pom.xml21
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/DefaultEventBindingFactory.java32
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingFactoryImpl.java24
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingImpl.java14
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInterceptor.java158
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInvoker.java42
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventReferenceBindingProvider.java57
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java129
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceInterface.java33
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/xml/EventBindingProcessor.java134
-rw-r--r--sandbox/event/modules/binding-event/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
11 files changed, 620 insertions, 43 deletions
diff --git a/sandbox/event/modules/binding-event/pom.xml b/sandbox/event/modules/binding-event/pom.xml
index ed9228ff7e..7e74d69039 100644
--- a/sandbox/event/modules/binding-event/pom.xml
+++ b/sandbox/event/modules/binding-event/pom.xml
@@ -28,7 +28,7 @@
</parent>
<artifactId>tuscany-binding-event</artifactId>
- <name>Apache Tuscany SCA Default Binding Model</name>
+ <name>Apache Tuscany SCA Event Binding</name>
<dependencies>
@@ -61,6 +61,25 @@
<artifactId>tuscany-contribution-impl</artifactId>
<version>1.4-EVENT-SNAPSHOT</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-wsdl</artifactId>
+ <version>1.4-EVENT-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-axiom</artifactId>
+ <version>1.4-EVENT-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-ws-wsdlgen</artifactId>
+ <version>1.4-EVENT-SNAPSHOT</version>
+ </dependency>
+
<dependency>
<groupId>org.easymock</groupId>
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/DefaultEventBindingFactory.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/DefaultEventBindingFactory.java
new file mode 100644
index 0000000000..7f666ed6a9
--- /dev/null
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/DefaultEventBindingFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.event;
+
+import org.apache.tuscany.sca.assembly.Binding;
+
+/**
+ * Factory to create base binding for producers and consumers
+ */
+public interface DefaultEventBindingFactory {
+
+
+ public Binding createDefaultEventBinding();
+
+}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingFactoryImpl.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingFactoryImpl.java
index 1b6300aab4..3451e13747 100644
--- a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingFactoryImpl.java
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingFactoryImpl.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.binding.event.impl;
+import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.EventBinding;
import org.apache.tuscany.sca.assembly.EventBindingFactory;
@@ -29,12 +30,33 @@ import org.apache.tuscany.sca.assembly.EventBindingFactory;
*/
public class EventBindingFactoryImpl implements EventBindingFactory {
+ /*
+ * Constructor
+ */
public EventBindingFactoryImpl (){
-
}
+ /*
+ * (non-Javadoc)
+ * @see org.apache.tuscany.sca.assembly.EventBindingFactory#createEventBinding()
+ */
public EventBinding createEventBinding() {
return new EventBindingImpl();
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.tuscany.sca.assembly.EventBindingFactory#createEventBinding(org.apache.tuscany.sca.assembly.Binding)
+ */
+ public EventBinding createEventBinding(Binding baseBinding) {
+ if (baseBinding instanceof EventBinding)
+ return (EventBinding)baseBinding;
+
+ EventBindingImpl eventBinding = new EventBindingImpl();
+ eventBinding.setBaseBinding(baseBinding);
+ return eventBinding;
+ }
+
+
}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingImpl.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingImpl.java
index b07651960f..cfe2a58247 100644
--- a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingImpl.java
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingImpl.java
@@ -26,8 +26,8 @@ import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.EventBinding;
import org.apache.tuscany.sca.assembly.Extensible;
-import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
+import org.apache.tuscany.sca.binding.event.DefaultEventBindingFactory;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.IntentAttachPointType;
import org.apache.tuscany.sca.policy.PolicySet;
@@ -38,7 +38,7 @@ import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
*
* @version $$
*/
-public class EventBindingImpl implements EventBinding, Extensible, PolicySetAttachPoint, OptimizableBinding, AutomaticBinding {
+public class EventBindingImpl implements EventBinding, Extensible, PolicySetAttachPoint, AutomaticBinding {
private String name;
private String uri;
private Binding baseBinding;
@@ -59,7 +59,7 @@ public class EventBindingImpl implements EventBinding, Extensible, PolicySetAtta
}
/**
- * Constructs a new SCA binding.
+ * Constructs a new Event binding.
*/
protected EventBindingImpl() {
}
@@ -240,4 +240,12 @@ public class EventBindingImpl implements EventBinding, Extensible, PolicySetAtta
public boolean getIsAutomatic(){
return this.isAutomatic;
}
+
+ public Binding createDefaultBaseBinding(DefaultEventBindingFactory factory) {
+ if (baseBinding == null)
+ baseBinding = factory.createDefaultEventBinding();
+ return baseBinding;
+
+ }
+
}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInterceptor.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInterceptor.java
new file mode 100644
index 0000000000..cf15e54c33
--- /dev/null
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInterceptor.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.event.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.annotations.EventType;
+
+/**
+ * Policy interceptor for events
+ *
+ * @version $$
+ */
+public class EventBindingInterceptor implements Interceptor {
+ private Invoker next;
+ @SuppressWarnings("unused")
+ private Operation operation;
+ private RuntimeComponentService consumerService;
+ private Binding binding;
+ private InterfaceContractMapper interfaceContractMapper;
+
+ public EventBindingInterceptor(RuntimeComponentService consumerService,
+ Binding binding,
+ Operation operation,
+ InterfaceContractMapper interfaceContractMapper) {
+ super();
+ this.consumerService = consumerService;
+ this.operation = operation;
+ this.binding = binding;
+ this.interfaceContractMapper = interfaceContractMapper;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+
+ Object arg = msg.getBody();
+ if (arg instanceof Object[]) {
+ arg = ((Object [])arg)[0];
+ }
+
+ Operation consumerOperation = findOperation(consumerService.getInterfaceContract().getInterface().getOperations(), arg);
+
+ InvocationChain chain = getInvocationChain(consumerService.getRuntimeWire(binding), consumerOperation);
+ Invoker invoker = chain.getHeadInvoker();
+ while (invoker instanceof Interceptor && ((Interceptor)invoker).getNext() != null) {
+ invoker = ((Interceptor)invoker).getNext();
+ }
+ msg = invoker.invoke(msg);
+ } catch (Exception e) {
+ e.printStackTrace();
+ msg.setBody(e);
+ }
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ private String getEventType(Class<?> clazz) {
+ EventType eventTypeAnnotation = clazz.getAnnotation(EventType.class);
+ if (eventTypeAnnotation != null)
+ return eventTypeAnnotation.name();
+ if (clazz.getSuperclass() != null && clazz.getSuperclass() != Object.class) {
+ String eventType = getEventType(clazz.getSuperclass());
+ if (eventType != null)
+ return eventType;
+ }
+ for (Class<?> interfaze : clazz.getInterfaces()) {
+ String eventType = getEventType(interfaze);
+ if (eventType != null)
+ return eventType;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Operation findOperation(List<Operation> operations, Object arg) {
+ if (arg == null) {
+ return operations.get(0);
+ }
+ else {
+ String eventType = getEventType(arg.getClass());
+
+ Operation firstMatching = null;
+ for (Operation op : operations) {
+ String[] eventTypes = op.getEventTypes();
+ if (eventTypes == null || eventTypes.length == 0) {
+
+ if (op.getInputType().getLogical().get(0).getPhysical().isAssignableFrom(arg.getClass())) {
+
+ // If no event type is specified, return the first method which
+ // (1) has assignable parameters
+ // (2) has no explicit event types specified
+ if (eventType == null) {
+
+ return op;
+ }
+ else if (firstMatching == null) {
+ // Remember first matching method without event types and
+ // return this operation if no operation has explicitly specified
+ // this event type.
+ firstMatching = op;
+ }
+ }
+ } else {
+ for (String type : eventTypes) {
+ if (type.equals(eventType)) {
+ return op;
+ }
+ }
+ }
+
+ }
+ return firstMatching;
+ }
+ }
+
+ public InvocationChain getInvocationChain(RuntimeWire wire, Operation operation) {
+ for (InvocationChain chain : wire.getInvocationChains()) {
+ Operation op = chain.getTargetOperation();
+ if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) {
+ return chain;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInvoker.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInvoker.java
index 481f3b2b0a..2c36acbf94 100644
--- a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInvoker.java
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventBindingInvoker.java
@@ -19,54 +19,50 @@
package org.apache.tuscany.sca.binding.event.impl;
-import org.apache.tuscany.sca.invocation.Interceptor;
-import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
/**
- * TODO: Implement event binding invoker
+ * Event binding invoker
* @version $$
*/
-public class EventBindingInvoker implements Interceptor, DataExchangeSemantics {
- private InvocationChain chain;
+public class EventBindingInvoker implements Invoker, DataExchangeSemantics {
+
+ private Invoker baseInvoker;
/**
- * Construct a EventBindingInvoker that delegates to the service invocaiton chain
+ * Construct a EventBindingInvoker that delegates to the service invocation chain
* @param chain
*/
- public EventBindingInvoker(InvocationChain chain) {
+ public EventBindingInvoker(ReferenceBindingProvider baseBindingProvider, Operation operation) {
super();
- this.chain = chain;
- }
-
- /**
- * @see org.apache.tuscany.sca.invocation.Interceptor#getNext()
- */
- public Invoker getNext() {
- return chain.getHeadInvoker();
+
+ // TODO: Should we match producer event types with the event types of the operation?
+ baseInvoker = baseBindingProvider.createInvoker(operation);
}
- /**
- * @see org.apache.tuscany.sca.invocation.Interceptor#setNext(org.apache.tuscany.sca.invocation.Invoker)
- */
- public void setNext(Invoker next) {
- // NOOP
- }
/**
* @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message)
*/
public Message invoke(Message msg) {
- return getNext().invoke(msg);
+ if (baseInvoker != null) {
+ return baseInvoker.invoke(msg);
+ }
+ else {
+ msg.setBody(null);
+ return msg;
+ }
}
/**
* @see org.apache.tuscany.sca.invocation.DataExchangeSemantics#allowsPassByReference()
*/
public boolean allowsPassByReference() {
- return chain.allowsPassByReference();
+ return true;
}
}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventReferenceBindingProvider.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventReferenceBindingProvider.java
index bb09fb5b77..6faa1fbf6f 100644
--- a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventReferenceBindingProvider.java
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventReferenceBindingProvider.java
@@ -21,10 +21,17 @@ package org.apache.tuscany.sca.binding.event.impl;
import java.util.logging.Logger;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.binding.event.DefaultEventBindingFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
@@ -36,18 +43,20 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
*/
public class EventReferenceBindingProvider implements ReferenceBindingProvider {
- @SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(EventReferenceBindingProvider.class.getName());
@SuppressWarnings("unused")
private RuntimeComponent component;
@SuppressWarnings("unused")
private EventBindingImpl binding;
+ @SuppressWarnings("unused")
private RuntimeComponentReference reference;
private boolean started = false;
private ReferenceBindingProvider baseBindingProvider;
+
+ @SuppressWarnings("unchecked")
public EventReferenceBindingProvider(ExtensionPointRegistry extensionPoints,
RuntimeComponent component,
RuntimeComponentReference reference,
@@ -55,17 +64,47 @@ public class EventReferenceBindingProvider implements ReferenceBindingProvider {
this.component = component;
this.reference = reference;
this.binding = binding;
+
+
+ ProviderFactoryExtensionPoint providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+
+ Binding baseBinding = binding.getBaseBinding();
+ if (baseBinding == null) {
+
+ DefaultEventBindingFactory defaultEventBindingFactory =
+ (DefaultEventBindingFactory)modelFactories.getFactory(DefaultEventBindingFactory.class);
+
+ if (defaultEventBindingFactory == null) {
+ logger.severe("Default binding for Event binding not available");
+ }
+ baseBinding = binding.createDefaultBaseBinding(defaultEventBindingFactory);
+ }
- // TODO: Set baseBindingProvider
+ BindingProviderFactory providerFactory =
+ (BindingProviderFactory)providerFactories.getProviderFactory(baseBinding.getClass());
+ if (providerFactory != null) {
+ baseBindingProvider =
+ providerFactory.createReferenceBindingProvider((RuntimeComponent)component,
+ (RuntimeComponentReference)reference,
+ baseBinding);
+ for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createReferencePolicyProvider(component, reference, baseBinding);
+ if (policyProvider != null) {
+ reference.addPolicyProvider(baseBinding, policyProvider);
+ }
+ }
+ }
+ if (baseBindingProvider == null) {
+ throw new IllegalStateException("Provider factory not found for class: " + baseBinding.getClass().getName());
+ }
+
}
public InterfaceContract getBindingInterfaceContract() {
- if (reference.getReference() != null) {
- return reference.getReference().getInterfaceContract();
- } else {
- return reference.getInterfaceContract();
- }
+ return baseBindingProvider.getBindingInterfaceContract();
}
public boolean supportsOneWayInvocation() {
@@ -74,13 +113,14 @@ public class EventReferenceBindingProvider implements ReferenceBindingProvider {
public Invoker createInvoker(Operation operation) {
- return baseBindingProvider.createInvoker(operation);
+ return new EventBindingInvoker(baseBindingProvider, operation);
}
public void start() {
if (started) {
return;
} else {
+ baseBindingProvider.start();
started = true;
}
}
@@ -89,6 +129,7 @@ public class EventReferenceBindingProvider implements ReferenceBindingProvider {
if (!started) {
return;
} else {
+ baseBindingProvider.stop();
started = false;
}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java
index 593795aae0..5f90089d73 100644
--- a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java
@@ -20,11 +20,30 @@
package org.apache.tuscany.sca.binding.event.impl;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.EventBinding;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.binding.event.DefaultEventBindingFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.AsyncServiceBindingProvider;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
import org.apache.tuscany.sca.provider.ServiceBindingProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
/**
* The event service binding provider
@@ -32,22 +51,92 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
* @version $$
*/
public class EventServiceBindingProvider implements ServiceBindingProvider {
-
+
+ private static final Logger logger = Logger.getLogger(EventReferenceBindingProvider.class.getName());
+
private RuntimeComponentService service;
+ private RuntimeComponentService eventService;
+ private ServiceBindingProvider baseBindingProvider;
+
+ private InterfaceContract eventInterfaceContract;
+
+ private EventBinding eventBinding;
+ private InterfaceContractMapper interfaceContractMapper;
+
+
+
+ @SuppressWarnings("unchecked")
public EventServiceBindingProvider(ExtensionPointRegistry extensionPoints,
RuntimeComponent component,
RuntimeComponentService service,
EventBindingImpl binding) {
- this.service = service;
+
+
+ eventBinding = binding;
+
+
+ ProviderFactoryExtensionPoint providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ Binding baseBinding = binding.getBaseBinding();
+ if (baseBinding == null) {
+
+ DefaultEventBindingFactory defaultEventBindingFactory =
+ (DefaultEventBindingFactory)modelFactories.getFactory(DefaultEventBindingFactory.class);
+
+ if (defaultEventBindingFactory == null) {
+ logger.severe("Default binding for Event binding not available");
+ }
+ baseBinding = binding.createDefaultBaseBinding(defaultEventBindingFactory);
+ }
+
+ BindingProviderFactory providerFactory =
+ (BindingProviderFactory)providerFactories.getProviderFactory(baseBinding.getClass());
+
+ JavaInterfaceFactory javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ if (providerFactory != null) {
+ try {
+ this.service = service;
+
+ eventService = (RuntimeComponentService)service.clone();
+
+ JavaInterface iface = javaInterfaceFactory.createJavaInterface(EventServiceInterface.class);
+
+ eventInterfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ eventInterfaceContract.setInterface(iface);
+ eventService.setInterfaceContract(eventInterfaceContract);
+
+ if (service.getService() != null) {
+ eventService.setService((Service)service.getService().clone());
+ eventService.getService().setInterfaceContract(eventInterfaceContract);
+ }
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ baseBindingProvider =
+ providerFactory.createServiceBindingProvider((RuntimeComponent)component,
+ (RuntimeComponentService)eventService,
+ baseBinding);
+ if (baseBindingProvider instanceof AsyncServiceBindingProvider) {
+ ((AsyncServiceBindingProvider)baseBindingProvider).setTargetBinding(binding);
+ }
+
+ }
+
+ if (baseBindingProvider == null) {
+ throw new IllegalStateException("Provider factory not found for class: " + baseBinding.getClass().getName());
+ }
}
public InterfaceContract getBindingInterfaceContract() {
- if (service.getService() != null) {
- return service.getService().getInterfaceContract();
- } else {
- return service.getInterfaceContract();
- }
+ return service.getInterfaceContract();
}
public boolean supportsOneWayInvocation() {
@@ -55,9 +144,35 @@ public class EventServiceBindingProvider implements ServiceBindingProvider {
}
public void start() {
+ try {
+ for (RuntimeWire wire : service.getRuntimeWires()) {
+ RuntimeWire clonedWire = (RuntimeWire)wire.clone();
+ clonedWire.rebuild();
+ clonedWire.getSource().setInterfaceContract(eventInterfaceContract);
+ clonedWire.getTarget().setInterfaceContract(eventInterfaceContract);
+ if (clonedWire.getTarget().getContract() == service)
+ clonedWire.getTarget().setContract(eventService);
+ eventService.getRuntimeWires().add(clonedWire);
+ }
+
+ List<InvocationChain> chains = eventService.getRuntimeWire(eventBinding).getInvocationChains();
+ for (InvocationChain chain : chains) {
+ Interceptor interceptor = new EventBindingInterceptor(service,
+ eventBinding,
+ chain.getSourceOperation(),
+ interfaceContractMapper);
+ chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, interceptor);
+ }
+
+ baseBindingProvider.start();
+ } catch (CloneNotSupportedException e) {
+ // Should never happen
+ }
}
public void stop() {
+ baseBindingProvider.stop();
}
+
}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceInterface.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceInterface.java
new file mode 100644
index 0000000000..1111bccfe1
--- /dev/null
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceInterface.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.event.impl;
+
+import org.osoa.sca.annotations.Remotable;
+
+
+/**
+ * Interface for event services
+ *
+ * @version $$
+ */
+@Remotable
+public interface EventServiceInterface {
+
+ void onEvent(Object event);
+}
diff --git a/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/xml/EventBindingProcessor.java b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/xml/EventBindingProcessor.java
new file mode 100644
index 0000000000..000be21d26
--- /dev/null
+++ b/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/xml/EventBindingProcessor.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.event.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.EventBinding;
+import org.apache.tuscany.sca.assembly.EventBindingFactory;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * A processor to read the XML that describes the event binding.
+ *
+ * @version $$
+ */
+
+public class EventBindingProcessor implements StAXArtifactProcessor<EventBinding>, Constants{
+
+ private PolicyFactory policyFactory;
+ private EventBindingFactory eventBindingFactory;
+ private PolicyAttachPointProcessor policyProcessor;
+ private IntentAttachPointTypeFactory intentAttachPointTypeFactory;
+ @SuppressWarnings("unused")
+ private Monitor monitor;
+
+ protected static final String BINDING_EVENT = "binding.event";
+ protected static final QName BINDING_EVENT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, BINDING_EVENT);
+
+ public EventBindingProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.eventBindingFactory = modelFactories.getFactory(EventBindingFactory.class);
+ policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ this.monitor = monitor;
+ }
+
+ public QName getArtifactType() {
+ return BINDING_EVENT_QNAME;
+ }
+
+ public Class<EventBinding> getModelType() {
+ return EventBinding.class;
+ }
+
+ public EventBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ EventBinding eventBinding = eventBindingFactory.createEventBinding();
+ IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
+ bindingType.setName(getArtifactType());
+ bindingType.setUnresolved(true);
+ ((PolicySetAttachPoint)eventBinding).setType(bindingType);
+
+ // Read policies
+ policyProcessor.readPolicies(eventBinding, reader);
+
+ // Read binding name
+ String name = reader.getAttributeValue(null, NAME);
+ if (name != null) {
+ eventBinding.setName(name);
+ }
+
+ // Read binding URI
+ String uri = reader.getAttributeValue(null, URI);
+ if (uri != null) {
+ eventBinding.setURI(uri);
+ }
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && BINDING_EVENT_QNAME.equals(reader.getName())) {
+ break;
+ }
+ }
+ return eventBinding;
+ }
+
+ public void resolve(EventBinding model, ModelResolver resolver) throws ContributionResolveException {
+ policyProcessor.resolvePolicies(model, resolver);
+ }
+
+ public void write(EventBinding eventBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <binding.event>
+ policyProcessor.writePolicyPrefixes(eventBinding, writer);
+ writer.writeStartElement(Constants.SCA10_TUSCANY_NS, BINDING_EVENT);
+ policyProcessor.writePolicyAttributes(eventBinding, writer);
+
+ // Write binding name
+ if (eventBinding.getName() != null) {
+ writer.writeAttribute(NAME, eventBinding.getName());
+ }
+
+ // Write binding URI
+ if (eventBinding.getURI() != null) {
+ writer.writeAttribute(URI, eventBinding.getURI());
+ }
+
+ writer.writeEndElement();
+ }
+
+}
diff --git a/sandbox/event/modules/binding-event/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/event/modules/binding-event/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..a2ac94ebc2
--- /dev/null
+++ b/sandbox/event/modules/binding-event/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.binding.event.xml.EventBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.event,model=org.apache.tuscany.sca.binding.event.impl.EventBindingImpl