]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/osgi/AdminThread.java
Use locator path as OSGi installation string
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / osgi / AdminThread.java
1 package org.argeo.init.osgi;
2
3 import java.io.File;
4
5 import org.osgi.framework.BundleContext;
6 import org.osgi.framework.launch.Framework;
7
8 /** Monitors the runtime and can shut it down. */
9 @Deprecated
10 public class AdminThread extends Thread {
11 public final static String PROP_ARGEO_OSGI_SHUTDOWN_FILE = "argeo.osgi.shutdownFile";
12 private File shutdownFile;
13 private final BundleContext bundleContext;
14
15 public AdminThread(BundleContext bundleContext) {
16 super("OSGi Boot Admin");
17 this.bundleContext = bundleContext;
18 if (System.getProperty(PROP_ARGEO_OSGI_SHUTDOWN_FILE) != null) {
19 shutdownFile = new File(
20 System.getProperty(PROP_ARGEO_OSGI_SHUTDOWN_FILE));
21 if (!shutdownFile.exists()) {
22 shutdownFile = null;
23 OsgiBootUtils.warn("Shutdown file " + shutdownFile
24 + " not found, feature deactivated");
25 }
26 }
27 }
28
29 public void run() {
30 if (shutdownFile != null) {
31 // wait for file to be removed
32 while (shutdownFile.exists()) {
33 try {
34 Thread.sleep(1000);
35 } catch (InterruptedException e) {
36 e.printStackTrace();
37 }
38 }
39
40 Framework framework = (Framework) bundleContext.getBundle(0);
41 try {
42 // shutdown framework
43 framework.stop();
44 // wait 10 mins for shutdown
45 framework.waitForStop(10 * 60 * 1000);
46 // close VM
47 System.exit(0);
48 } catch (Exception e) {
49 e.printStackTrace();
50 System.exit(1);
51 }
52 }
53 }
54 }