The Packet Assembly/Disassembly Protocol Handler class.
This class provides the black-box for handling PADP packets.
ACK_TIMEOUT
public static long ACK_TIMEOUT
The default packet acknowledgement timeout.
If a sent packet isn't acknowledged via an ACK packet within this time,
an attampt will be made to resend it.
DEFAULT_QUEUE_LENGTH
public static final int DEFAULT_QUEUE_LENGTH
The default queue length.
IP_TIMEOUT
public static long IP_TIMEOUT
The default inter-packet timeout.
If no packets are received within this time, the connection is assumed to have been lost.
To prevent the other end from timing out, use tickle packets.
STATE_CONNECTED
public static final int STATE_CONNECTED
The connected state value.
STATE_DISCONNECTED
public static final int STATE_DISCONNECTED
The disconnected state value.
STATE_SUSPENDED
public static final int STATE_SUSPENDED
The suspended state value.
connect
public void connect()
Connects to the underlying protocol stack to start a communication session,
if we're not already connected.
Initially, we'll be put into "suspended" mode, until a connection is
initialized from the remote end.
- connect in interface CMPDLPTransferInterface
enableDebugMode
public void enableDebugMode()
Enable packet debug mode.
handleACK
protected void handleACK(PADP_Packet pkt)
Handle an ACKnowledgement packet received from the remote end.
pkt - the packet that was received.
handleAbort
protected void handleAbort(PADP_Packet pkt)
Handle an abort packet received from the remote end.
pkt - the packet that was received.
handleData
protected void handleData(PADP_Packet pkt)
Handle a data packet received from the remote end.
pkt - the packet that was received.
handleNACK
protected void handleNACK(PADP_Packet pkt)
Handle a Negative ACKnowledgement packet received from the remote end.
Note that NACK packets are no longer supported by the HotSync protocol.
Thus, we don't actually process this packet type.
pkt - the packet that was received.
handleTickle
protected void handleTickle(PADP_Packet pkt)
Handle a tickle packet received from the remote end.
pkt - the packet that was received.
incTransID
protected byte incTransID()
Increments the transaction ID.
Note that the transaction ID wraps. If we hit 0xFE, we wrap back to 0x01.
isConnected
public boolean isConnected()
Checks to see if this protocol is currently connected.
- isConnected in interface CMPDLPTransferInterface
- true if we're in STATE_SUSPENDED or STATE_CONNECTED, false otherwise.
parsePADPacket
protected PADP_Packet parsePADPacket(GenericPacket data)
Converts an incoming GenericData packet into a PAD_Packet instance.
data - the incoming GenericPacket.
- the PADP_Packet object representing the data from the GenericPacket object.
processPacket
protected void processPacket(PADP_Packet pkt)
Processes an incoming packet.
pkt - the incoming packet to be processed.
run
public void run()
Runs the input queue thread.
selfDisconnect
protected void selfDisconnect()
An internal method for handling disconnects that are caused by inter-packet timeouts
or by a retry overrun.
sendAck
protected void sendAck(PADP_Packet pkt)
Send an ACKnowledgement packet for a received packet.
pkt - the packet that we wish to acknowledge.
sendPacket
protected void sendPacket(PADP_Packet pkt)
throws NotConnectedExceptionSends a packet to the underlying SLP protocol handler.
pkt - the packet object to send.
sendTickle
protected void sendTickle()
Sends a tickle packet.
setDebugOutputStream
public void setDebugOutputStream(PrintStream stream)
Sets the print stream that debug packet data should be sent to, if enabled.
stream - the PrintStream object to use for debug data output.
startTickles
public void startTickles()
Start the tickle packet sending process.
stopTickles
public void stopTickles()
Stop the tickle packet sending process.
suspendConnection
public void suspendConnection()
Suspend the connection.
Suspending the connection causes the protocol stack to disconnect from the remote end,
but allows it to remain an active listener for new incoming connections.
- suspendConnection in interface CMPDLPTransferInterface
timerExpired
public void timerExpired(PacketTimer packettimer)
A timer expirey handler.
This method is called by a PacketTimer if it expires.
- timerExpired in interface PacketTimerInterface
packettimer - the timer object that expired.
transmitPacket
public void transmitPacket(data[] ,
byte hostSocket,
byte serverSocket)
throws NotConnectedException,
PADP_PacketTooBigExceptionTransmit a packet to the underlying SLP protocol layer.
Calls to this method causes the data to be fragmented (if required) and transmitted via PADP.
hostSocket - the host socket the data is being sent from.serverSocket - the server socket to send this data to.
transmitPacket
protected void transmitPacket(data[] ,
byte hostSocket,
byte serverSocket,
boolean flag)
throws NotConnectedException,
PADP_PacketTooBigExceptionTransmit a packet to the underlying SLP protocol layer.
Calls to this method causes the data to be fragmented (if required) and transmitted via PADP.
hostSocket - the host socket the data is being sent from.serverSocket - the server socket to send this data to.flag - true if this is the first packet, false otherwise.
transmitPacket
public void transmitPacket(GenericPacket pkt)
throws NotConnectedException,
PADP_PacketTooBigExceptionTransmit a packet to the underlying SLP protocol layer.
Calls to this method causes the data to be fragmented (if required) and transmitted via PADP.
pkt - the packet of data to be wrapped in a PADP packet (or packets) and transmitted.
useLongPackets
public void useLongPackets(boolean flag)
Sets the use of long packets.
- useLongPackets in interface CMPDLPTransferInterface
flag - true if we should use long packet support, false otherwise.