Sun Adapter for TCP/IP HL7

com.stc.connector.tcpip.model.client
Class TCPIPClientApplicationImpl

java.lang.Object
  extended by com.stc.connector.tcpip.model.client.TCPIPClientApplicationImpl
All Implemented Interfaces:
TCPIPClientApplication
Direct Known Subclasses:
TCPIPEXTClientApplicationImpl, TCPIPServerApplicationImpl

public class TCPIPClientApplicationImpl
extends java.lang.Object
implements TCPIPClientApplication

This class implements the TCPIP client application interface.

Version:
cvs revision: $Revision: 1.19 $ Last Modified: $Date: 2008/04/23 07:15:12 $
Author:
Harry Liu

Field Summary
protected  int defaultTimeout
          A default timeout value.
protected  TCPIPMonitorData mMonitorData
           
static java.lang.String version
           
 
Constructor Summary
TCPIPClientApplicationImpl()
          Default constructor for WSDL generation.
TCPIPClientApplicationImpl(TCPIPApplicationConnection appConn, java.lang.String appName, TCPIPMonitorData aMonitorData)
          Creates a new instance of TCPIPClientApplicationImpl
 
Method Summary
protected  void checkIfClosed()
          Checks whether the application connection was closed.
 void closeConnection()
          Closes the existing connection physically (no matter it is good or bad).
 TCPIPApplicationConnection getApplicationConnection()
          Gets the TCPIP application connection which created this instance of TCPIPClientApplication.
 java.lang.String getApplicationName()
           
 java.lang.String getCallingAdapter()
          Returns the callingAdapter.
 TCPIPClientGeneralInfo getClientGeneralInfo()
          Returns the TCPIPClientGeneralInfo instance.
 byte[] getLeftOverFromLastRead()
           
 int getMaxDataSize()
          Returns the maxDataSize.
protected  long getMaxEmptyReadRetry()
           
 com.stc.connector.management.util.ObjectReference getMonitor()
           
 javax.resource.spi.ResourceAdapter getResourceAdapter()
          Method getResourceAdapter.
 java.net.Socket getSocket()
          Returns the underlying java.net.Socket instance which the e*Way relys on.
 TCPIPSocketInfo getSocketInfo()
          Returns the TCPIPSocketInfo instance.
 java.lang.String getState()
          Returns the State which is set by user.
 StateHandler getStateHandler()
          Returns the stateHandler.
 TCPIPClientConfigInfoInterface getTCPIPOutboundConfigInfo()
          Returns an object which represents the base TCP/IP Outbound configuration information.
protected  int getTimeToWaitForAResponse()
           
 boolean isCalledByInbound()
          Returns the calledByInbound.
 boolean isClosed()
          Checks whether the connection is closed.
 boolean isServerCloseNotification(byte[] closeCommand)
          Returns true if the data which the server receives represents the close notification.
 boolean isServerCloseNotification(java.lang.String closeCommand)
          Returns true if the data which the server receives represents the close notification.
 boolean isServerIdleTimeout()
          Returns true if the server detects that the client has no actual activity (idle) for certain time.
protected  byte[] readFully()
          Read until no more data (end of file) or timeout occurs.
protected  byte[] readFully(boolean endOnTimeout)
          Read until no more data (end of file), or timeout occurs (if the parameter endOnTimeout is true).
 byte[] receiveBytes()
          Reads all data which is available on TCP/IP connection.
 java.lang.String receiveString()
          Reads all data which is available on TCP/IP connection.
 java.lang.String receiveString(java.lang.String encoding)
          Reads all data which is available on TCP/IP connection.
 void sendBytes(byte[] bytes)
          Sends a byte array through the TCP/IP connection.
 void sendString(java.lang.String str)
          Sends a String with JVM default encoding through the TCP/IP connection.
 void sendString(java.lang.String str, java.lang.String encoding)
          Sends a String with the specified encoding through the TCP/IP connection.
 void setApplicationConnection(TCPIPApplicationConnection appConn)
          Sets the TCPIP application connection.
 void setApplicationName(java.lang.String name)
           
protected  void setCalledByInbound(boolean calledByInbound)
          Sets the calledByInbound.
protected  void setCallingAdapter(java.lang.String callingAdapter)
          Sets the callingAdapter.
 void setClientGeneralInfo(TCPIPClientGeneralInfo clientGeneralInfo)
           
 void setLeftOverFromLastRead(byte[] bs)
           
 void setMaxDataSize(int maxDataSize)
          Sets the maxDataSize.
 void setSocketInfo(TCPIPSocketInfo socketInfo)
          Method setSocketInfo.
 void setState(java.lang.String stateValue)
          Sets State.
 void setTCPIPOutboundConfigInfo(TCPIPClientConfigInfo outboundConfigInfo)
           
 void updateMBeanProperty(java.lang.String propertyName, java.lang.String propertyDisplayValue)
          Updates certain RA MBean property with the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static final java.lang.String version
