diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-29 00:45:49 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-29 00:45:49 +0000 |
commit | fe31f16450d9d52c05bd091ca4922a601167186c (patch) | |
tree | 800250af7e4908cb2c1f3a6ef3c811624813cee5 | |
parent | c8633f6406d0ec0340c5fe5afa1a70bee97efc42 (diff) |
Add more checks for the stop() method
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@830811 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 64 insertions, 47 deletions
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java index 8079ca430a..36feb6526a 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeActivator.java @@ -21,6 +21,9 @@ package org.apache.tuscany.sca.node.osgi.impl; import static org.apache.tuscany.sca.node.osgi.impl.NodeManager.isSCABundle; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.RemoteServiceAdminImpl; import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.TopologyManagerImpl; import org.apache.tuscany.sca.osgi.service.discovery.impl.DiscoveryActivator; @@ -34,10 +37,11 @@ import org.osgi.framework.SynchronousBundleListener; * Bundle activator to receive the BundleContext */ public class NodeActivator implements BundleActivator, SynchronousBundleListener { + private final static Logger logger = Logger.getLogger(NodeActivator.class.getName()); private static BundleContext bundleContext; private boolean inited; private NodeManager manager; - + private DiscoveryActivator discoveryActivator = new DiscoveryActivator(); private RemoteServiceAdminImpl remoteAdmin; private TopologyManagerImpl controller; @@ -55,50 +59,57 @@ public class NodeActivator implements BundleActivator, SynchronousBundleListener } public void start(BundleContext context) throws Exception { - bundleContext = context; - - // FIXME: We should try to avoid aggressive initialization - init(); - - remoteAdmin = new RemoteServiceAdminImpl(context); - remoteAdmin.start(); - - discoveryActivator.start(context); - - controller = new TopologyManagerImpl(context); - controller.start(); - - boolean found = false; - for (Bundle b : context.getBundles()) { - if (isSCABundle(b)) { - found = true; - break; - } - } + try { + bundleContext = context; - if (found) { + // FIXME: We should try to avoid aggressive initialization init(); - } else { - context.addBundleListener(this); + + remoteAdmin = new RemoteServiceAdminImpl(context); + remoteAdmin.start(); + + discoveryActivator.start(context); + + controller = new TopologyManagerImpl(context); + controller.start(); + + boolean found = false; + for (Bundle b : context.getBundles()) { + if (isSCABundle(b)) { + found = true; + break; + } + } + + if (found) { + init(); + } else { + context.addBundleListener(this); + } + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + throw e; } } public void stop(BundleContext context) throws Exception { - context.removeBundleListener(this); - controller.stop(); - controller = null; - - discoveryActivator.stop(context); - discoveryActivator = null; - - remoteAdmin.stop(); - remoteAdmin = null; - - manager.stop(); - bundleContext.removeBundleListener(manager); - manager = null; - bundleContext = null; - inited = false; + if (inited) { + context.removeBundleListener(this); + controller.stop(); + controller = null; + + discoveryActivator.stop(context); + discoveryActivator = null; + + remoteAdmin.stop(); + remoteAdmin = null; + + manager.stop(); + bundleContext.removeBundleListener(manager); + manager = null; + bundleContext = null; + inited = false; + } } public static BundleContext getBundleContext() { diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java index e8bf5def45..1181f49300 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/OSGiNodeFactoryImpl.java @@ -96,12 +96,15 @@ public class OSGiNodeFactoryImpl extends NodeFactoryImpl { public synchronized void init() { if (!inited) { - super.init(); - // Register the ExtensionPointRegistry as an OSGi service Dictionary<Object, Object> props = new Hashtable<Object, Object>(); + registry = createExtensionPointRegistry(); + registry.start(); registration = bundleContext.registerService(ExtensionPointRegistry.class.getName(), registry, props); + + // Call super.init after the extension point registry is registered + super.init(); } } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java index b87dfc08fa..a043e33c32 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java @@ -73,12 +73,14 @@ public class AbstractOSGiServiceHandler implements LifeCycleListener { } public void stop() { - discoveryTracker.close(); - discoveryTracker = null; - introspector = null; - nodeFactory = null; - registry = null; - context = null; + if (nodeFactory != null) { + discoveryTracker.close(); + discoveryTracker = null; + introspector = null; + nodeFactory = null; + registry = null; + context = null; + } } public void setDomainRegistry(String domainRegistry) { diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java index 5d5b72183f..59a21ade06 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java @@ -48,6 +48,7 @@ public class OSGiServiceImporter extends AbstractOSGiServiceHandler { } public void start() { + // Defer init() to importService() } public ImportRegistration importService(Bundle bundle, EndpointDescription endpointDescription) { |