org.opengts.util
Class AbstractClientPacketHandler

java.lang.Object
  extended by org.opengts.util.AbstractClientPacketHandler
All Implemented Interfaces:
ClientPacketHandler
Direct Known Subclasses:
CommandPacketHandler, RemoteLogServer.RemoteLogHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler, TrackClientPacketHandler

public abstract class AbstractClientPacketHandler
extends java.lang.Object
implements ClientPacketHandler

An abstract implementation of the ClientPacketHandler interface


Field Summary
static java.util.TimeZone GMT_Timezone
           
static int PACKET_LEN_END_OF_STREAM
           
static int PACKET_LEN_LINE_TERMINATOR
           
 
Constructor Summary
AbstractClientPacketHandler(java.lang.String name)
           
 
Method Summary
 void clearSavedEventCount()
          Clears the event count state
 void clearTerminateSession()
          Clears the terminate-session state to false
 boolean equals(java.lang.Object other)
           
 boolean equalsSessionID(java.lang.String sessionID)
          Returns true if the specified session ID matches the current session ID
 void forceCloseTCPSession()
          Sets the terminate-session state to the specified value
 int getActualPacketLength(byte[] packet, int packetLen)
          Callback to obtain the length of the next packet, based on the provided partial packet data.
static boolean GetDebugMode()
          Gets the global debug mode
 byte[] getFinalPacket(boolean hasError)
          Returns the final packet that should be sent to the device before closing the socket connection.
abstract  byte[] getHandlePacket(byte[] cmd)
          Parse the provided packet information, and return any response that should be sent back to the remote device
 java.lang.String getHostAddress()
          Gets the IP adress of the remote host
 java.net.InetAddress getInetAddress()
          Gets the IP adress of the remote host
 byte[] getInitialPacket()
          Returns the initial packet that should be sent to the device upon openning the socket connection .
 java.lang.String getIPAddress()
          Gets the IP adress of the remote host
 int getLocalPort()
          Gets the local port to which this socket is bound
 int getMaximumPacketLength()
          Returns the maximum packet length
 int getMinimumPacketLength()
          Returns the minimum packet length
 java.lang.String getName()
           
 boolean getPromptEnabled()
          Gets the prompt enabled state
 int getRemotePort()
          Gets the remote/client port used by the client to send the received packet
 int getResponsePort()
          Returns the client response port#
 int getSavedEventCount()
          Gets the current value of the event count state
 long getSequenceID()
           
