java.lang.Object
net.i2p.internal.I2CPMessageQueue
net.i2p.router.client.I2CPMessageQueueImpl
All Implemented Interfaces:
Closeable, AutoCloseable

class I2CPMessageQueueImplextends I2CPMessageQueue
Contains the methods to talk to a router or client via I2CP, when both are in the same JVM. This interface contains methods to access two queues, one for transmission and one for receiving. The methods are identical to those in java.util.concurrent.BlockingQueue.
  • Field Details

  • Constructor Details

    • I2CPMessageQueueImpl

      public I2CPMessageQueueImpl(BlockingQueue<I2CPMessage> in, BlockingQueue<I2CPMessage> out)
      Wrap a pair of queues as an I2CP message queue.
      Parameters:
      in - the queue messages from the client arrive on
      out - the queue messages to the client are written to
  • Method Details

    • offer

      public boolean offer(I2CPMessage msg)
      Send a message, nonblocking.
      Specified by:
      offer in class I2CPMessageQueue
      Parameters:
      msg - the message to enqueue for the router to read
      Returns:
      success (false if no space available)
    • offer

      public boolean offer(I2CPMessage msg, long timeout) throws InterruptedException
      Send a message, blocking.
      Specified by:
      offer in class I2CPMessageQueue
      Parameters:
      msg - the message to enqueue for the router to read
      timeout - how long to wait for space (ms)
      Returns:
      success (false if no space available or if timed out)
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting for space to become available
    • poll

      public I2CPMessage poll()
      Receive a message, non-blocking.
      Specified by:
      poll in class I2CPMessageQueue
      Returns:
      message or null if none available
    • pending

      public int pending()
      Messages waiting to be read by the client.
      Specified by:
      pending in class I2CPMessageQueue
      Returns:
      messages waiting to be received
    • remainingCapacity

      public int remainingCapacity()
      Slots free for messages from the client.
      Specified by:
      remainingCapacity in class I2CPMessageQueue
      Returns:
      how many more messages will be accepted; Integer.MAX_VALUE when unbounded
    • put

      public void put(I2CPMessage msg) throws InterruptedException
      Send a message, blocking until space is available.
      Specified by:
      put in class I2CPMessageQueue
      Parameters:
      msg - the message to enqueue for the router to read
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting for space to become available
    • take

      public I2CPMessage take() throws InterruptedException
      Receive a message, blocking until one is available.
      Specified by:
      take in class I2CPMessageQueue
      Returns:
      the next message removed from the inbound side of the queue
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting for a message to arrive