|
- package de.uniluebeck.mi.projmi6.hapi;
-
- import ca.uhn.hl7v2.DefaultHapiContext;
- import ca.uhn.hl7v2.HapiContext;
- import ca.uhn.hl7v2.app.HL7Service;
- import ca.uhn.hl7v2.model.v251.message.ADT_A01;
- import ca.uhn.hl7v2.model.v251.message.BAR_P05;
- import de.uniluebeck.mi.projmi6.controller.MainController;
-
- import java.util.concurrent.ArrayBlockingQueue;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
-
- /**
- * Created by nils on 20.11.2015.
- */
- public class HL7Server {
-
- private static final int PORT = 1111;
- private final HapiContext context;
- private final HL7Service server;
- private final ThreadPoolExecutor executor;
-
- public HL7Server(MainController mainctrl) throws InterruptedException {
- executor = new ThreadPoolExecutor(10, 100, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));
- executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
-
- context = new DefaultHapiContext();
- context.setExecutorService(executor);
- server = context.newServer(PORT, false);
-
- server.registerApplication("ADT", "A01", new HL7Receiver<ADT_A01>(ADT_A01.class, mainctrl));
- server.registerApplication("BAR", "P05", new HL7Receiver<BAR_P05>(BAR_P05.class, mainctrl));
-
- server.registerConnectionListener(new HL7ConnectionListener());
- server.setExceptionHandler(new HL7ExceptionHandler());
-
- //server.startAndWait();
- server.start();
- }
-
- public void stop() {
- if (server != null && server.isRunning()) {
- server.stop();
- }
- }
-
- public void shutdown() {
- if (executor != null && !executor.isTerminated()) {
- executor.shutdown();
- }
- }
- }
|