1 package org
.argeo
.init
;
3 import java
.lang
.System
.Logger
;
4 import java
.util
.HashMap
;
7 import org
.argeo
.init
.osgi
.OsgiRuntimeContext
;
9 public class Service
implements Runnable
, AutoCloseable
{
10 private final static Logger log
= System
.getLogger(Service
.class.getName());
12 private static RuntimeContext runtimeContext
= null;
14 protected Service(String
[] args
) {
22 public void close() throws Exception
{
25 public static void main(String
[] args
) {
26 long pid
= ProcessHandle
.current().pid();
27 log
.log(Logger
.Level
.DEBUG
, "Starting with PID " + pid
);
30 Runtime
.getRuntime().addShutdownHook(new Thread(() -> {
32 if (Service
.runtimeContext
!= null)
33 Service
.runtimeContext
.close();
34 } catch (Exception e
) {
38 }, "Runtime shutdown"));
40 Map
<String
, String
> config
= new HashMap
<>();
42 try (OsgiRuntimeContext osgiRuntimeContext
= new OsgiRuntimeContext(config
)) {
43 osgiRuntimeContext
.run();
44 Service
.runtimeContext
= osgiRuntimeContext
;
45 Service
.runtimeContext
.waitForStop(0);
46 } catch (NoClassDefFoundError e
) {
47 try (StaticRuntimeContext staticRuntimeContext
= new StaticRuntimeContext(config
)) {
48 staticRuntimeContext
.run();
49 Service
.runtimeContext
= staticRuntimeContext
;
50 Service
.runtimeContext
.waitForStop(0);
53 } catch (Exception e
) {