net.i2p.internal

## Class I2CPMessageQueue

- java.lang.Object
- - net.i2p.internal.I2CPMessageQueue

- All Implemented Interfaces:
    Closeable, AutoCloseable
  Direct Known Subclasses:
    I2CPMessageQueueImpl

      public abstract class I2CPMessageQueue
      extends 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().

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `I2CPMessageQueue()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` == offer(new PoisonI2CPMessage());
    `abstract boolean` | `offer(I2CPMessage msg)` Send a message, nonblocking.
    `abstract boolean` | `offer(I2CPMessage msg, long timeout)` Send a message, blocking.
    `abstract I2CPMessage` | `poll()` Receive a message, nonblocking.
    `abstract void` | `put(I2CPMessage msg)` Send a message, blocking until space is available.
    `abstract I2CPMessage` | `take()` Receive a message, blocking until one is available.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### I2CPMessageQueue

          public I2CPMessageQueue()

  - ### Method Detail

    - #### close

          public void close()

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

    - #### offer

          public abstract boolean offer(I2CPMessage msg)

      Send a message, nonblocking.
      Returns:
        success (false if no space available)

    - #### offer

          public abstract boolean offer(I2CPMessage msg,
                                        long timeout)
                                 throws InterruptedException

      Send a message, blocking.
      Parameters:
        `timeout` - how long to wait for space (ms)
      Returns:
        success (false if no space available or if timed out)
      Throws:
        `InterruptedException`

    - #### poll

          public abstract I2CPMessage poll()

      Receive a message, nonblocking. Unused for now.
      Returns:
        message or null if none available

    - #### put

          public abstract void put(I2CPMessage msg)
                            throws InterruptedException

      Send a message, blocking until space is available. Unused for now.
      Throws:
        `InterruptedException`

    - #### take

          public abstract I2CPMessage take()
                                    throws InterruptedException

      Receive a message, blocking until one is available.
      Returns:
        message
      Throws:
        `InterruptedException`