See Also:
Constant Field Values

defaultTimeout

protected int defaultTimeout
A default timeout value. It will be used under some situations.


mMonitorData

protected TCPIPMonitorData mMonitorData
Constructor Detail

TCPIPClientApplicationImpl

public TCPIPClientApplicationImpl()
Default constructor for WSDL generation.


TCPIPClientApplicationImpl

public TCPIPClientApplicationImpl(TCPIPApplicationConnection appConn,
                                  java.lang.String appName,
                                  TCPIPMonitorData aMonitorData)
Creates a new instance of TCPIPClientApplicationImpl

Parameters:
appConn - The application connection which created this instance of application.
appName - The applicatin name.
aMonitorData - The TCPIPMonitorData object
Method Detail

getSocket

public java.net.Socket getSocket()
                          throws TCPIPApplicationException,
                                 java.io.IOException
Description copied from interface: TCPIPClientApplication
Returns the underlying java.net.Socket instance which the e*Way relys on. You can perform Socket operations through the returned Socket instance. Also, you can query/change some socket options dynamically at runtime through the corresponding getters/setters of the returned Socket instance. For more details, please refer the JDK javedoc on java.net.*.

Specified by:
getSocket in interface TCPIPClientApplication
Returns:
Socket instance
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
See Also:
TCPIPClientApplication.getSocket()

isClosed

public boolean isClosed()
                 throws TCPIPApplicationException,
                        java.io.IOException
Description copied from interface: TCPIPClientApplication
Checks whether the connection is closed.

Specified by:
isClosed in interface TCPIPClientApplication
Returns:
boolean Represents the status of the connection
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
See Also:
TCPIPClientApplication.isClosed()

closeConnection

public void closeConnection()
                     throws TCPIPApplicationException,
                            java.io.IOException
Description copied from interface: TCPIPClientApplication
Closes the existing connection physically (no matter it is good or bad). Once the connection is closed, any action over this connection will be invalid and will get exception.

Specified by:
closeConnection in interface TCPIPClientApplication
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
See Also:
TCPIPClientApplication.closeConnection()

receiveBytes

public byte[] receiveBytes()
                    throws TCPIPApplicationException,
                           java.io.IOException,
                           TCPIPNoResponseException
Description copied from interface: TCPIPClientApplication
Reads all data which is available on TCP/IP connection. Returns a byte array.
 Followings are the end conditions of the read operation:
   - No more data in the socket stream (end of file)
   - Timeout occurs (note: here timeout is treated as an indication instead of error)
 
Once one of the above conditions stands, the reading attempt will gracefully stop and all data will be returned. A zero-length byte array will be returned if no any data is received.

Specified by:
receiveBytes in interface TCPIPClientApplication
Returns:
A byte array
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
TCPIPNoResponseException
See Also:
TCPIPClientApplication.receiveBytes()

receiveString

public java.lang.String receiveString()
                               throws TCPIPApplicationException,
                                      java.io.IOException,
                                      TCPIPNoResponseException
Description copied from interface: TCPIPClientApplication
Reads all data which is available on TCP/IP connection. Returns a String object with JVM default encoding.
 Followings are the end conditions of the read operation:
   - No more data in the socket stream (end of file)
   - Timeout occurs (note: here timeout is treated as an indication instead of error)
 
Once one of the above conditions stands, the reading attempt will gracefully stop and all data will be returned. An empty string "" will be returned if no any data is received.

Specified by:
receiveString in interface TCPIPClientApplication
Returns:
A String
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
TCPIPNoResponseException
See Also:
TCPIPClientApplication.receiveString()

receiveString

public java.lang.String receiveString(java.lang.String encoding)
                               throws TCPIPApplicationException,
                                      java.io.IOException,
                                      TCPIPNoResponseException
Description copied from interface: TCPIPClientApplication
Reads all data which is available on TCP/IP connection. Returns a String object with specified encoding.
 Followings are the end conditions of the read operation:
   - No more data in the socket stream (end of file)
   - Timeout occurs (note: here timeout is treated as an indication instead of error)
 
Once one of the above conditions stands, the reading attempt will gracefully stop and all data will be returned. An empty string "" will be returned if no any data is received.

Specified by:
receiveString in interface TCPIPClientApplication
Parameters:
encoding - The encoding charset name.
Returns:
A String
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
TCPIPNoResponseException
See Also:
TCPIPClientApplication.receiveString(String)

