p2ps.imp.endpoint
Class AbstractMessageProtcol

java.lang.Object
  extended byp2ps.imp.endpoint.AbstractMessageProtcol
All Implemented Interfaces:
MessageProtocolHandler
Direct Known Subclasses:
ASCIIMessageProtocol, DefaultTCPMessageProtocol

public abstract class AbstractMessageProtcol
extends java.lang.Object
implements MessageProtocolHandler

An abstract implementation of MessageProtcolHandler. Provides default methods for packet handling.

Version:
$Revision: 295 $
Author:
Ian Wang

Constructor Summary
AbstractMessageProtcol()
           
 
Method Summary
 void addReceivePacket(byte[] packet)
          Adds a packet to the queue of received packets
 void addSendData(byte[] data, boolean block)
          Adds data to the queue of application data to be sent
abstract  java.lang.Object[] createReceiveItems(byte[] packet)
           
abstract  java.lang.Object[] createSendPackets(byte[] data)
           
 DataMessage getReceiveData()
          Retrieves the next data to be passed to the application
 byte[] getSendPacket()
          Retrieves the next packet of information to be sent via the endpoint.
 boolean isReceiveData()
           
 boolean isSendPacket()
           
 void packetError(java.io.IOException except)
          Called when an exception occured sending the packed
 void packetSent()
          Called when the packet is successfully sent, advances to the next packet in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMessageProtcol

public AbstractMessageProtcol()
Method Detail

createSendPackets

public abstract java.lang.Object[] createSendPackets(byte[] data)
Returns:
an array of send packets (object array containing byte arrays)

createReceiveItems

public abstract java.lang.Object[] createReceiveItems(byte[] packet)
Returns:
an array of receive messages (object array containing byte arrays)

addSendData

public void addSendData(byte[] data,
                        boolean block)
                 throws java.io.IOException
Adds data to the queue of application data to be sent

Specified by:
addSendData in interface MessageProtocolHandler
Parameters:
data - the application data to be send by the endpoint
Throws:
java.io.IOException

getSendPacket

public byte[] getSendPacket()
Retrieves the next packet of information to be sent via the endpoint.

Specified by:
getSendPacket in interface MessageProtocolHandler
Returns:
the bytes to be sent by the endpoint

isSendPacket

public boolean isSendPacket()
Specified by:
isSendPacket in interface MessageProtocolHandler
Returns:
true if a packet of data is ready to be sent

packetSent

public void packetSent()
Called when the packet is successfully sent, advances to the next packet in the queue.

Specified by:
packetSent in interface MessageProtocolHandler

packetError

public void packetError(java.io.IOException except)
Called when an exception occured sending the packed

Specified by:
packetError in interface MessageProtocolHandler
Parameters:
except -

addReceivePacket

public void addReceivePacket(byte[] packet)
Adds a packet to the queue of received packets

Specified by:
addReceivePacket in interface MessageProtocolHandler
Parameters:
packet - the packet received by the endpoint

getReceiveData

public DataMessage getReceiveData()
Retrieves the next data to be passed to the application

Specified by:
getReceiveData in interface MessageProtocolHandler
Returns:
the bytes to be received by the application

isReceiveData

public boolean isReceiveData()
Specified by:
isReceiveData in interface MessageProtocolHandler
Returns:
true if any data is ready to be received by the application