java.lang.Object
net.i2p.internal.I2CPMessageQueue
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
I2CPMessageQueueImpl

public abstract class I2CPMessageQueueextends Object implements Closeable
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.

Reading may be done in a thread using the QueuedI2CPMessageReader class. Non-blocking writing may be done directly with offer(I2CPMessage).

  • Constructor Details

    • I2CPMessageQueue

      public I2CPMessageQueue()
      Constructor for implementations, which configure the queue after construction.
  • Method Details

    • offer

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

      public abstract boolean offer(I2CPMessage msg, long timeout) throws InterruptedException
      Send a message, blocking.
      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 abstract I2CPMessage poll()
      Receive a message, non-blocking. Unused for now.
      Returns:
      message or null if none available
    • pending

      public abstract int pending()
      How many messages are waiting to be received, for diagnostics.

      A queue that stays non-empty means the client is not draining it, which is the reason offer(I2CPMessage) fails and the only explanation for a client that has stopped answering.

      Returns:
      messages waiting to be received
    • remainingCapacity

      public abstract int remainingCapacity()
      How many more messages this queue will accept, for diagnostics.
      Returns:
      remaining capacity; Integer.MAX_VALUE when unbounded
    • put

      public abstract void put(I2CPMessage msg) throws InterruptedException
      Send a message, blocking until space is available. Unused for now.
      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 abstract I2CPMessage take() throws InterruptedException
      Receive a message, blocking until one is available.
      Returns:
      the next message from the router, waiting indefinitely if none is queued
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting for a message to arrive
    • close

      public void close()
      == offer(new PoisonI2CPMessage());
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable