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