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