cdac.medinfo.sdk.hl7282.hl7net.upperlayer

## Class UserSession

- java.lang.Object
- - cdac.medinfo.sdk.hl7282.hl7net.upperlayer.UserSession

- All Implemented Interfaces:
    IConnectionListener, IDataNotificationListener, IExceptionReceiver

      public class UserSession
      extends java.lang.Object
      implements IDataNotificationListener, IExceptionReceiver, IConnectionListener

  User Session provides method for client side to Query other systems & also to trigger any specific Event.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `UserSession()` Instantiates User Session
    `UserSession(java.net.Socket objSocket)` Instantiates User Session by given connection.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addExceptionListener(IExceptionListener objIExceptionListener)` Register for Receiving Deferred Response.
    `boolean` | `close()` Close.
    `void` | `closeConnection()` This function is automatically invoked when connection is closed by remote end.
    `void` | `connect(java.net.InetAddress ip, int iPort)` Connects this UserSession to provided server IP address and port.
    `void` | `connect(java.net.InetSocketAddress addr)` Connects this UserSession to provided server Socket Address
    `void` | `connect(int iPort)` Connects this UserSession to provided server on local host to given port
    `void` | `connect(java.lang.String strIP, int iPort)` Connects this UserSession to provided server IP Address and port
    `void` | `enableMLLP()` Enable MLLP at User session.
    `EnumErrorCode` | `getErrorCode()` Retrieves Error Code of received message.
    `IProcessHandler` | `getListener()` Retrieves instance of Listener Which implements IProcessHandler, All messages subscribed by this UserSession are received using this listener.
    `Message` | `getMessage()` Retrieves Message from UserSession.
    `ISingleCollection<Message>` | `getRecievedMessagesCollection(java.lang.String strMessageControlID)` This method returns the Collection of Message by MessageControlId.
    `ISingleCollection<IHL7BatchFile>` | `getResponseBatches()` Retrieves last received Response Batch collection.
    `int` | `getTimeOut()` Returns setting for Socket read timeout of this session, 0 returns implies that the option is disabled (i.e., timeout of infinity).
    `int` | `getWaitPeriod()` Retrieves the wait Period for which UserSession should wait till it receives ACK/Reponse for triggered event/Query.
    `void` | `notifyData(IHL7BatchFile objBatchFile)` Invoked when HL7BatchFile is received from Remote End.
    `void` | `notifyData(Message objReceivedMessage, EnumErrorCode enumErrorCode)` Invoked when Message is received from Remote End.
    `void` | `onException(java.lang.Exception ex, byte[] buffer)` Invoked when exception is fetched while processing Message.
    `void` | `onException(java.lang.Exception ex, ISegmentSet objISegmentSet)` Invoked when exception is fetched while processing Message.
    `boolean` | `sendBatchFile(IHL7BatchFile objBatchFile)` Sends specified HL7BatchFile server system if Batch processor is supported.
    `boolean` | `sendBatchFile(java.lang.String strFilePath)` This method parses HL7Batch from file located at given path if Batch Processor is supported.
    `boolean` | `sendMessage(Message messageToSend)` Sends the message to server system.
    `boolean` | `sendMessage(java.lang.String strFilePath)` This method parses message from file located at given path.
    `void` | `setBatchProcessor(IBatchProcessor objIBatchProcessor)` Sets the Batch Processor
    `void` | `setClientSideQCNAgent(IClientQueryCancellation objClientSideQCNAgent)` This will set the Query Cancellation agent on ClientSideMessageAgent
    `void` | `setClientSideQICAgent(IClientInteractiveContinuation objClientSideQICAgent)` Sets the Interactive Continuation Agent.
    `void` | `setClientSideTransactionHandler(ITransactionHandler objClientSideTransactionHandler)` This will set the ITransactionHandler on User session.
    `void` | `setErrorCode(EnumErrorCode enumErrorCode)` Sets Error Code of received
    `void` | `setFragmentProcessor(IFragmentProcessor objIFragmentProcessor)` Sets the Fragment Processor
    `void` | `setIBatchReceiver(IBatchReceiver objIBatchReceiver)` This will set the IBatchReceiver on user session.
    `void` | `setICanceledResponseReceiver(ICanceledResponseReceiver objCanceledResponseReceiver)` This will set the ICanceledResponseReceiver on user session.
    `void` | `setIInteractiveResponseReciever(IInteractiveResponseReciever objInteractiveResponseReciever)` This will set the IInteractiveResponseReciever on user session.
    `void` | `setListener(IProcessHandler objProcessHandler)` Sets Listener Which implements IProcessHandler, All messages subscribed by this UserSession are received using this listener.
    `void` | `setLocalExtensionAgent(LocalExtensionAgent objLocalExtensionAgent)` sets localextensionAgent on UserSession.
    `void` | `setMessage(Message objHL7Message)` Sets Message on UserSession.
    `void` | `setMessageFactory(MessageFactory objMessageFactory)` Sets Message Factory
    `void` | `setReadWriteLength(int iReadLength, int iWriteLength)` Sets max length limit of reading and writing.
    `void` | `setSequenceAgent(ISequenceAgent objSequenceAgent)` Sets the sequence agent on UserSession.Sequence Agent is required to enable Sequence Numbering in the message transactions.
    `void` | `setTimeOut(int itimeout)` sets Socket read timeout of this session, in milliseconds.
    `void` | `setWaitPeriod(int waitPeriod)` Sets the wait period for which UserSession should wait till it receives ACK/reponse for triggered event/Query.
    `void` | `stopListener()` Stops listening for HL7 message if listener is started.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### UserSession

          public UserSession()

      Instantiates User Session

    - #### UserSession

          public UserSession(java.net.Socket objSocket)
                      throws java.io.IOException

      Instantiates User Session by given connection.
      Parameters:
        `objSocket` - Specified socket to which UserSessoin is to be connected
      Throws:
        `java.io.IOException` - thrown when IOOperation fails

  - ### Method Detail

    - #### setClientSideQICAgent

          public void setClientSideQICAgent(IClientInteractiveContinuation objClientSideQICAgent)

      Sets the Interactive Continuation Agent.
      Parameters:
        `objClientSideQICAgent` - the ClientSideQICAgent to set.

    - #### setSequenceAgent

          public void setSequenceAgent(ISequenceAgent objSequenceAgent)

      Sets the sequence agent on UserSession.Sequence Agent is required to enable Sequence Numbering in the message transactions.
      Parameters:
        `objSequenceAgent` - Sequence Agent to be set on UserSession.

    - #### onException

          public void onException(java.lang.Exception ex,
                         byte[] buffer)

      Invoked when exception is fetched while processing Message.
      Specified by:
        `onException` in interface `IExceptionReceiver`
      Parameters:
        `ex` - Exception fetched
        `buffer` - data for which error is fetched

    - #### onException

          public void onException(java.lang.Exception ex,
                         ISegmentSet objISegmentSet)

      Invoked when exception is fetched while processing Message.
      Specified by:
        `onException` in interface `IExceptionReceiver`
      Parameters:
        `ex` - Exception fetched
        `buffer` - data for which error is fetched

    - #### setFragmentProcessor

          public void setFragmentProcessor(IFragmentProcessor objIFragmentProcessor)

      Sets the Fragment Processor
      Parameters:
        `objIFragmentProcessor` - the objIFragmentProcessor to set

    - #### enableMLLP

          public void enableMLLP()

      Enable MLLP at User session.

    - #### setBatchProcessor

          public void setBatchProcessor(IBatchProcessor objIBatchProcessor)

      Sets the Batch Processor
      Parameters:
        `objIBatchProcessor` - the objIBatchProcessor to set

    - #### setMessageFactory

          public void setMessageFactory(MessageFactory objMessageFactory)

      Sets Message Factory
      Parameters:
        `objMessageFactory` - instance of Message Factory

    - #### getWaitPeriod

          public int getWaitPeriod()

      Retrieves the wait Period for which UserSession should wait till it receives ACK/Reponse for triggered event/Query.
      Returns:
        int - wait period

    - #### setReadWriteLength

          public void setReadWriteLength(int iReadLength,
                                int iWriteLength)

      Sets max length limit of reading and writing.
      Parameters:
        `iReadLength` - value of Reading max length
        `iWriteLength` - value of Writing max length

    - #### setWaitPeriod

          public void setWaitPeriod(int waitPeriod)

      Sets the wait period for which UserSession should wait till it receives ACK/reponse for triggered event/Query.
      Parameters:
        `waitPeriod` - Specifies wait period for UserSession.

    - #### getMessage

          public Message getMessage()

      Retrieves Message from UserSession.
      Returns:
        Message Specifies object of Message from UserSession.

    - #### setMessage

          public void setMessage(Message objHL7Message)

      Sets Message on UserSession.
      Parameters:
        `objHL7Message` - Specifies object of Message from UserSession.

    - #### getListener

          public IProcessHandler getListener()

      Retrieves instance of Listener Which implements IProcessHandler, All messages subscribed by this UserSession are received using this listener.
      Returns:
        IProcessHandler instance of listener implements IProcessHandler

    - #### setListener

          public void setListener(IProcessHandler objProcessHandler)

      Sets Listener Which implements IProcessHandler, All messages subscribed by this UserSession are received using this listener.
      Parameters:
        `objProcessHandler` - instance of listener implements IProcessHandler

    - #### addExceptionListener

          public void addExceptionListener(IExceptionListener objIExceptionListener)

      Register for Receiving Deferred Response.
      Parameters:
        `objIExceptionListener` - - implementor of IExceptionListener

    - #### setIInteractiveResponseReciever

          public void setIInteractiveResponseReciever(IInteractiveResponseReciever objInteractiveResponseReciever)

      This will set the IInteractiveResponseReciever on user session.
      Parameters:
        `objInteractiveResponseReciever` - - implementor of IInteractiveResponseReciever

    - #### setIBatchReceiver

          public void setIBatchReceiver(IBatchReceiver objIBatchReceiver)

      This will set the IBatchReceiver on user session.
      Parameters:
        `objIExceptionListener` - - implementor of IExceptionListener

    - #### setICanceledResponseReceiver

          public void setICanceledResponseReceiver(ICanceledResponseReceiver objCanceledResponseReceiver)

      This will set the ICanceledResponseReceiver on user session.
      Parameters:
        `objCanceledResponseReceiver` - - implementor of ICanceledResponseReceiver.

    - #### setClientSideTransactionHandler

          public void setClientSideTransactionHandler(ITransactionHandler objClientSideTransactionHandler)

      This will set the ITransactionHandler on User session.
      Parameters:
        `objClientSideTransactionHandler` - - implementor of ITransactionHandler

    - #### getErrorCode

          public EnumErrorCode getErrorCode()

      Retrieves Error Code of received message.
      Returns:
        EnumErrorCode - Error Code returned

    - #### setErrorCode

          public void setErrorCode(EnumErrorCode enumErrorCode)

      Sets Error Code of received
      Parameters:
        `enumErrorCode` -

    - #### notifyData

          public void notifyData(Message objReceivedMessage,
                        EnumErrorCode enumErrorCode)
                          throws java.io.IOException,
                                 InvalidMessageException

      Invoked when Message is received from Remote End.
      Specified by:
        `notifyData` in interface `IDataNotificationListener`
      Parameters:
        `objReceivedMessage` - Received Message
        `enumErrorCode` - Received Error Code
      Throws:
        `java.io.IOException` - Signals that an IO Exception has occurred.
        `InvalidMessageException`

    - #### stopListener

          public void stopListener()
                            throws java.io.IOException

      Stops listening for HL7 message if listener is started.
      Throws:
        `java.io.IOException`

    - #### notifyData

          public void notifyData(IHL7BatchFile objBatchFile)

      Invoked when HL7BatchFile is received from Remote End.
      Specified by:
        `notifyData` in interface `IDataNotificationListener`
      Parameters:
        `objBatchFile` - Received Message

    - #### getResponseBatches

          public ISingleCollection<IHL7BatchFile> getResponseBatches()

      Retrieves last received Response Batch collection.
      Returns:
        ISingleCollection - Collection of ACK messages received.

    - #### connect

          public void connect(java.lang.String strIP,
                     int iPort)
                       throws java.io.IOException

      Connects this UserSession to provided server IP Address and port
      Parameters:
        `strIP` - IP address specified in String format
        `iPort` - specified Port
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### connect

          public void connect(int iPort)
                       throws java.io.IOException

      Connects this UserSession to provided server on local host to given port
      Parameters:
        `iPort` - int value of port.
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### connect

          public void connect(java.net.InetAddress ip,
                     int iPort)
                       throws java.io.IOException

      Connects this UserSession to provided server IP address and port.
      Parameters:
        `ip` - instance of INet Address.
        `iPort` - int value of port.
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### connect

          public void connect(java.net.InetSocketAddress addr)
                       throws java.io.IOException

      Connects this UserSession to provided server Socket Address
      Parameters:
        `addr` - specified address
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### sendMessage

          public boolean sendMessage(Message messageToSend)
                              throws java.io.IOException

      Sends the message to server system. In case of Event or Query this method waits until an ACK is received.
      Parameters:
        `messageToSend` - instance of message
      Returns:
        boolean - shows status as success or failure if sending operation performed successfully it returns true else false.
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### sendMessage

          public boolean sendMessage(java.lang.String strFilePath)
                              throws java.io.IOException

      This method parses message from file located at given path. After parsing it sends the message to server system
      Parameters:
        `strFilePath` - specified path of File containing message
      Returns:
        boolean - shows status as success or failure if sending operation performed successfully it returns true else false.
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### sendBatchFile

          public boolean sendBatchFile(IHL7BatchFile objBatchFile)
                                throws java.io.IOException

      Sends specified HL7BatchFile server system if Batch processor is supported.
      Parameters:
        `objBatchFile` - instance of HL7 Batch file
      Returns:
        boolean - shows status as success or failure if sending operation performed successfully it returns true else false.
      Throws:
        `java.io.IOException` - Signals when IO error occurs.

    - #### sendBatchFile

          public boolean sendBatchFile(java.lang.String strFilePath)
                                throws java.io.IOException

      This method parses HL7Batch from file located at given path if Batch Processor is supported. After parsing it sends the HL7Batch to server system.
      Parameters:
        `strFilePath` - specified path of File containing HL7Batch
      Returns:
        boolean - shows status as success or failure if sending operation performed successfully it returns true else false.
      Throws:
        `java.io.IOException` - Signals that an I/O exception has occurred.

    - #### setLocalExtensionAgent

          public void setLocalExtensionAgent(LocalExtensionAgent objLocalExtensionAgent)

      sets localextensionAgent on UserSession. LocalExtensionAgent is required for handling of locally extended messages.
      Parameters:
        `objLocalExtensionAgent` - Specified LocallyExtendedAgent to be set on UserSession.

    - #### closeConnection

          public void closeConnection()

      This function is automatically invoked when connection is closed by remote end.
      Specified by:
        `closeConnection` in interface `IConnectionListener`

    - #### close

          public boolean close()
                        throws java.io.IOException

      Close.
      Returns:
        true, if successful
      Throws:
        `java.io.IOException`

    - #### getTimeOut

          public int getTimeOut()

      Returns setting for Socket read timeout of this session, 0 returns implies that the option is disabled (i.e., timeout of infinity).
      Returns:
        the setting for socket read timeout.

    - #### setTimeOut

          public void setTimeOut(int itimeout)

      sets Socket read timeout of this session, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time.If the timeout expires, a session is closed,The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
      Parameters:
        `timeout` - the specified timeout, in milliseconds.

    - #### getRecievedMessagesCollection

          public ISingleCollection<Message> getRecievedMessagesCollection(java.lang.String strMessageControlID)

      This method returns the Collection of Message by MessageControlId.
      Returns:
        ISingleCollection Collection of message.

    - #### setClientSideQCNAgent

          public void setClientSideQCNAgent(IClientQueryCancellation objClientSideQCNAgent)

      This will set the Query Cancellation agent on ClientSideMessageAgent
      Parameters:
        `objClientSideQCNAgent` - object of Client Side QCN Agent.