From 0269f4bdcdd988aa67b911a3b1f3b3874da18304 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 21 Jan 2010 21:21:33 +0000 Subject: Exclude service listeners from system bundles Use the Deployer to load client contribution for dynamic nodes git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@901857 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/EndpointIntrospector.java | 22 ++++++++++++++++++---- .../impl/TopologyManagerImpl.java | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) (limited to 'sca-java-2.x/trunk/modules/node-impl-osgi') diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java index c22506d560..d27a8708ee 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java @@ -26,6 +26,7 @@ import static org.osgi.framework.Constants.OBJECTCLASS; import static org.osgi.framework.Constants.SERVICE_ID; import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -59,6 +60,8 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory; import org.apache.tuscany.sca.implementation.osgi.OSGiProperty; @@ -94,7 +97,7 @@ public class EndpointIntrospector { private ModelResolverExtensionPoint modelResolvers; // private StAXArtifactProcessor compositeProcessor; private JavaInterfaceFactory javaInterfaceFactory; - // private Deployer deployer; + private Deployer deployer; private ServiceTracker discoveryTracker; /** @@ -134,7 +137,7 @@ public class EndpointIntrospector { this.policyFactory = factories.getFactory(PolicyFactory.class); this.implementationFactory = factories.getFactory(OSGiImplementationFactory.class); this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); - // this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class); + this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class); } private Intent getIntent(String intent) { @@ -263,6 +266,17 @@ public class EndpointIntrospector { Contribution contribution = generateContribution(bundle, sid, remoteInterfaces, bindings, allIntents, osgiProps); return contribution; } + + public Contribution loadContribution(Bundle bundle, Composite composite) { + try { + URL root = bundle.getEntry("/"); + Contribution contribution = deployer.loadContribution(root.toURI(), root, deployer.createMonitor()); + deployer.attachDeploymentComposite(contribution, composite, false); + return contribution; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } /** * Generate a contribution that contains the composite for the exported service @@ -326,7 +340,7 @@ public class EndpointIntrospector { } // FIXME: Should we scan the owning bundle to create the SCA contribution? - Contribution contribution = createContribution(bundle, id, composite); + Contribution contribution = loadContribution(bundle, composite); return contribution; } @@ -419,7 +433,7 @@ public class EndpointIntrospector { componentReference.getBindings().addAll(bindings); } - Contribution contribution = createContribution(bundle, id, composite); + Contribution contribution = loadContribution(bundle, composite); return contribution; } diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/TopologyManagerImpl.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/TopologyManagerImpl.java index 31f4f4c0b3..33faa77c84 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/TopologyManagerImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/TopologyManagerImpl.java @@ -195,7 +195,11 @@ public class TopologyManagerImpl implements ListenerHook, RemoteServiceAdminList Collection listenerInfos = (Collection)listeners; boolean changed = false; for (ListenerInfo l : listenerInfos) { - if (!l.isRemoved() && l.getBundleContext() != context) { + if (l.getBundleContext().getBundle().getBundleId() == 0L || l.getBundleContext() == context) { + // Ignore system and tuscany bundle + continue; + } + if (!l.isRemoved()) { String key = l.getFilter(); if (key == null) { // key = ""; @@ -357,6 +361,19 @@ public class TopologyManagerImpl implements ListenerHook, RemoteServiceAdminList // Get a listener ListenerInfo listener = listeners.iterator().next(); Bundle bundle = listener.getBundleContext().getBundle(); + if (bundle.getBundleId() == 0L) { + // Skip system bundles + continue; + } + try { + Filter filter = listener.getBundleContext().createFilter(matchedFilter); + if (!filter.match(new Hashtable(endpoint.getProperties()))) { + continue; + } + } catch (InvalidSyntaxException ex) { + logger.log(Level.SEVERE, ex.getMessage(), ex); + continue; + } Map props = new HashMap(endpoint.getProperties()); props.put(Bundle.class.getName(), bundle); -- cgit v1.2.3