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 Details

    • _allocated

      private int _allocated
      Capacity granted so far.
    • _total

      private int _total
      Capacity requested in total.
    • _requestId

      private long _requestId
      Unique id of the request.
    • _requestTime

      private long _requestTime
      When the request was made.
    • _allocationsSinceWait

      private int _allocationsSinceWait
      Grants made since the request last waited.
    • _aborted

      private volatile boolean _aborted
      True if the requester gave up.
    • _waited

      private boolean _waited
      True if the request has ever waited.
    • satisfiedBuffer

      final List<FIFOBandwidthLimiter.Request> satisfiedBuffer
      Requests satisfied in the same pass.
    • _lsnr

      Listener notified when the request completes.
    • _attachment

      private Object _attachment
      Caller's object stored with the request.
    • _priority

      private int _priority
      Priority of the request.
  • Constructor Details

    • SimpleRequest

      public SimpleRequest(int bytes, int priority)
      Allocation request for the given byte count.
      Parameters:
      bytes - bytes of capacity wanted
      priority - 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 count
      priority - 0 for now
    • getRequestTime

      public long getRequestTime()
      Uses System clock, not context clock.
      Specified by:
      getRequestTime in interface FIFOBandwidthLimiter.Request
      Returns:
      the creation time in milliseconds from the System clock
    • getTotalRequested

      public int getTotalRequested()
      The total number of bytes requested.
      Specified by:
      getTotalRequested in interface FIFOBandwidthLimiter.Request
      Returns:
      the total requested
    • getPendingRequested

      public int getPendingRequested()
      The number of requested bytes not yet allocated.
      Specified by:
      getPendingRequested in interface FIFOBandwidthLimiter.Request
      Returns:
      the outstanding allocation in bytes, 0 when fully allocated
    • getAborted

      public boolean getAborted()
      Whether this request has been aborted.
      Specified by:
      getAborted in interface FIFOBandwidthLimiter.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:
      abort in interface FIFOBandwidthLimiter.Request
    • getCompleteListener

      public FIFOBandwidthLimiter.CompleteListener getCompleteListener()
      The listener notified when the request completes.
      Specified by:
      getCompleteListener in interface FIFOBandwidthLimiter.Request
      Returns:
      the complete listener
    • setCompleteListener

      public void setCompleteListener(FIFOBandwidthLimiter.CompleteListener lsnr)
      Only used by NTCP.
      Specified by:
      setCompleteListener in interface FIFOBandwidthLimiter.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. Check getPendingRequested() > 0 in a loop.
      Specified by:
      waitForNextAllocation in interface FIFOBandwidthLimiter.Request
    • getAllocationsSinceWait

      int getAllocationsSinceWait()
      Only returns nonzero if there's no listener and waitForNextAllocation() 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

      public void attach(Object obj)
      Attach an arbitrary object to this request.
      Specified by:
      attach in interface FIFOBandwidthLimiter.Request
      Parameters:
      obj - the caller's own state, returned by FIFOBandwidthLimiter.Request.attachment()
    • attachment

      public Object attachment()
      The attached object, or null.
      Specified by:
      attachment in interface FIFOBandwidthLimiter.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:
      getPriority in interface PQEntry
      Returns:
      the priority passed to the request constructor
    • setSeqNum

      public void setSeqNum(long num)
      Sequence number assigned to this request. Currently a no-op - the assignment is commented out, uncomment it when switching to PBQ.
      Specified by:
      setSeqNum in interface PQEntry
      Parameters:
      num - the sequence number
    • getSeqNum

      public long getSeqNum()
      Description copied from interface: PQEntry
      Needed to ensure FIFO ordering within a single priority.
      Specified by:
      getSeqNum in interface PQEntry
      Returns:
      the sequence number
    • toString

      public String toString()
      The string representation of the request.
      Overrides:
      toString in class Object