Simplified a bit the access to EquinoxOSGiHost.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@692321 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb240413ba
commit
e72d612a60
6 changed files with 37 additions and 49 deletions
|
@ -20,8 +20,6 @@
|
|||
package org.apache.tuscany.sca.node.equinox.launcher;
|
||||
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.domainManager;
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.startOSGi;
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.stopOSGi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
@ -79,13 +77,14 @@ public class DomainManagerLauncher {
|
|||
// Create a launcher
|
||||
DomainManagerLauncher launcher = newInstance();
|
||||
|
||||
OSGiHost osgiHost = null;
|
||||
EquinoxOSGiHost equinox = null;
|
||||
Object domainManager = null;
|
||||
ShutdownThread shutdown = null;
|
||||
try {
|
||||
|
||||
// Start the OSGi host
|
||||
osgiHost = startOSGi();
|
||||
equinox = new EquinoxOSGiHost();
|
||||
equinox.start();
|
||||
|
||||
// Start the domain manager
|
||||
domainManager = launcher.createDomainManager();
|
||||
|
@ -98,7 +97,7 @@ public class DomainManagerLauncher {
|
|||
logger.info("SCA Domain Manager is now started.");
|
||||
|
||||
// Install a shutdown hook
|
||||
ShutdownThread hook = new ShutdownThread(domainManager, osgiHost);
|
||||
ShutdownThread hook = new ShutdownThread(domainManager, equinox);
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
|
||||
logger.info("Press enter to shutdown.");
|
||||
|
@ -124,8 +123,8 @@ public class DomainManagerLauncher {
|
|||
if (domainManager != null) {
|
||||
stopDomainManager(domainManager);
|
||||
}
|
||||
if (osgiHost != null) {
|
||||
stopOSGi(osgiHost);
|
||||
if (equinox != null) {
|
||||
equinox.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,12 +148,12 @@ public class DomainManagerLauncher {
|
|||
|
||||
private static class ShutdownThread extends Thread {
|
||||
private Object domainManager;
|
||||
private OSGiHost osgiHost;
|
||||
private EquinoxOSGiHost equinox;
|
||||
|
||||
public ShutdownThread(Object domainManager, OSGiHost osgiHost) {
|
||||
public ShutdownThread(Object domainManager, EquinoxOSGiHost equinox) {
|
||||
super();
|
||||
this.domainManager = domainManager;
|
||||
this.osgiHost = osgiHost;
|
||||
this.equinox = equinox;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -164,7 +163,7 @@ public class DomainManagerLauncher {
|
|||
// Ignore
|
||||
}
|
||||
try {
|
||||
stopOSGi(osgiHost);
|
||||
equinox.stop();
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ import org.eclipse.core.runtime.adaptor.LocationManager;
|
|||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* Wraps the Equinox runtime.
|
||||
*/
|
||||
public class EquinoxOSGiHost implements OSGiHost {
|
||||
public class EquinoxOSGiHost {
|
||||
private LauncherBundleActivator activator = new LauncherBundleActivator();
|
||||
private BundleContext context;
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package org.apache.tuscany.sca.node.equinox.launcher;
|
||||
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.nodeDaemon;
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.startOSGi;
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.stopOSGi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
@ -68,13 +66,14 @@ public class NodeDaemonLauncher {
|
|||
// Create a node launcher
|
||||
NodeDaemonLauncher launcher = newInstance();
|
||||
|
||||
OSGiHost osgiHost = null;
|
||||
EquinoxOSGiHost equinox = null;
|
||||
Object node = null;
|
||||
ShutdownThread shutdown = null;
|
||||
try {
|
||||
|
||||
// Start the OSGi host
|
||||
osgiHost = startOSGi();
|
||||
equinox = new EquinoxOSGiHost();
|
||||
equinox.start();
|
||||
|
||||
// Start the node
|
||||
node = launcher.createNodeDaemon();
|
||||
|
@ -87,7 +86,7 @@ public class NodeDaemonLauncher {
|
|||
logger.info("SCA Node Daemon is now started.");
|
||||
|
||||
// Install a shutdown hook
|
||||
shutdown = new ShutdownThread(node, osgiHost);
|
||||
shutdown = new ShutdownThread(node, equinox);
|
||||
Runtime.getRuntime().addShutdownHook(shutdown);
|
||||
|
||||
logger.info("Press enter to shutdown.");
|
||||
|
@ -112,8 +111,8 @@ public class NodeDaemonLauncher {
|
|||
if (node != null) {
|
||||
stopNode(node);
|
||||
}
|
||||
if (osgiHost != null) {
|
||||
stopOSGi(osgiHost);
|
||||
if (equinox != null) {
|
||||
equinox.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,12 +135,12 @@ public class NodeDaemonLauncher {
|
|||
|
||||
private static class ShutdownThread extends Thread {
|
||||
private Object node;
|
||||
private OSGiHost osgiHost;
|
||||
private EquinoxOSGiHost equinox;
|
||||
|
||||
public ShutdownThread(Object node, OSGiHost osgiHost) {
|
||||
public ShutdownThread(Object node, EquinoxOSGiHost equinox) {
|
||||
super();
|
||||
this.node = node;
|
||||
this.osgiHost = osgiHost;
|
||||
this.equinox = equinox;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -151,7 +150,7 @@ public class NodeDaemonLauncher {
|
|||
// Ignore
|
||||
}
|
||||
try {
|
||||
stopOSGi(osgiHost);
|
||||
equinox.stop();
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package org.apache.tuscany.sca.node.equinox.launcher;
|
||||
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.node;
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.startOSGi;
|
||||
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.stopOSGi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
@ -117,13 +115,14 @@ public class NodeLauncher {
|
|||
// Create a node launcher
|
||||
NodeLauncher launcher = newInstance();
|
||||
|
||||
OSGiHost osgiHost = null;
|
||||
EquinoxOSGiHost equinox = null;
|
||||
Object node = null;
|
||||
ShutdownThread shutdown = null;
|
||||
try {
|
||||
|
||||
// Start the OSGi host
|
||||
osgiHost = startOSGi();
|
||||
equinox = new EquinoxOSGiHost();
|
||||
equinox.start();
|
||||
|
||||
if (args.length ==1) {
|
||||
|
||||
|
@ -151,7 +150,7 @@ public class NodeLauncher {
|
|||
logger.info("SCA Node is now started.");
|
||||
|
||||
// Install a shutdown hook
|
||||
shutdown = new ShutdownThread(node, osgiHost);
|
||||
shutdown = new ShutdownThread(node, equinox);
|
||||
Runtime.getRuntime().addShutdownHook(shutdown);
|
||||
|
||||
logger.info("Press enter to shutdown.");
|
||||
|
@ -176,8 +175,8 @@ public class NodeLauncher {
|
|||
if (node != null) {
|
||||
stopNode(node);
|
||||
}
|
||||
if (osgiHost != null) {
|
||||
stopOSGi(osgiHost);
|
||||
if (equinox != null) {
|
||||
equinox.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,12 +199,12 @@ public class NodeLauncher {
|
|||
|
||||
private static class ShutdownThread extends Thread {
|
||||
private Object node;
|
||||
private OSGiHost osgiHost;
|
||||
private EquinoxOSGiHost equinox;
|
||||
|
||||
public ShutdownThread(Object node, OSGiHost osgiHost) {
|
||||
public ShutdownThread(Object node, EquinoxOSGiHost equinox) {
|
||||
super();
|
||||
this.node = node;
|
||||
this.osgiHost = osgiHost;
|
||||
this.equinox = equinox;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -215,7 +214,7 @@ public class NodeLauncher {
|
|||
// Ignore
|
||||
}
|
||||
try {
|
||||
stopOSGi(osgiHost);
|
||||
equinox.stop();
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
|
|
@ -172,14 +172,4 @@ final class NodeLauncherUtil {
|
|||
}
|
||||
}
|
||||
|
||||
static OSGiHost startOSGi() {
|
||||
OSGiHost host = new EquinoxOSGiHost();
|
||||
host.start();
|
||||
return host;
|
||||
}
|
||||
|
||||
static void stopOSGi(OSGiHost host) {
|
||||
host.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,18 +32,19 @@ import org.junit.Test;
|
|||
*
|
||||
*/
|
||||
public class NodeLauncherTestCase {
|
||||
private static OSGiHost host;
|
||||
private static EquinoxOSGiHost equinox;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
// System.setProperty("TUSCANY_HOME", "target/tuscany");
|
||||
host = NodeLauncherUtil.startOSGi();
|
||||
equinox = new EquinoxOSGiHost();
|
||||
equinox.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
if (host != null) {
|
||||
NodeLauncherUtil.stopOSGi(host);
|
||||
if (equinox != null) {
|
||||
equinox.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue