Class HL7Service
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
SimpleServer,TwoPortService
An HL7 service. Accepts incoming TCP/IP connections and creates Connection objects. Uses a single ApplicationRouter 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, Christian Ohr
-
Constructor Summary
ConstructorsConstructorDescriptionHL7Service(HapiContext theHapiContext) HL7Service(Parser parser, LowerLayerProtocol llp) HL7Service(Parser parser, LowerLayerProtocol llp, ExecutorService executorService) Creates a new instance of Server -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled after startup before the thread enters its main loop.protected voidCalled after the thread has left its main loop.getRemoteConnection(String ipAddress) Returns a connection to a remote host that was initiated by the given remote host.Returns all currently active connections.protected booleanDeprecated.voidA convenience method for registering applications (usingregisterApplication()) with this service.voidCalled by subclasses when a new Connection is made.voidregisterApplication(ApplicationRouter.AppRoutingData appRouting, ReceivingApplication<? extends Message> application) Registers the given application to handle messages corresponding to ALL message types and trigger events.voidregisterApplication(ReceivingApplication<? extends Message> application) Registers the given application to handle messages corresponding to ALL message types and trigger events.voidregisterApplication(String messageType, String triggerEvent, Application handler) voidregisterApplication(String messageType, String triggerEvent, ReceivingApplication handler) Registers the given application to handle messages corresponding to the given type and trigger event.voidregisterConnectionListener(ConnectionListener listener) Registers the given ConnectionListener with the HL7Service - when a remote host makes a new Connection, all registered listeners will be notified.voidSets an exception handler which will be invoked in the event of a failure during parsing, processing, or encoding of an incoming message or its response.voidsetParserExeptionHandler(Receiver.ReceiverParserExceptionHandler parserExeptionHandler) Register a receiver level parser exception handler so that an application can be notified of protocol level parsing errors if anybooleanUnregisteres the first application that matches the routing databooleanunregisterApplication(ReceivingApplication<? extends Message> application) Unregisteres the passed applicationMethods inherited from class ca.uhn.hl7v2.concurrent.Service
getExecutorService, getServiceExitedWithException, handle, isRunning, prepareTermination, run, setServiceExitedWithException, setShutdownTimeout, start, startAndWait, stop, stopAndWait, waitForTermination
-
Constructor Details
-
HL7Service
- Parameters:
theHapiContext- HapiContext
-
HL7Service
- Parameters:
parser- parser to be usedllp- LowerLayerProtocol
-
HL7Service
Creates a new instance of Server- Parameters:
parser- parser to be usedllp- LowerLayerProtocolexecutorService- executor used for starting threads
-
-
Method Details
-
afterStartup
Called after startup before the thread enters its main loop. This implementation launches a cleaner thread that removes stale connections from the connection list. Override to initialize resources for the running thread, e.g. openingServerSockets etc.- Overrides:
afterStartupin classService
-
afterTermination
Called after the thread has left its main loop. This implementation stops the connection cleaner thread and closes any open connections. Override to clean up additional resources from the running thread, e.g. closingServerSockets.- Overrides:
afterTerminationin classService
-
keepRunning
Deprecated.UseService.isRunning(). Deprecated as of version 0.6.Returns true if the thread should continue to run, false otherwise (ie if stop() has been called). -
newConnection
Called by subclasses when a new Connection is made. Registers the ApplicationRouter with the given Connection and stores it.- Parameters:
c- existing connection
-
getRemoteConnection
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.- Parameters:
ipAddress- IP Address- Returns:
- connection that was initiated by the given address
-
getRemoteConnections
Returns all currently active connections.- Returns:
- list of active remote connections
-
registerConnectionListener
Registers the given ConnectionListener with the HL7Service - when a remote host makes a new Connection, all registered listeners will be notified.- Parameters:
listener- connection listener to be called
-
registerApplication
Deprecated.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. -
registerApplication
public void registerApplication(String messageType, String triggerEvent, ReceivingApplication 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. -
registerApplication
public void registerApplication(ApplicationRouter.AppRoutingData appRouting, ReceivingApplication<? extends Message> application) Registers the given application to handle messages corresponding to ALL message types and trigger events. -
registerApplication
Registers the given application to handle messages corresponding to ALL message types and trigger events. -
unregisterApplication
Unregisteres the first application that matches the routing data- Parameters:
appRouting-- Returns:
- true if an application was unregistered, false otherwise
-
unregisterApplication
Unregisteres the passed application- Parameters:
application- receiving application- Returns:
- true if an application was unregistered, false otherwise
-
setExceptionHandler
Sets an exception handler which will be invoked in the event of a failure during parsing, processing, or encoding of an incoming message or its response. -
setParserExeptionHandler
Register a receiver level parser exception handler so that an application can be notified of protocol level parsing errors if any -
loadApplicationsFromFile
public void loadApplicationsFromFile(File f) throws IOException, HL7Exception, ClassNotFoundException, InstantiationException, 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.ResultProcessorEach class listed in this file must implement Application and must have a zero-argument constructor.
-
Service.isRunning().