blob: a78e4f1af4083dcfd1fd3887cbafc69ef2cdd242 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;
import com.yahoo.yolean.system.CatchSigTerm;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author arnej27959
*/
public class StandaloneMain {
private static final Logger log = Logger.getLogger(StandaloneMain.class.getName());
private final BootstrapLoader loader;
static {
// force load slf4j to avoid other logging frameworks from initializing before it
org.slf4j.LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
}
public StandaloneMain() {
this.loader = new ApplicationLoader(Main.newOsgiFramework(), Main.newConfigModule());
}
public static void main(String [] args) {
if (args == null || args.length != 1 || args[0] == null) {
throw new IllegalArgumentException("Expected 1 argument, got " + Arrays.toString(args) + ".");
}
StandaloneMain me = new StandaloneMain();
me.run(args[0]);
}
void run(String bundleLocation) {
try {
System.out.println("debug\tInitializing application without privileges.");
loader.init(bundleLocation, false);
loader.start();
setupSigTermHandler();
waitForShutdown();
System.out.println("debug\tTrying to shutdown in a controlled manner.");
loader.stop();
System.out.println("debug\tTrying to clean up in a controlled manner.");
loader.destroy();
System.out.println("debug\tStopped ok.");
System.exit(0);
} catch (Throwable e) {
System.out.print("debug\tUnexpected: ");
e.printStackTrace();
log.log(Level.SEVERE, "Unexpected: ", e);
System.exit(6);
}
}
private final AtomicBoolean signalCaught = new AtomicBoolean(false);
private void setupSigTermHandler() {
CatchSigTerm.setup(signalCaught); // catch termination signal
}
private void waitForShutdown() {
synchronized (signalCaught) {
while (!signalCaught.get()) {
try {
signalCaught.wait();
} catch (InterruptedException e) {
// empty
}
}
}
}
}
|