ca.uhn.hl7v2.protocol.impl
Class ProcessorImpl

java.lang.Object
  extended by ca.uhn.hl7v2.protocol.impl.ProcessorImpl
All Implemented Interfaces:
Processor

public class ProcessorImpl
extends java.lang.Object
implements Processor

A default implementation of Processor.

Version:
$Revision: 1.4 $ updated on $Date: 2009/12/16 19:36:34 $ by $Author: jamesagnew $
Author:
Bryan Tripp

Field Summary
 
Fields inherited from interface ca.uhn.hl7v2.protocol.Processor
AA, AE, AL, AR, CA, CE, CR, ER, NE, SU
 
Constructor Summary
ProcessorImpl(ProcessorContext theContext, boolean isThreaded)
           
 
Method Summary
 void cycle(boolean expectingAck)
          Performs a single iteration of the receiving-side of the HL7 original mode or enhanced mode processing rules (see HL7 Standard v2.5 Chapter 2; the choice of rules is determined by message values).
 ProcessorContext getContext()
           
 boolean isAvailable(java.lang.String theAckId)
           
 Transportable receive(java.lang.String theAckId, long theTimeoutMillis)
          Gets the message with the given acknowledgement ID from the incoming message list.
 void reserve(java.lang.String theAckId, long thePeriodMillis)
          Indicates that the calling thread expects a message with a certain ack ID.
 void send(Transportable theMessage, int maxRetries, long retryIntervalMillis)
          Sends a message to a remote system via an underlying TransportLayer.
 void stop()
          If self-threaded, stops threads that have been created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessorImpl

public ProcessorImpl(ProcessorContext theContext,
                     boolean isThreaded)
Parameters:
theContext - source of supporting services
isThreaded - true if this class should create threads in which to call cycle(), and in which to send responses from Applications. This is the preferred mode. Use false if threading is not allowed, eg you are running the code in an EJB container. In this case, the send() and receive() methods will call cycle() themselves as needed. However, cycle() makes potentially blocking calls, so these methods may not return until the next message is received from the remote server, regardless of timeout. Probably the worst example of this would be if receive() was called to wait for an application ACK that was specified as "RE" (ie required on error). No response will be returned if the message is processed without error, and in a non-threaded environment, receive() will block forever. Use true if you can, otherwise study this class carefully. TODO: write a MLLPTransport with non-blocking IO TODO: reconnect transport layers on error and retry
Method Detail

stop

public void stop()
If self-threaded, stops threads that have been created.


send

public void send(Transportable theMessage,
                 int maxRetries,
                 long retryIntervalMillis)
          throws HL7Exception
Description copied from interface: Processor
Sends a message to a remote system via an underlying TransportLayer. If the message specifies that an accept ACK is required (under enhanced mode processing rules) then this method may retry if transmission does not appear to be successful. The call to this method blocks while this is happening. Retries are attempted if a CR message is received, or if no message is received in the specified time frame. If a CE is received, an exception is thrown. If a CA is received, the call returns quietly. If no accept ack is required, this method returns immediately after attempting to send a message, throwing an exception only if there is an immediate problem (eg the server can't be contacted). If an accept ack is required only on error, the method waits for maxRetries * retryItervalMillis for an error to be returned, and assumes that there is no error if none appears in that time. The message is not actually resent while waiting for an error ACK.

Specified by:
send in interface Processor
Parameters:
theMessage - the message to send
maxRetries - note that this should be a small value if you demand an accept ack only on error
retryIntervalMillis - note that this should be a small value if you demand an accept ack only on error
Throws:
TransportException - if there is an immediate problem trying to send the message.
HL7Exception
See Also:
Processor.send(ca.uhn.hl7v2.protocol.Transportable, int, long)

reserve

public void reserve(java.lang.String theAckId,
                    long thePeriodMillis)
Description copied from interface: Processor
Indicates that the calling thread expects a message with a certain ack ID. If this message arrives within the specified period of time, it will be held in an inbound list instead of being passed on to an Application. If a message is in this list it isAvailable() and can be had via receive()

Specified by:
reserve in interface Processor
Parameters:
theAckId - the acknowledgement ID of the message
thePeriodMillis - time span during which the message should be kept if received
See Also:
Processor.reserve(java.lang.String, long)

cycle

public void cycle(boolean expectingAck)
           throws HL7Exception
Description copied from interface: Processor

Performs a single iteration of the receiving-side of the HL7 original mode or enhanced mode processing rules (see HL7 Standard v2.5 Chapter 2; the choice of rules is determined by message values). Steps in the process are as follows:

1. TransportLayer.receive() is called to get the next message
2. Validation is performed and the message is stored locally.
2. If the message requires an accept ACK, then an accept, reject, or error message is returned as appropriate
3. If the message is an accept ack, it is added to a local list that can be accessed by the send() method
4. If the message has been reserved, it is added to the available message list.
5. Otherwise it is sent to an Application.

Specified by:
cycle in interface Processor
Parameters:
expectingAck - is passed to TransportLayer.receive(), and may determine where the message is read from (eg different sockets may be used for commit-level ACKs). Note that this call blocks until a message is ready at the specified location, so to run the Processor continuously, separate threads are needed to call cycle() with true and false args.
Throws:
HL7Exception
See Also:
Processor.cycle(boolean)

isAvailable

public boolean isAvailable(java.lang.String theAckId)
Specified by:
isAvailable in interface Processor
Parameters:
theAckId - the acknowledgement ID of an expected message
Returns:
true if the message has come in and has been saved in the inbound message list
See Also:
Processor.isAvailable(java.lang.String)

receive

public Transportable receive(java.lang.String theAckId,
                             long theTimeoutMillis)
                      throws HL7Exception
Description copied from interface: Processor
Gets the message with the given acknowledgement ID from the incoming message list. This method blocks until the message appears on the list. If you don't want to block, call isAvailable() to see if it is there. Note also that the message has no way of arriving on the list during this call unless the Processor is running as a thread, or unless some other thread is calling cycle().

Specified by:
receive in interface Processor
theTimeoutMillis - milliseconds until the call times out and returns null if the desired message is not available.
Returns:
the incoming message with the given ack ID, or null if the call times out.
Throws:
HL7Exception
See Also:
Processor.receive(java.lang.String, long)

getContext

public ProcessorContext getContext()
Specified by:
getContext in interface Processor
Returns:
the operational context of this protocol instance
See Also:
Processor.getContext()


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