Class MultiPeerUploader
- java.lang.Object
-
- com.biglybt.core.networkmanager.impl.MultiPeerUploader
-
- All Implemented Interfaces:
RateControlledEntity
public class MultiPeerUploader extends java.lang.Object implements RateControlledEntity
A rate-controlled write entity backed by multiple peer connections, with an emphasis on transmitting packets with full payloads, i.e. it writes to the transport in mss-sized chunks if at all possible. It also employs fair, round-robin write scheduling, where connections each take turns writing a single full packet per round.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MultiPeerUploader.PeerData
Does this entity have data ready for writing.
-
Field Summary
Fields Modifier and Type Field Description private boolean
destroyed
private static int
FLUSH_CHECK_LOOP_TIME
private static int
FLUSH_WAIT_TIME
private long
last_flush_check_time
(package private) AEMonitor
lists_lock
private RateHandler
rate_handler
private java.util.LinkedList
ready_connections
private EventWaiter
waiter
(package private) java.util.HashMap
waiting_connections
-
Fields inherited from interface com.biglybt.core.networkmanager.impl.RateControlledEntity
PRIORITY_HIGH, PRIORITY_NORMAL
-
-
Constructor Summary
Constructors Constructor Description MultiPeerUploader(RateHandler rate_handler)
Create a new packet-filling multi-peer upload entity, rate-controlled by the given handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPeerConnection(NetworkConnectionBase peer_connection)
Add the given connection to be managed by this upload entity.(package private) void
addToReadyList(NetworkConnectionBase conn)
private void
addToWaitingList(NetworkConnectionBase conn)
boolean
canProcess(EventWaiter waiter)
Is ready for a processing op.void
destroy()
Destroy this upload entity.int
doProcessing(EventWaiter waiter, int max_bytes)
Attempt to do a processing operation.private void
flushCheck()
Checks the connections in the waiting list to see if it's time to be force-flushed.long
getBytesReadyToWrite()
int
getConnectionCount(EventWaiter _waiter)
If there are no connections then the waiter will be kicked when a connection arrivesint
getPriority()
Get this entity's priority level.boolean
getPriorityBoost()
stats functionsRateHandler
getRateHandler()
int
getReadyConnectionCount(EventWaiter waiter)
The waiter is kicked if the ready condition changesjava.lang.String
getString()
boolean
removePeerConnection(NetworkConnectionBase peer_connection)
Remove the given connection from this upload entity.private int
write(EventWaiter waiter, int num_bytes_to_write, boolean protocol_is_free)
-
-
-
Field Detail
-
FLUSH_CHECK_LOOP_TIME
private static final int FLUSH_CHECK_LOOP_TIME
- See Also:
- Constant Field Values
-
FLUSH_WAIT_TIME
private static final int FLUSH_WAIT_TIME
- See Also:
- Constant Field Values
-
last_flush_check_time
private long last_flush_check_time
-
rate_handler
private final RateHandler rate_handler
-
destroyed
private boolean destroyed
-
waiting_connections
final java.util.HashMap waiting_connections
-
ready_connections
private final java.util.LinkedList ready_connections
-
lists_lock
final AEMonitor lists_lock
-
waiter
private volatile EventWaiter waiter
-
-
Constructor Detail
-
MultiPeerUploader
public MultiPeerUploader(RateHandler rate_handler)
Create a new packet-filling multi-peer upload entity, rate-controlled by the given handler.- Parameters:
rate_handler
- listener to handle upload rate limits
-
-
Method Detail
-
getRateHandler
public RateHandler getRateHandler()
- Specified by:
getRateHandler
in interfaceRateControlledEntity
-
flushCheck
private void flushCheck()
Checks the connections in the waiting list to see if it's time to be force-flushed.
-
destroy
public void destroy()
Destroy this upload entity. Note: Removes all peer connections in the process.
-
addPeerConnection
public void addPeerConnection(NetworkConnectionBase peer_connection)
Add the given connection to be managed by this upload entity.- Parameters:
peer_connection
- to be write managed
-
removePeerConnection
public boolean removePeerConnection(NetworkConnectionBase peer_connection)
Remove the given connection from this upload entity.- Parameters:
peer_connection
- to be removed- Returns:
- true if the connection was found and removed, false if not removed
-
addToWaitingList
private void addToWaitingList(NetworkConnectionBase conn)
-
addToReadyList
void addToReadyList(NetworkConnectionBase conn)
-
write
private int write(EventWaiter waiter, int num_bytes_to_write, boolean protocol_is_free)
-
getBytesReadyToWrite
public long getBytesReadyToWrite()
- Specified by:
getBytesReadyToWrite
in interfaceRateControlledEntity
-
getConnectionCount
public int getConnectionCount(EventWaiter _waiter)
Description copied from interface:RateControlledEntity
If there are no connections then the waiter will be kicked when a connection arrives- Specified by:
getConnectionCount
in interfaceRateControlledEntity
- Returns:
-
getReadyConnectionCount
public int getReadyConnectionCount(EventWaiter waiter)
Description copied from interface:RateControlledEntity
The waiter is kicked if the ready condition changes- Specified by:
getReadyConnectionCount
in interfaceRateControlledEntity
- Returns:
-
canProcess
public boolean canProcess(EventWaiter waiter)
Description copied from interface:RateControlledEntity
Is ready for a processing op.- Specified by:
canProcess
in interfaceRateControlledEntity
- Returns:
- true if it can process >0 bytes, false if not ready
-
doProcessing
public int doProcessing(EventWaiter waiter, int max_bytes)
Description copied from interface:RateControlledEntity
Attempt to do a processing operation.- Specified by:
doProcessing
in interfaceRateControlledEntity
- Returns:
- true if >0 bytes were processed (success), false if 0 bytes were processed (failure)
-
getPriority
public int getPriority()
Description copied from interface:RateControlledEntity
Get this entity's priority level.- Specified by:
getPriority
in interfaceRateControlledEntity
- Returns:
- priority
-
getPriorityBoost
public boolean getPriorityBoost()
Description copied from interface:RateControlledEntity
stats functions- Specified by:
getPriorityBoost
in interfaceRateControlledEntity
- Returns:
-
getString
public java.lang.String getString()
- Specified by:
getString
in interfaceRateControlledEntity
-
-