summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-31 02:07:02 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-31 02:07:02 +0000
commitb633d36baa7b03e087d05ed8b74a7422fbcc0404 (patch)
tree08bbbb8711f0ca7477ef696ae925661257459f9b
parent27c3c5897baa5822d3ce64459d1190696c691612 (diff)
Use ServiceFactory to create service proxies based on the interface classes from the requesting bundle
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@799489 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java65
1 files changed, 37 insertions, 28 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
index be38b46f52..7c2b90e601 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
@@ -52,6 +52,7 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -107,23 +108,15 @@ public class OSGiImplementationProvider implements ImplementationProvider {
osgiProps.put(SERVICE_IMPORTED, "true");
osgiProps.put(SERVICE_IMPORTED_CONFIGS, new String[] {REMOTE_CONFIG_SCA});
- ProxyFactory proxyService = proxyFactoryExtensionPoint.getInterfaceProxyFactory();
- if (!interfaceClass.isInterface()) {
- proxyService = proxyFactoryExtensionPoint.getClassProxyFactory();
- }
-
for (RuntimeWire wire : reference.getRuntimeWires()) {
- final Object proxy = proxyService.createProxy(interfaceClass, wire);
+ final OSGiServiceFactory serviceFactory = new OSGiServiceFactory(interfaceClass.getName(), wire);
ServiceRegistration registration =
AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
public ServiceRegistration run() {
// Register the proxy as OSGi service
BundleContext context = osgiBundle.getBundleContext();
ServiceRegistration registration =
- context.registerService(interfaceClass.getName(), proxy, osgiProps);
- // Create a DiscoveredServiceTracker to track the status of the remote service
- // RemoteServiceTracker tracker = new RemoteServiceTracker(registration);
- // context.registerService(DiscoveredServiceTracker.class.getName(), tracker, props);
+ context.registerService(interfaceClass.getName(), serviceFactory, osgiProps);
return registration;
}
});
@@ -196,23 +189,39 @@ public class OSGiImplementationProvider implements ImplementationProvider {
return implementation;
}
- // private class RemoteServiceTracker implements DiscoveredServiceTracker {
- // private ServiceRegistration referenceRegistration;
- //
- // private RemoteServiceTracker(ServiceRegistration referenceRegistration) {
- // super();
- // this.referenceRegistration = referenceRegistration;
- // }
- //
- // public void serviceChanged(DiscoveredServiceNotification notification) {
- // ServiceEndpointDescription description = notification.getServiceEndpointDescription();
- // switch(notification.getType()) {
- // case UNAVAILABLE:
- // case AVAILABLE:
- // case MODIFIED:
- // case MODIFIED_ENDMATCH:
- // }
- // }
- // }
+ public class OSGiServiceFactory implements ServiceFactory {
+ private RuntimeWire wire;
+ private String interfaceName;
+
+ /**
+ * @param interfaceName
+ * @param wire
+ */
+ public OSGiServiceFactory(String interfaceName, RuntimeWire wire) {
+ super();
+ this.interfaceName = interfaceName;
+ this.wire = wire;
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ Class<?> interfaceClass = null;
+ try {
+ interfaceClass = bundle.loadClass(interfaceName);
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+ ProxyFactory proxyService = proxyFactoryExtensionPoint.getInterfaceProxyFactory();
+ if (!interfaceClass.isInterface()) {
+ proxyService = proxyFactoryExtensionPoint.getClassProxyFactory();
+ }
+ Object proxy = proxyService.createProxy(interfaceClass, wire);
+ return proxy;
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+ // Do we need to release the proxy?
+ }
+
+ }
}