public class FragmentConnector extends java.lang.Object implements IPacketConnector, IListener
EVENT_PACKET_CLOSED, EVENT_PACKET_RECEIVED
Constructor and Description |
---|
FragmentConnector(IPacketConnector connector)
Creates a new fragment connector that uses the specified
connector to send packets.
|
FragmentConnector(IPacketConnector connector,
long timeout)
Creates a new fragmenting packet connector that is capable
of sending larger packets than the underlying connector.
|
Modifier and Type | Method and Description |
---|---|
void |
addPacketListener(int type,
IListener listener)
Adds a packet listener for the specified events.
|
IPacket |
createPacket()
Creates and returns a new packet for this connector.
|
int |
getPacketLength()
Returns the packet length that is supported by the connector.
|
IPlugin |
getPlugin()
Returns the plug-in of the underlying connector.
|
void |
handleEvent(Event event)
Called whenever the underlying connector is signaling
a change.
|
void |
release()
Releases the underlying packet connector.
|
boolean |
removePacketListener(int type,
IListener listener)
Removes a packet listener for the specified events.
|
void |
sendPacket(IPacket packet)
Sends a packet and throws an exception if the packet
cannot be sent or if the connector has been closed already.
|
public FragmentConnector(IPacketConnector connector)
connector
- The connector used to send packets.java.lang.NullPointerException
- Thrown if the connector is
null.public FragmentConnector(IPacketConnector connector, long timeout)
connector
- The packet connector that is used to
send and receive data.timeout
- The maximum interval that lies between
two fragments. This value can be used to cleanup the
buffer of the fragment connector.java.lang.NullPointerException
- Thrown if the connector is
null.public void addPacketListener(int type, IListener listener)
addPacketListener
in interface IPacketConnector
type
- The type of events.listener
- The listener to add.public boolean removePacketListener(int type, IListener listener)
removePacketListener
in interface IPacketConnector
type
- The type of events.listener
- The listener to remove.public IPacket createPacket() throws java.io.IOException
createPacket
in interface IPacketConnector
java.io.IOException
- Thrown if the connector has been closed.public int getPacketLength()
getPacketLength
in interface IPacketConnector
public IPlugin getPlugin()
getPlugin
in interface IConnector
public void handleEvent(Event event)
handleEvent
in interface IListener
event
- The event to deal with.public void release()
release
in interface IConnector
public void sendPacket(IPacket packet) throws java.io.IOException
sendPacket
in interface IPacketConnector
packet
- The packet to send.java.io.IOException
- Thrown by the underlying connector.