in modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java [117:287]
public static void main(String[] args) throws Exception {
CommandLineParser parser = new PosixParser();
Options options = getCommandLineOptions();
CommandLine cli = parser.parse(options, args);
Object node = null;
ShutdownThread shutdown = null;
EquinoxHost equinox = null;
try {
if (cli.hasOption("config")) {
System.setProperty("osgi.configuration.area", cli.getOptionValue("config"));
}
while (true) {
if (cli.hasOption("node")) {
// Create a node from a configuration URI
String configurationURI = cli.getOptionValue("node");
logger.info("SCA Node configuration: " + configurationURI);
// Create a node launcher
NodeLauncher launcher = newInstance();
equinox = launcher.equinoxHost;
node = launcher.createNode(configurationURI);
}
else if (cli.hasOption("bundles")) {
/**
* osgi.bundles
* The comma-separated list of bundles which are automatically installed and optionally started once the system is up
* and running. Each entry is of the form:
* <URL | simple bundle location>[@ [<start-level>] [":start"]]
* If the start-level (>0 integer) is omitted then the framework will use the default start level for the bundle.
* If the "start" tag is added then the bundle will be marked as started after being installed. Simple bundle locations are
* interepreted as relative to the framework's parent directory. The start-level indicates the OSGi start level at which the
* bundle should run. If this value is not set, the system computes an appropriate default.
*/
String bundles = cli.getOptionValue("bundles");
if (bundles != null) {
System.setProperty("osgi.bundles", cli.getOptionValue("bundles"));
}
// Create a node launcher
NodeLauncher launcher = newInstance();
equinox = launcher.equinoxHost;
/*
List<String> bundleFiles = cli.getArgList();
for (String bf : bundleFiles) {
File f = new File(bf);
equinox.installBundle(f.toURI().toURL(), null);
}
for (Bundle b : launcher.bundleContext.getBundles()) {
try {
if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
// Start the non-fragment bundle
b.start();
}
} catch (Exception e) {
logger.severe(NodeLauncherUtil.string(b, false) + " " + e.getMessage());
// logger.log(Level.SEVERE, e.getMessage(), e);
}
}
*/
}
else {
// Create a node from a composite URI and a contribution location
String compositeURI = cli.getOptionValue("composite");
List<String> contribs = cli.getArgList();
Contribution[] contributions = null;
if (!contribs.isEmpty()) {
contributions = new Contribution[contribs.size()];
int index = 0;
for (String contrib : contribs) {
logger.info("SCA contribution: " + contrib);
URL url = null;
try {
url = new URL(contrib);
} catch (MalformedURLException e) {
url = new File(contrib).toURI().toURL();
}
contributions[index] = new Contribution("contribution-" + index, url.toString());
index++;
}
} else {
HelpFormatter formatter = new HelpFormatter();
formatter.setSyntaxPrefix("Usage: ");
formatter.printHelp("java " + NodeLauncher.class.getName()
+ " [-config <equinoxConfiguration>]"
+ " [-c <compositeURI>]"
+ " [-b <bundles>]"
+ " [-t <ttl>]"
+ " contribution1 ... contributionN", options);
return;
}
// Create a node launcher
logger.info("SCA composite: " + compositeURI);
NodeLauncher launcher = newInstance();
equinox = launcher.equinoxHost;
node = launcher.createNode(compositeURI, contributions);
}
if (node != null) {
logger.info("Apache Tuscany SCA Node is starting...");
// Start the node
try {
node.getClass().getMethod("start").invoke(node);
} catch (Exception e) {
logger.log(Level.SEVERE, "SCA Node could not be started", e);
throw e;
}
logger.info("SCA Node is now started.");
}
// Install a shutdown hook
shutdown = new ShutdownThread(node, equinox);
Runtime.getRuntime().addShutdownHook(shutdown);
long ttl = Long.parseLong(cli.getOptionValue("ttl", "-1"));
if (ttl >= 0) {
logger.info("Waiting for " + ttl + " milliseconds ...");
Thread.sleep(ttl);
break; // Exit
}
// Wait until the "Enter" is pressed
logger.info("Press 'q' to quit, 'r' to restart.");
int k = 0;
try {
while ((k != 'q') && (k != 'r')) {
k = System.in.read();
}
} catch (IOException e) {
// Wait forever
Object lock = new Object();
synchronized (lock) {
lock.wait();
}
}
// Stop the node
if (node != null) {
Object n = node;
node = null;
stopNode(n);
}
// Quit
if (k == 'q') {
break;
}
}
} finally {
// Remove the shutdown hook
if (shutdown != null) {
Runtime.getRuntime().removeShutdownHook(shutdown);
}
// Stop the node
if (node != null) {
destroyNode(node);
}
if (equinox != null) {
equinox.stop();
}
}
}