|
- package de.uniluebeck.mi.projmi6.hapi2;
-
- 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 java.util.concurrent.ArrayBlockingQueue;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
-
- /**
- * Created by nils on 20.11.2015.
- */
- public class HL7Server2 {
-
- private static final int PORT = 1111;
- private final HapiContext context;
- private final HL7Service server;
- private final ThreadPoolExecutor executor;
-
- public HL7Server2() 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 HL7Recever2<ADT_A01>(ADT_A01.class));
- server.registerApplication("BAR", "P05", new HL7Recever2<BAR_P05>(BAR_P05.class));
-
- server.registerConnectionListener(new HL7ConnectionListener2());
- server.setExceptionHandler(new HL7ExceptionHandler2());
-
- //server.startAndWait();
- server.start();
- }
-
- // TODO: Remove, for testing purpose only!
- public static void main(String[] args) throws InterruptedException {
- HL7Server2 srv = new HL7Server2();
- for (; ; ) {
-
- }
- //srv.stop();
- //srv.shutdown();
- }
-
- public void stop() {
- if (server != null && server.isRunning()) {
- server.stop();
- }
- }
-
- public void shutdown() {
- if (executor != null && !executor.isTerminated()) {
- executor.shutdown();
- }
- }
- }
|