sendBytes

public void sendBytes(byte[] bytes)
               throws TCPIPApplicationException,
                      java.io.IOException
Description copied from interface: TCPIPClientApplication
Sends a byte array through the TCP/IP connection.

Specified by:
sendBytes in interface TCPIPClientApplication
Parameters:
bytes - A byte array to send
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
See Also:
TCPIPClientApplication.sendBytes(byte[])

sendString

public void sendString(java.lang.String str)
                throws TCPIPApplicationException,
                       java.io.IOException
Description copied from interface: TCPIPClientApplication
Sends a String with JVM default encoding through the TCP/IP connection.

Specified by:
sendString in interface TCPIPClientApplication
Parameters:
str - A String to send
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
See Also:
TCPIPClientApplication.sendString(String)

sendString

public void sendString(java.lang.String str,
                       java.lang.String encoding)
                throws TCPIPApplicationException,
                       java.io.IOException
Description copied from interface: TCPIPClientApplication
Sends a String with the specified encoding through the TCP/IP connection.

Specified by:
sendString in interface TCPIPClientApplication
Parameters:
str - A String to send
encoding - The encoding charset name.
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
See Also:
TCPIPClientApplication.sendString(String, String)

getTCPIPOutboundConfigInfo

public TCPIPClientConfigInfoInterface getTCPIPOutboundConfigInfo()
Description copied from interface: TCPIPClientApplication
Returns an object which represents the base TCP/IP Outbound configuration information.

Specified by:
getTCPIPOutboundConfigInfo in interface TCPIPClientApplication
Returns:
TCPIPClientConfigInfo object
See Also:
TCPIPClientApplication.getTCPIPOutboundConfigInfo()

setTCPIPOutboundConfigInfo

public void setTCPIPOutboundConfigInfo(TCPIPClientConfigInfo outboundConfigInfo)
Parameters:
outboundConfigInfo -

getClientGeneralInfo

public TCPIPClientGeneralInfo getClientGeneralInfo()
Returns the TCPIPClientGeneralInfo instance.

Returns:
TCPIPClientGeneralInfo instance

setClientGeneralInfo

public void setClientGeneralInfo(TCPIPClientGeneralInfo clientGeneralInfo)
Parameters:
clientGeneralInfo - TCPIPClientGeneralInfo to be set

getSocketInfo

public TCPIPSocketInfo getSocketInfo()
Returns the TCPIPSocketInfo instance.

Returns:
TCPIPSocketInfo instance

setSocketInfo

public void setSocketInfo(TCPIPSocketInfo socketInfo)
Method setSocketInfo.

Parameters:
socketInfo - TCPIPSocketInfo to be set

getMaxDataSize

public int getMaxDataSize()
Description copied from interface: TCPIPClientApplication
Returns the maxDataSize. This size defines the max size of data which the programs can hold internally. The valid range is from 1 to 2GB (the max value of java integer).

Specified by:
getMaxDataSize in interface TCPIPClientApplication
Returns:
The max size of data that can be held.
See Also:
TCPIPClientApplication.getMaxDataSize()

setMaxDataSize

public void setMaxDataSize(int maxDataSize)
                    throws TCPIPApplicationException
Description copied from interface: TCPIPClientApplication
Sets the maxDataSize. This size defines the max size of data which the programs can hold internally. The valid range is from 1 to 2GB (the max value of java integer).

Specified by:
setMaxDataSize in interface TCPIPClientApplication
Parameters:
maxDataSize - The maxDataSize to set
Throws:
TCPIPApplicationException - on error
See Also:
TCPIPClientApplication.setMaxDataSize(int)

getTimeToWaitForAResponse

protected int getTimeToWaitForAResponse()
Returns:

getMaxEmptyReadRetry

protected long getMaxEmptyReadRetry()
Returns:

readFully

protected byte[] readFully()
                    throws TCPIPApplicationException,
                           java.io.IOException,
                           TCPIPNoResponseException
Read until no more data (end of file) or timeout occurs. A zero-length byte array will be returned if no any data is received.

Returns:
A byte array.
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
TCPIPNoResponseException

readFully

protected byte[] readFully(boolean endOnTimeout)
                    throws TCPIPApplicationException,
                           java.io.IOException,
                           TCPIPNoResponseException
Read until no more data (end of file), or timeout occurs (if the parameter endOnTimeout is true). Note: If parameter endOnTimeout is false, it will continue to read even timeout happens, so the reading will end on condition of "no more data (EOF)"; otherwise, timeout may end the read gracefully. In either case, this method won't throw exception on timeout which is treated as an indication instead of error. A zero-length byte array will be returned if no any data is received.

