Package io.roastedroot.proxywasm
Class SimpleSharedQueueHandler
- java.lang.Object
-
- io.roastedroot.proxywasm.SimpleSharedQueueHandler
-
- All Implemented Interfaces:
SharedQueueHandler
public class SimpleSharedQueueHandler extends Object implements SharedQueueHandler
A basic, in-memory implementation of theSharedQueueHandlerinterface.This handler manages shared queues entirely within the host's memory using standard Java collections. It is suitable for single-process environments or testing scenarios where queue persistence or cross-process sharing is not required.
All operations on this handler are synchronized to ensure thread safety within a single JVM.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimpleSharedQueueHandler.SharedQueueRepresents an individual shared queue managed bySimpleSharedQueueHandler.
-
Field Summary
-
Fields inherited from interface io.roastedroot.proxywasm.SharedQueueHandler
DEFAULT
-
-
Constructor Summary
Constructors Constructor Description SimpleSharedQueueHandler()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]dequeueSharedQueue(int queueId)Removes and returns the message at the front of the specified queue.io.roastedroot.proxywasm.internal.WasmResultenqueueSharedQueue(int queueId, byte[] value)Adds a message (byte array) to the end of the specified queue.SimpleSharedQueueHandler.SharedQueuegetSharedQueue(int queueId)Retrieves the internalSimpleSharedQueueHandler.SharedQueueobject associated with the given ID.intregisterSharedQueue(QueueName queueName)Registers a new shared queue with the given name or returns the ID if it already exists.intresolveSharedQueue(QueueName queueName)Finds the ID of an existing queue based on its name.
-
-
-
Method Detail
-
getSharedQueue
public SimpleSharedQueueHandler.SharedQueue getSharedQueue(int queueId)
Retrieves the internalSimpleSharedQueueHandler.SharedQueueobject associated with the given ID. This is primarily for internal use or testing/inspection.- Parameters:
queueId- The ID of the queue to retrieve.- Returns:
- The
SimpleSharedQueueHandler.SharedQueueinstance, ornullif no queue exists with that ID.
-
enqueueSharedQueue
public io.roastedroot.proxywasm.internal.WasmResult enqueueSharedQueue(int queueId, byte[] value)Adds a message (byte array) to the end of the specified queue.- Specified by:
enqueueSharedQueuein interfaceSharedQueueHandler- Parameters:
queueId- The ID of the target queue.value- The message data to enqueue.- Returns:
WasmResult.OKif successful, orWasmResult.NOT_FOUNDif the queue ID is invalid.
-
dequeueSharedQueue
public byte[] dequeueSharedQueue(int queueId) throws WasmExceptionRemoves and returns the message at the front of the specified queue.- Specified by:
dequeueSharedQueuein interfaceSharedQueueHandler- Parameters:
queueId- The ID of the target queue.- Returns:
- The dequeued message data as a byte array, or
nullif the queue is empty. - Throws:
WasmException- withWasmResult.NOT_FOUNDif the queue ID is invalid.
-
resolveSharedQueue
public int resolveSharedQueue(QueueName queueName) throws WasmException
Finds the ID of an existing queue based on its name.- Specified by:
resolveSharedQueuein interfaceSharedQueueHandler- Parameters:
queueName- TheQueueName(VM ID and name string) to look up.- Returns:
- The integer ID of the existing queue.
- Throws:
WasmException- withWasmResult.NOT_FOUNDif no queue with the specified name exists.
-
registerSharedQueue
public int registerSharedQueue(QueueName queueName) throws WasmException
Registers a new shared queue with the given name or returns the ID if it already exists. If the queue does not exist, a new unique ID is generated and associated with the name.- Specified by:
registerSharedQueuein interfaceSharedQueueHandler- Parameters:
queueName- TheQueueName(VM ID and name string) to register or resolve.- Returns:
- The integer ID of the (potentially newly created) queue.
- Throws:
WasmException- (Although not declared, could potentially occur in subclass implementations or future versions, e.g., due to resource limits. Current implementation does not throw.)
-
-