import java.io.IOException;
import java.io.InputStream;
import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
private static RuntimeContext runtimeContext = null;
+ private static List<Runnable> postStart = Collections.synchronizedList(new ArrayList<>());
+
protected Service(String[] args) {
}
OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext(config);
osgiRuntimeContext.run();
Service.runtimeContext = osgiRuntimeContext;
+ for (Runnable run : postStart) {
+ try {
+ run.run();
+ } catch (Exception e) {
+ logger.log(Level.ERROR, "Cannot run post start callback " + run, e);
+ }
+ }
Service.runtimeContext.waitForStop(0);
- } catch (NoClassDefFoundError e) {
+ } catch (NoClassDefFoundError noClassDefFoundE) {
StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext((Map<String, String>) config);
staticRuntimeContext.run();
Service.runtimeContext = staticRuntimeContext;
+ for (Runnable run : postStart) {
+ try {
+ run.run();
+ } catch (Exception e) {
+ logger.log(Level.ERROR, "Cannot run post start callback " + run, e);
+ }
+ }
Service.runtimeContext.waitForStop(0);
}
} catch (Exception e) {
public static RuntimeContext getRuntimeContext() {
return runtimeContext;
}
+
+ /** Add a post-start call back to be run after the runtime has been started. */
+ public static void addPostStart(Runnable runnable) {
+ postStart.add(runnable);
+ }
}