Parameters:
endOnTimeout - true or false
Returns:
A byte array.
Throws:
TCPIPApplicationException - on error
java.io.IOException - on i/o error
TCPIPNoResponseException

checkIfClosed

protected void checkIfClosed()
                      throws TCPIPApplicationException
Checks whether the application connection was closed. If closed then an TCPIPApplicationException is thrown.

Throws:
TCPIPApplicationException - if the Application Connection associated with this application was already closed.

getApplicationConnection

public TCPIPApplicationConnection getApplicationConnection()
Gets the TCPIP application connection which created this instance of TCPIPClientApplication.

Returns:
TCPIPApplicationConnection instance.

setApplicationConnection

public void setApplicationConnection(TCPIPApplicationConnection appConn)
Sets the TCPIP application connection.


getResourceAdapter

public javax.resource.spi.ResourceAdapter getResourceAdapter()
Method getResourceAdapter.

Returns:
ResourceAdapter

getStateHandler

public StateHandler getStateHandler()
                             throws TCPIPApplicationException
Returns the stateHandler.

Returns:
StateHandler
Throws:
TCPIPApplicationException - up on error

getState

public java.lang.String getState()
                          throws TCPIPApplicationException
Description copied from interface: TCPIPClientApplication
Returns the State which is set by user. User can use this state to keep track the progress of the business rules. This state has same life cycle as the resource adapter, that is, it is attached with the resource adapter. Once you set the state, its value will be kept during the whole life cycle of the resource adapter.

Specified by:
getState in interface TCPIPClientApplication
Returns:
The state value.
Throws:
TCPIPApplicationException - on error
See Also:
TCPIPClientApplication.getState()

setState

public void setState(java.lang.String stateValue)
              throws TCPIPApplicationException
Description copied from interface: TCPIPClientApplication
Sets State. User can use this state to keep track the progress of the business rules. This state has same life cycle as the resource adapter, that is, it is attached with the resource adapter. Once you set the state, its value will be kept during the whole life cycle of the resource adapter.

Specified by:
setState in interface TCPIPClientApplication
Parameters:
stateValue - The state value to set
Throws:
TCPIPApplicationException - on error
See Also:
com.stc.connector.appconn.tcpip.model.TCPIPClientApplication#setState()

getApplicationName

public java.lang.String getApplicationName()
See Also:
com.stc.connector.appconn.tcpip.model.TCPIPClientApplication#getApplicationName()

setApplicationName

public void setApplicationName(java.lang.String name)
See Also:
com.stc.connector.appconn.tcpip.model.TCPIPClientApplication#setApplicationName(String)

isCalledByInbound

public boolean isCalledByInbound()
Returns the calledByInbound.

Returns:
boolean

setCalledByInbound

protected void setCalledByInbound(boolean calledByInbound)
Sets the calledByInbound.

Parameters:
calledByInbound - The calledByInbound to set

getCallingAdapter

public java.lang.String getCallingAdapter()
Returns the callingAdapter.

Returns:
String

setCallingAdapter

protected void setCallingAdapter(java.lang.String callingAdapter)
Sets the callingAdapter.

Parameters:
callingAdapter - The callingAdapter to set

isServerCloseNotification

public boolean isServerCloseNotification(java.lang.String closeCommand)
                                  throws TCPIPApplicationException
Returns true if the data which the server receives represents the close notification.

Parameters:
closeCommand -
Returns:
Throws:
TCPIPApplicationException

isServerCloseNotification

public boolean isServerCloseNotification(byte[] closeCommand)
                                  throws TCPIPApplicationException
Returns true if the data which the server receives represents the close notification.

Parameters:
closeCommand -
Returns:
Throws:
TCPIPApplicationException

isServerIdleTimeout

public boolean isServerIdleTimeout()
                            throws TCPIPApplicationException
Returns true if the server detects that the client has no actual activity (idle) for certain time.

Returns:
Throws:
TCPIPApplicationException

getLeftOverFromLastRead

public byte[] getLeftOverFromLastRead()
Returns:

setLeftOverFromLastRead

public void setLeftOverFromLastRead(byte[] bs)
Parameters:
bs -

updateMBeanProperty

public void updateMBeanProperty(java.lang.String propertyName,
                                java.lang.String propertyDisplayValue)
Updates certain RA MBean property with the specified value.

Parameters:
propertyName -
propertyDisplayValue -

getMonitor

public com.stc.connector.management.util.ObjectReference getMonitor()
Returns:
EwayConnection's Monitor

Sun Adapter for TCP/IP HL7