1 | |
package ca.uhn.hl7v2.hoh.relay; |
2 | |
|
3 | |
import java.io.FileNotFoundException; |
4 | |
|
5 | |
import org.springframework.context.ApplicationContext; |
6 | |
import org.springframework.context.support.FileSystemXmlApplicationContext; |
7 | |
import org.springframework.util.Log4jConfigurer; |
8 | |
|
9 | |
import ca.uhn.hl7v2.hoh.util.IOUtils; |
10 | |
import ca.uhn.hl7v2.hoh.util.VersionLogger; |
11 | |
|
12 | |
public class Launcher { |
13 | 5 | private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Launcher.class); |
14 | |
|
15 | |
private FileSystemXmlApplicationContext myAppContext; |
16 | |
|
17 | |
public Launcher() { |
18 | 0 | this("conf" + IOUtils.FILE_PATH_SEP + "config.xml"); |
19 | 0 | } |
20 | |
|
21 | 15 | public Launcher(String configFile) { |
22 | 15 | long start = System.currentTimeMillis(); |
23 | |
|
24 | 15 | StringBuilder b = new StringBuilder(); |
25 | 15 | b.append("HAPI HL7 over HTTP Relay is starting. This software is Licensed under the "); |
26 | 15 | b.append("Apache Software License (version 2.0) and is Copyright(c) "); |
27 | 15 | b.append("2012 University Health Network."); |
28 | 15 | ourLog.info(b.toString()); |
29 | |
|
30 | 15 | VersionLogger.init(); |
31 | |
|
32 | 15 | Runtime.getRuntime().addShutdownHook(new ShutdownHook()); |
33 | |
|
34 | 15 | myAppContext = new FileSystemXmlApplicationContext(configFile); |
35 | 15 | myAppContext.start(); |
36 | |
|
37 | 15 | long delay = System.currentTimeMillis() - start; |
38 | 15 | ourLog.info("HAPI HL7 over HTTP Relay started in {} ms", delay); |
39 | 15 | } |
40 | |
|
41 | |
public ApplicationContext getAppCtx() { |
42 | 0 | return myAppContext; |
43 | |
} |
44 | |
|
45 | |
public void shutdown() { |
46 | 29 | ourLog.info("Shutdown request detected, stopping all services"); |
47 | 24 | if (myAppContext != null) { |
48 | 15 | myAppContext.close(); |
49 | 15 | myAppContext = null; |
50 | |
} |
51 | 24 | ourLog.info("Shutdown request completed"); |
52 | 24 | } |
53 | |
|
54 | |
public static void main(String[] args) throws FileNotFoundException { |
55 | 0 | Log4jConfigurer.initLogging("file:conf" + IOUtils.FILE_PATH_SEP + "log4j.xml"); |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | 0 | new Launcher(); |
62 | 0 | } |
63 | |
|
64 | 30 | private final class ShutdownHook extends Thread { |
65 | |
@Override |
66 | |
public void run() { |
67 | 15 | shutdown(); |
68 | 12 | } |
69 | |
} |
70 | |
|
71 | |
} |