java.lang.Object
net.i2p.router.transport.FIFOBandwidthLimiter.SimpleRequest
- All Implemented Interfaces:
FIFOBandwidthLimiter.Request, PQEntry
- Enclosing class:
FIFOBandwidthLimiter
private static class FIFOBandwidthLimiter.SimpleRequestextends Object implements FIFOBandwidthLimiter.Request
One bandwidth capacity request.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue if the requester gave up.private intCapacity granted so far.private intGrants made since the request last waited.private ObjectCaller's object stored with the request.Listener notified when the request completes.private intPriority of the request.private longUnique id of the request.private longWhen the request was made.private intCapacity requested in total.private booleanTrue if the request has ever waited.(package private) final List<FIFOBandwidthLimiter.Request> Requests satisfied in the same pass.Constructor Summary
ConstructorsConstructorDescriptionSimpleRequest(int bytes, int priority) Allocation request for the given byte count.Method Summary
Modifier and TypeMethodDescriptionvoidabort()Abort the request; the connection no longer wants the data.(package private) voidallocateBytes(int bytes) Increments allocationsSinceWait only if there is a listener.voidAttach an arbitrary object to this request.The attached object, or null.booleanWhether this request has been aborted.(package private) intOnly returns nonzero if there's no listener andwaitForNextAllocation()has been called (i.e.The listener notified when the request completes.intThe number of requested bytes not yet allocated.intThe request priority, as required by the PQEntry interface.longUses System clock, not context clock.longNeeded to ensure FIFO ordering within a single priority.intThe total number of bytes requested.private booleanChecks whether the request got all its capacity.(package private) voidCounts one grant since the last wait.voidreset(int bytes, int priority) Reinitialize this request for a new allocation by the same consumer.voidOnly used by NTCP.voidsetSeqNum(long num) Sequence number assigned to this request.toString()The string representation of the request.voidOnly used by SSU.
Field Details
_allocated
private int _allocatedCapacity granted so far._total
private int _totalCapacity requested in total._requestId
private long _requestIdUnique id of the request._requestTime
private long _requestTimeWhen the request was made._allocationsSinceWait
private int _allocationsSinceWaitGrants made since the request last waited._aborted
private volatile boolean _abortedTrue if the requester gave up._waited
private boolean _waitedTrue if the request has ever waited.satisfiedBuffer
Requests satisfied in the same pass._lsnr
Listener notified when the request completes._attachment
Caller's object stored with the request._priority
private int _priorityPriority of the request.
Constructor Details
SimpleRequest
public SimpleRequest(int bytes, int priority) Allocation request for the given byte count.- Parameters:
bytes- bytes of capacity wantedpriority- 0 for now
Method Details
reset
public void reset(int bytes, int priority) Reinitialize this request for a new allocation by the same consumer. Only called when the request is complete (fully allocated) and no longer in the pending queue; aborted requests are never reset.- Parameters:
bytes- the byte countpriority- 0 for now
getRequestTime
public long getRequestTime()Uses System clock, not context clock.- Specified by:
getRequestTimein interfaceFIFOBandwidthLimiter.Request- Returns:
- the creation time in milliseconds from the System clock
getTotalRequested
public int getTotalRequested()The total number of bytes requested.- Specified by:
getTotalRequestedin interfaceFIFOBandwidthLimiter.Request- Returns:
- the total requested
getPendingRequested
public int getPendingRequested()The number of requested bytes not yet allocated.- Specified by:
getPendingRequestedin interfaceFIFOBandwidthLimiter.Request- Returns:
- the outstanding allocation in bytes, 0 when fully allocated
getAborted
public boolean getAborted()Whether this request has been aborted.- Specified by:
getAbortedin interfaceFIFOBandwidthLimiter.Request- Returns:
- true if
abort()was called, so no more bytes will be allocated
abort
public void abort()Abort the request; the connection no longer wants the data.- Specified by:
abortin interfaceFIFOBandwidthLimiter.Request
getCompleteListener
The listener notified when the request completes.- Specified by:
getCompleteListenerin interfaceFIFOBandwidthLimiter.Request- Returns:
- the complete listener
setCompleteListener
Only used by NTCP.- Specified by:
setCompleteListenerin interfaceFIFOBandwidthLimiter.Request- Parameters:
lsnr- notified once fully allocated; null clears any previously set listener
isComplete
private boolean isComplete()Checks whether the request got all its capacity.- Returns:
- true if fully allocated
waitForNextAllocation
public void waitForNextAllocation()Only used by SSU. May return without allocating. CheckgetPendingRequested()> 0 in a loop.- Specified by:
waitForNextAllocationin interfaceFIFOBandwidthLimiter.Request
getAllocationsSinceWait
int getAllocationsSinceWait()Only returns nonzero if there's no listener andwaitForNextAllocation()has been called (i.e. SSU) Now unused.- Returns:
- grants since the last wait, zero if there is a listener
allocateBytes
void allocateBytes(int bytes) Increments allocationsSinceWait only if there is a listener. Does not notify; caller must call notifyAllocation().- Parameters:
bytes- bytes of capacity granted
notifyAllocation
void notifyAllocation()Counts one grant since the last wait.attach
Attach an arbitrary object to this request.- Specified by:
attachin interfaceFIFOBandwidthLimiter.Request- Parameters:
obj- the caller's own state, returned byFIFOBandwidthLimiter.Request.attachment()
attachment
The attached object, or null.- Specified by:
attachmentin interfaceFIFOBandwidthLimiter.Request- Returns:
- the object passed to
FIFOBandwidthLimiter.Request.attach(Object), or null if none was attached
getPriority
public int getPriority()The request priority, as required by the PQEntry interface.- Specified by:
getPriorityin interfacePQEntry- Returns:
- the priority passed to the request constructor
setSeqNum
getSeqNum
toString