ca.uhn.hl7v2.app
Class HL7Service

java.lang.Object
  extended by ca.uhn.hl7v2.app.HL7Service
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SimpleServer, TwoPortService

public abstract class HL7Service
extends java.lang.Object
implements java.lang.Runnable

An HL7 service. Accepts incoming TCP/IP connections and creates Connection objects. Uses a single MessageTypeRouter object (for all Connections) to define the Applications to which message are sent. To configure, use registerApplication() or loadApplicationsFromFile().

A separate thread looks for Connections that have been closed (locally or remotely) and discards them.

Author:
Bryan Tripp

Field Summary
protected  LowerLayerProtocol llp
           
protected  Parser parser
           
 
Constructor Summary
HL7Service(Parser parser, LowerLayerProtocol llp)
          Creates a new instance of Server
 
Method Summary
 Connection getRemoteConnection(java.lang.String IP)
          Returns a connection to a remote host that was initiated by the given remote host.
 java.util.Vector getRemoteConnections()
          Returns all currently active connections.
 boolean isRunning()
           
protected  boolean keepRunning()
          Deprecated. Use isRunning(). Deprecated as of version 0.6.
 void loadApplicationsFromFile(java.io.File f)
          A convenience method for registering applications (using registerApplication() ) with this service.
 void newConnection(Connection c)
          Called by subclasses when a new Connection is made.
 void registerApplication(java.lang.String messageType, java.lang.String triggerEvent, Application handler)
          Registers the given application to handle messages corresponding to the given type and trigger event.
 void registerConnectionListener(ConnectionListener listener)
          Registers the given ConnectionListener with the HL7Service - when a remote host makes a new Connection, all registered listeners will be notified.
abstract  void run()
          Implemented by subclasses to accept remote connections, create Connection objects, and call newConnection().
 void start()
          Starts the server listening for connections in a new thread.
 void stop()
          Stops the server from listening for new connections, and closes all existing Connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected Parser parser

llp

protected LowerLayerProtocol llp
Constructor Detail

HL7Service

public HL7Service(Parser parser,
                  LowerLayerProtocol llp)
Creates a new instance of Server

Method Detail

run

public abstract void run()
Implemented by subclasses to accept remote connections, create Connection objects, and call newConnection(). Must stop running when keepRunning() returns false, and clean up all resources before exiting. If this method quits because of an exception, it must call HL7Service.stop() before exiting.

Specified by:
run in interface java.lang.Runnable

keepRunning

protected boolean keepRunning()
Deprecated. Use isRunning(). Deprecated as of version 0.6.

Returns true if the thread should continue to run, false otherwise (ie if stop() has been called).


isRunning

public boolean isRunning()
Returns:
Returns true if the server has been started, and has not yet been stopped.

start

public void start()
Starts the server listening for connections in a new thread. This continues until stop() is called.


stop

public void stop()
Stops the server from listening for new connections, and closes all existing Connections.


newConnection

public void newConnection(Connection c)
Called by subclasses when a new Connection is made. Registers the MessageTypeRouter with the given Connection and stores it.


getRemoteConnection

public Connection getRemoteConnection(java.lang.String IP)
Returns a connection to a remote host that was initiated by the given remote host. If the connection has not been made, this method blocks until the remote host connects.


getRemoteConnections

public java.util.Vector getRemoteConnections()
Returns all currently active connections.


registerConnectionListener

public void registerConnectionListener(ConnectionListener listener)
Registers the given ConnectionListener with the HL7Service - when a remote host makes a new Connection, all registered listeners will be notified.


registerApplication

public void registerApplication(java.lang.String messageType,
                                java.lang.String triggerEvent,
                                Application handler)
Registers the given application to handle messages corresponding to the given type and trigger event. Only one application can be registered for a given message type and trigger event combination. A repeated registration for a particular combination of type and trigger event over-writes the previous one. Note that the wildcard "*" for messageType or triggerEvent means any type or event, respectively.


loadApplicationsFromFile

public void loadApplicationsFromFile(java.io.File f)
                              throws java.io.IOException,
                                     HL7Exception,
                                     java.lang.ClassNotFoundException,
                                     java.lang.InstantiationException,
                                     java.lang.IllegalAccessException

A convenience method for registering applications (using registerApplication() ) with this service. Information about which Applications should handle which messages is read from the given text file. Each line in the file should have the following format (entries tab delimited):

message_type trigger_event application_class

message_type trigger_event application_class

Note that message type and event can be the wildcard "*", which means any.

For example, if you write an Application called org.yourorganiztion.ADTProcessor that processes several types of ADT messages, and another called org.yourorganization.ResultProcessor that processes result messages, you might have a file that looks like this:

ADT * org.yourorganization.ADTProcessor
ORU R01 org.yourorganization.ResultProcessor

Each class listed in this file must implement Application and must have a zero-argument constructor.

Throws:
java.io.IOException
HL7Exception
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException


Copyright © 2001-2011 University Health Network. All Rights Reserved.