protected  java.lang.String getSessionID()
          Returns the session ID (override only)
 ServerSocketThread.SessionInfo getSessionInfo()
          Gets a reference to the ClientPacketHandler's session info implementation
 long getSessionStartTime()
          Returns the session start time (seconds)
 long getSessionStartTimeMS()
          Returns the session start time (milliseconds)
 java.lang.String getSessionType()
          Gets the current session type name (ie.
 boolean getTerminateSession()
          Callback to determine if the current session should be terminated
 java.lang.String getThreadName()
          Returns name of the thread handling this client session
 boolean hasHostAddress()
          Returns true if a remote host address is available
 boolean hasIPAddress()
          Returns true if a remote host address is available
 boolean hasSavedEvents()
          Returns true if the current value of the event count state is greater-than zero
 void idleTimeoutInterrupt()
          Callback: timeout interrupt Called periodically during an idle read.
 void incrementSavedEventCount()
          Increments the event count state
static boolean IsDebugMode()
          Gets the global debug mode
 boolean isDuplex()
          Returns true if this session is duplex (ie TCP)
 boolean isInputStream()
          Returns true if this session is InputStream
 boolean isTCP()
          Returns true if this session is TCP
protected  boolean isTextPackets()
          Returns true if the packets are text
 boolean isUDP()
          Returns true if this session is UDP
protected  void printSessionStart()
          Displays the sesion startup message.
protected  void printSessionTerminated(long deltaMS)
          Displays the sesion startup message.
 void sessionStarted(java.net.InetAddress inetAddr, boolean isDuplex, boolean isText)
          Called when the session has started
 void sessionTerminated(java.lang.Throwable err, long readCount, long writeCount)
          Callback just before the session is terminated
static void SetDebugMode(boolean debug)
          Sets the global debug mode
 void setPromptEnabled(boolean enable)
          Sets the prompt enabled state
 void setSavedEventCount(int count)
          Sets the event count state to the specified value
 void setSessionInfo(ServerSocketThread.SessionInfo sessionInfo)
          Sets the session info handler
 void setTerminateSession()
          Sets the terminate-session state to true
 void setTerminateSession(boolean term)
          Sets the terminate-session state to the specified value
 boolean tcpWrite(byte[] data)
          Write bytes to TCP output stream
 boolean terminateSession()
          Callback to determine if the current session should be terminated
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKET_LEN_LINE_TERMINATOR

public static final int PACKET_LEN_LINE_TERMINATOR
See Also:
Constant Field Values

PACKET_LEN_END_OF_STREAM

public static final int PACKET_LEN_END_OF_STREAM
See Also:
Constant Field Values

GMT_Timezone

public static final java.util.TimeZone GMT_Timezone
Constructor Detail

AbstractClientPacketHandler

public AbstractClientPacketHandler(java.lang.String name)
Method Detail

SetDebugMode

public static void SetDebugMode(boolean debug)
Sets the global debug mode


GetDebugMode

public static boolean GetDebugMode()
Gets the global debug mode


IsDebugMode

public static boolean IsDebugMode()
Gets the global debug mode


getName

public java.lang.String getName()

getSequenceID

public long getSequenceID()

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

setSessionInfo

public void setSessionInfo(ServerSocketThread.SessionInfo sessionInfo)
Sets the session info handler

Specified by:
setSessionInfo in interface ClientPacketHandler
Parameters:
sessionInfo - An implementation of the ServerSocketThread.SessionInfo interface

getSessionInfo

public ServerSocketThread.SessionInfo getSessionInfo()
Gets a reference to the ClientPacketHandler's session info implementation

Specified by:
getSessionInfo in interface ClientPacketHandler
Returns:
Reference to the session info object

getThreadName

public java.lang.String getThreadName()
Returns name of the thread handling this client session

Returns:
The name of the thread handling this client session

getLocalPort

public int getLocalPort()
Gets the local port to which this socket is bound

Returns:
The local port to which this socket is bound

getRemotePort

public int getRemotePort()
Gets the remote/client port used by the client to send the received packet

Returns:
The client remote port

setPromptEnabled

public void setPromptEnabled(boolean enable)
Sets the prompt enabled state

Specified by:
setPromptEnabled in interface ClientPacketHandler
Parameters:
enable - True to enable prompt, false to disable

getPromptEnabled

public boolean getPromptEnabled()
Gets the prompt enabled state

Specified by:
getPromptEnabled in interface ClientPacketHandler
Returns:
True to enable prompt, false to disable

tcpWrite

public boolean tcpWrite(byte[] data)
Write bytes to TCP output stream

Specified by:
tcpWrite in interface ClientPacketHandler
Parameters:
data - The data bytes to write
Returns:
True if bytes were written, false otherwise

sessionStarted

public void sessionStarted(java.net.InetAddress inetAddr,
                           boolean isDuplex,
                           boolean isText)
Called when the session has started

Specified by:
sessionStarted in interface ClientPacketHandler
Parameters:
inetAddr - The host IP address
isDuplex - True if the connection is TCP
isText - True if the connection is text

printSessionStart

protected void printSessionStart()
Displays the sesion startup message. (override to disable)


equalsSessionID

public boolean equalsSessionID(java.lang.String sessionID)
Returns true if the specified session ID matches the current session ID

Specified by:
equalsSessionID in interface ClientPacketHandler
Parameters:
sessionID - The session ID to test (specifying null should always return false)
Returns:
True if the session IDs match, false otherwise

getSessionID

protected java.lang.String getSessionID()
Returns the session ID (override only)

Returns:
The session ID

getSessionStartTimeMS

public long getSessionStartTimeMS()
Returns the session start time (milliseconds)


getSessionStartTime

public long getSessionStartTime()
Returns the session start time (seconds)


isTextPackets

protected boolean isTextPackets()
Returns true if the packets are text

Returns:
True if the packets are text

isDuplex

public boolean isDuplex()
Returns true if this session is duplex (ie TCP)


isTCP

public boolean isTCP()
Returns true if this session is TCP


isUDP

public boolean isUDP()
Returns true if this session is UDP


isInputStream

public boolean isInputStream()
Returns true if this session is InputStream


getSessionType

public java.lang.String getSessionType()
Gets the current session type name (ie. TCP, UDP)

Returns:
The current session type name

getInetAddress

public java.net.InetAddress getInetAddress()
Gets the IP adress of the remote host

Returns:
The IP adress of the remote host

getHostAddress

public java.lang.String getHostAddress()
Gets the IP adress of the remote host

Returns:
The IP adress of the remote host

hasHostAddress

public boolean hasHostAddress()
Returns true if a remote host address is available

Returns:
True if a remote host address is available

getIPAddress

public java.lang.String getIPAddress()
Gets the IP adress of the remote host

Returns:
The IP adress of the remote host

hasIPAddress

public boolean hasIPAddress()
Returns true if a remote host address is available

Returns:
True if a remote host address is available

setSavedEventCount

public void setSavedEventCount(int count)
Sets the event count state to the specified value


clearSavedEventCount

public void clearSavedEventCount()
Clears the event count state


incrementSavedEventCount

public void incrementSavedEventCount()
Increments the event count state


hasSavedEvents

public boolean hasSavedEvents()
Returns true if the current value of the event count state is greater-than zero


getSavedEventCount

public int getSavedEventCount()
Gets the current value of the event count state


getResponsePort

public int getResponsePort()
Returns the client response port#

Specified by:
getResponsePort in interface ClientPacketHandler
Returns:
The port for UDP Datafram responses

getMinimumPacketLength

public int getMinimumPacketLength()
Returns the minimum packet length

Specified by:
getMinimumPacketLength in interface ClientPacketHandler
Returns:
The minimum packet length

getMaximumPacketLength

public int getMaximumPacketLength()
Returns the maximum packet length

Specified by:
getMaximumPacketLength in interface ClientPacketHandler
Returns:
The maximum packet length

getInitialPacket

public byte[] getInitialPacket()
                        throws java.lang.Exception
Returns the initial packet that should be sent to the device upon openning the socket connection .

Specified by:
getInitialPacket in interface ClientPacketHandler
Returns:
The initial response to be sent when the session opens
Throws:
java.lang.Exception

getFinalPacket

public byte[] getFinalPacket(boolean hasError)
                      throws java.lang.Exception
Returns the final packet that should be sent to the device before closing the socket connection.

Specified by:
getFinalPacket in interface ClientPacketHandler
Returns:
the final response to be sent before the session closes
Throws:
java.lang.Exception

getActualPacketLength

public int getActualPacketLength(byte[] packet,
                                 int packetLen)
Callback to obtain the length of the next packet, based on the provided partial packet data.

Specified by:
getActualPacketLength in interface ClientPacketHandler

getHandlePacket

public abstract byte[] getHandlePacket(byte[] cmd)
                                throws java.lang.Exception
Parse the provided packet information, and return any response that should be sent back to the remote device

Specified by:
getHandlePacket in interface ClientPacketHandler
Parameters:
cmd - The packet
Returns:
The response
Throws:
java.lang.Exception

idleTimeoutInterrupt

public void idleTimeoutInterrupt()
Callback: timeout interrupt Called periodically during an idle read. The periodic timeout is based on the value specified on the call to "ServerSocketThread.setMinimuTimeoutIntervalMS"

Specified by:
idleTimeoutInterrupt in interface ClientPacketHandler

forceCloseTCPSession

public void forceCloseTCPSession()
Sets the terminate-session state to the specified value

Specified by:
forceCloseTCPSession in interface ClientPacketHandler

setTerminateSession

public void setTerminateSession(boolean term)
Sets the terminate-session state to the specified value


setTerminateSession

public void setTerminateSession()
Sets the terminate-session state to true

Specified by:
setTerminateSession in interface ClientPacketHandler

clearTerminateSession

public void clearTerminateSession()
Clears the terminate-session state to false


getTerminateSession

public boolean getTerminateSession()
Callback to determine if the current session should be terminated

Specified by:
getTerminateSession in interface ClientPacketHandler
Returns:
True if the session should terminate

terminateSession

public boolean terminateSession()
Callback to determine if the current session should be terminated

Specified by:
terminateSession in interface ClientPacketHandler

sessionTerminated

public void sessionTerminated(java.lang.Throwable err,
                              long readCount,
                              long writeCount)
Callback just before the session is terminated

Specified by:
sessionTerminated in interface ClientPacketHandler

printSessionTerminated

protected void printSessionTerminated(long deltaMS)
Displays the sesion startup message. (override to disable)