import org.argeo.init.osgi.OsgiRuntimeContext;
+/** Configure and launch an Argeo service. */
public class Service implements Runnable, AutoCloseable {
private final static Logger log = System.getLogger(Service.class.getName());
// shutdown on exit
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
- if (Service.runtimeContext != null)
+ if (Service.runtimeContext != null) {
Service.runtimeContext.close();
+ //Service.runtimeContext.waitForStop(0);
+ }
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}, "Runtime shutdown"));
Map<String, String> config = new HashMap<>();
+ config.put("osgi.framework.useSystemProperties", "true");
+// for (Object key : System.getProperties().keySet()) {
+// config.put(key.toString(), System.getProperty(key.toString()));
+// log.log(Logger.Level.DEBUG, key + "=" + System.getProperty(key.toString()));
+// }
try {
- try (OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext(config)) {
+ try (OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext((Map<String, String>) config)) {
osgiRuntimeContext.run();
Service.runtimeContext = osgiRuntimeContext;
Service.runtimeContext.waitForStop(0);
} catch (NoClassDefFoundError e) {
- try (StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext(config)) {
+ try (StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext((Map<String, String>) config)) {
staticRuntimeContext.run();
Service.runtimeContext = staticRuntimeContext;
Service.runtimeContext.waitForStop(0);
String ext = moduleFileName.substring(lastDot + 1);
if (!"jar".equals(ext))
continue modules;
- String moduleName = moduleFileName.substring(0, lastDot);
- if (moduleName.endsWith("-SNAPSHOT"))
- moduleName = moduleName.substring(0, moduleName.length() - "-SNAPSHOT".length());
- int lastDash = moduleName.lastIndexOf('-');
- String versionStr = moduleName.substring(lastDash + 1);
- String componentName = moduleName.substring(0, lastDash);
+// String moduleName = moduleFileName.substring(0, lastDot);
+// if (moduleName.endsWith("-SNAPSHOT"))
+// moduleName = moduleName.substring(0, moduleName.length() - "-SNAPSHOT".length());
+// int lastDash = moduleName.lastIndexOf('-');
+// String versionStr = moduleName.substring(lastDash + 1);
+// String componentName = moduleName.substring(0, lastDash);
// if(versionStr.endsWith("-SNAPSHOT")) {
// versionStr = readVersionFromModule(modulePath);
// }
Version version;
- try {
+// try {
+// version = new Version(versionStr);
+// } catch (Exception e) {
+ String versionStr = readVersionFromModule(modulePath);
+ String componentName = readSymbolicNameFromModule(modulePath);
+ if (versionStr != null) {
version = new Version(versionStr);
- } catch (Exception e) {
- versionStr = readVersionFromModule(modulePath);
- if (versionStr != null) {
- version = new Version(versionStr);
- } else {
- OsgiBootUtils.debug("Ignore " + modulePath + " (" + e.getMessage() + ")");
- continue modules;
- }
+ } else {
+ OsgiBootUtils.debug("Ignore " + modulePath + " since version cannot be found");
+ continue modules;
}
+// }
A2Component component = contribution.getOrAddComponent(componentName);
A2Module module = component.getOrAddModule(version, modulePath);
if (OsgiBootUtils.isDebug())
// NOTE: this is the method called when logging a plain message without
// exception, so it should be considered as a format only when args are not null
+ if (format.contains("{}"))// workaround for weird Jetty formatting
+ params = null;
String msg = params == null ? format : MessageFormat.format(format, params);
publisher.log(this, level, bundle, msg, now, thread, (Throwable) null, findCallLocation(level, thread));
}
logEntry.put(KEY_THREAD, thread.getName());
// should be unmodifiable for security reasons
- submit(Collections.unmodifiableMap(logEntry));
+ if (!isClosed())
+ submit(Collections.unmodifiableMap(logEntry));
}
}
}
public void stop(BundleContext bundleContext) {
- if (loggingConfigurationSr != null)
- loggingConfigurationSr.unregister();
- if (logEntryPublisherSr != null)
- logEntryPublisherSr.unregister();
-
+// if (loggingConfigurationSr != null)
+// try {
+// loggingConfigurationSr.unregister();
+// } catch (Exception e) {
+// // silent
+// }
+// if (logEntryPublisherSr != null)
+// try {
+// logEntryPublisherSr.unregister();
+// } catch (Exception e) {
+// // silent
+// }
}
@Override
public void waitForStop(long timeout) throws InterruptedException {
if (framework == null)
throw new IllegalStateException("Framework is not initialised");
- stop(framework.getBundleContext());
framework.waitForStop(timeout);
}
@Override
public void close() throws Exception {
+ stop(framework.getBundleContext());
if (framework != null)
framework.stop();
}
--cp /usr/share/a2/org.argeo.tp.eclipse.equinox/org.eclipse.osgi.3.17.jar -jar /usr/share/a2/org.argeo.cms/org.argeo.init.2.3.jar
\ No newline at end of file
+-cp /usr/share/a2/org.argeo.tp.eclipse.equinox/org.eclipse.osgi.3.17.jar:/usr/share/a2/org.argeo.cms/org.argeo.init.2.3.jar org.argeo.init.Service
\ No newline at end of file