java.lang.Object
net.i2p.internal.I2CPMessageQueue
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
I2CPMessageQueueImpl
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 Summary
ConstructorsConstructorDescriptionConstructor for implementations, which configure the queue after construction.Method Summary
Modifier and TypeMethodDescriptionvoidclose()== offer(new PoisonI2CPMessage());abstract booleanoffer(I2CPMessage msg) Send a message, nonblocking.abstract booleanoffer(I2CPMessage msg, long timeout) Send a message, blocking.abstract intpending()How many messages are waiting to be received, for diagnostics.abstract I2CPMessagepoll()Receive a message, non-blocking.abstract voidput(I2CPMessage msg) Send a message, blocking until space is available.abstract intHow many more messages this queue will accept, for diagnostics.abstract I2CPMessagetake()Receive a message, blocking until one is available.
Constructor Details
I2CPMessageQueue
public I2CPMessageQueue()Constructor for implementations, which configure the queue after construction.
Method Details
offer
Send a message, nonblocking.- Parameters:
msg- the message to enqueue for the router to read- Returns:
- success (false if no space available)
offer
Send a message, blocking.- Parameters:
msg- the message to enqueue for the router to readtimeout- 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
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_VALUEwhen unbounded
put
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
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable