public final class FragmentReceiver
extends java.lang.Object
com.captainalm.lib.calmnet.packet.fragment
.Constructor and Description |
---|
FragmentReceiver(PacketLoader loader,
IPacketFactory factory)
Constructs a new FragmentReceiver with the specified
PacketLoader and IPacketFactory . |
Modifier and Type | Method and Description |
---|---|
boolean |
areFinishedIDsWaiting()
Gets whether finished IDs are waiting for obtaining.
|
boolean |
arePacketsWaiting()
Gets whether packets are waiting to be received.
|
void |
clearLastIDFinished()
Clears all the last finished packet IDs.
|
void |
clearRegistry()
Clears the registry (And requests the sender to stop sending).
|
void |
clearWaitingPackets()
Clears the currently waiting packets.
|
void |
deletePacketFromRegistry(int id)
Deletes a packet from the registry and requests the sender to stop sending.
|
int |
getLastIDFinished()
Gets the last finished packet ID.
|
int |
getNumberOfEmptySendsTillForcedCompleteOrResend()
Gets the number of
sendPacket() calls, that return null, to a registry entry are made before
the FragmentSendCompletePacket or FragmentRetrySendPacket packets are sent. |
IPacketFactory |
getPacketFactory()
Gets the
IPacketFactory in use. |
PacketLoader |
getPacketLoader()
Gets the
PacketLoader in use. |
java.lang.Integer |
pollLastIDFinished()
Polls the last finished packet ID.
|
IPacket |
receivePacket()
Receives a
IPacket from the FragmentReceiver. |
boolean |
receivePacket(IPacket packetIn)
Receives a
IPacket into the FragmentReceiver. |
IPacket |
receivePacketPolling()
Receives a
IPacket from the FragmentReceiver. |
IPacket[] |
sendPacket()
Sends the current
IPacket s from the FragmentReceiver. |
void |
setNumberOfEmptySendsTillForcedCompleteOrResend(int numberOfEmptySends)
Sets the number of
sendPacket() calls, that return null, to a registry entry are made before
the FragmentSendCompletePacket or FragmentRetrySendPacket packets are sent. |
void |
setPacketFactory(IPacketFactory factory)
Sets the
IPacketFactory to use. |
void |
setPacketLoader(PacketLoader loader)
Sets the
PacketLoader to use. |
void |
setResponseVerification(boolean state)
Sets whether responses should be verified.
|
void |
setSentDataWillBeAllVerified(boolean state)
Gets whether all sent fragments are verified to be equal.
|
boolean |
shouldSentDataBeAllVerified()
Gets whether all sent fragments are verified to be equal.
|
boolean |
shouldVerifyResponses()
Gets whether responses should be verified.
|
void |
stopAllDataVerificationAndCompleteReceive()
Stops data verification for all packets being received when
shouldSentDataBeAllVerified() is true. |
void |
stopDataVerificationAndCompleteReceive(int id)
Stops data verification for the specified Packet ID when
shouldSentDataBeAllVerified() is true. |
public FragmentReceiver(PacketLoader loader, IPacketFactory factory)
PacketLoader
and IPacketFactory
.loader
- The packet loader to use.factory
- The packet factory to use.java.lang.NullPointerException
- loader or factory is null.public IPacket receivePacket() throws java.lang.InterruptedException
IPacket
from the FragmentReceiver.
This method blocks until a packet can be received.java.lang.InterruptedException
- The Thread was Interrupted.public IPacket receivePacketPolling()
IPacket
from the FragmentReceiver.public IPacket[] sendPacket() throws PacketException
IPacket
s from the FragmentReceiver.PacketException
- A Packet Exception has occurred.public boolean receivePacket(IPacket packetIn) throws PacketException
IPacket
into the FragmentReceiver.packetIn
- The packet to receive.PacketException
- A Packet Exception has occurred.public boolean arePacketsWaiting()
public void clearWaitingPackets()
public void deletePacketFromRegistry(int id)
id
- The ID of the packet to remove.public void clearRegistry()
public boolean areFinishedIDsWaiting()
public int getLastIDFinished() throws java.lang.InterruptedException
java.lang.InterruptedException
- The Thread was Interrupted.public java.lang.Integer pollLastIDFinished()
public void clearLastIDFinished()
public IPacketFactory getPacketFactory()
IPacketFactory
in use.public void setPacketFactory(IPacketFactory factory)
IPacketFactory
to use.factory
- The packet factory to use.java.lang.NullPointerException
- factory is null.public PacketLoader getPacketLoader()
PacketLoader
in use.public void setPacketLoader(PacketLoader loader)
PacketLoader
to use.loader
- The packet loader to use.java.lang.NullPointerException
- loader is null.public boolean shouldVerifyResponses()
public void setResponseVerification(boolean state)
setSentDataWillBeAllVerified(boolean)
will be set to false too.state
- If responses should be verified.public boolean shouldSentDataBeAllVerified()
public void setSentDataWillBeAllVerified(boolean state)
setResponseVerification(boolean)
set to true.state
- If all sent fragments will be verified to be equal.public int getNumberOfEmptySendsTillForcedCompleteOrResend()
sendPacket()
calls, that return null, to a registry entry are made before
the FragmentSendCompletePacket
or FragmentRetrySendPacket
packets are sent.
A FragmentSendCompletePacket
is sent if completely received and a
FragmentRetrySendPacket
is sent if not completely received.
This excludes empty packets due to shouldSentDataBeAllVerified()
.public void setNumberOfEmptySendsTillForcedCompleteOrResend(int numberOfEmptySends)
sendPacket()
calls, that return null, to a registry entry are made before
the FragmentSendCompletePacket
or FragmentRetrySendPacket
packets are sent.
A FragmentSendCompletePacket
is sent if completely received and a
FragmentRetrySendPacket
is sent if not completely received.
This excludes empty packets due to shouldSentDataBeAllVerified()
.numberOfEmptySends
- The number of empty sends to allow.java.lang.IllegalArgumentException
- numberOfEmptySends is less than 1.public void stopDataVerificationAndCompleteReceive(int id)
shouldSentDataBeAllVerified()
is true.id
- The PacketID to act on.public void stopAllDataVerificationAndCompleteReceive()
shouldSentDataBeAllVerified()
is true.