p2ps.endpoint
Interface MessageProtocolHandler

All Known Implementing Classes:
AbstractMessageProtcol

public interface MessageProtocolHandler

An interface implemented by classes responsible for creating messages adhering to a certain protocol for send data, and decoding these messages for received data. This could for example involve adding header information or creating a long message from multiple packets.

Version:
$Revision: 295 $
Author:
Ian Wang

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
 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.
 

Method Detail

addSendData

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

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. Either packetSent/packetError should be called to advance to the next packet.

Returns:
the bytes to be sent by the endpoint

isSendPacket

public boolean isSendPacket()
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.


packetError

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

Parameters:
except -

addReceivePacket

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

Parameters:
packet - the packet received by the endpoint

getReceiveData

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

Returns:
the bytes to be received by the application

isReceiveData

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