summaryrefslogtreecommitdiffstats
path: root/sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java')
-rw-r--r--sandbox/event/modules/binding-event/src/main/java/org/apache/tuscany/sca/binding/event/impl/EventServiceBindingProvider.java129
1 files changed, 122 insertions, 7 deletions
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();
}
+
}