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 theSharedQueueHandler
interface.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 class
SimpleSharedQueueHandler.SharedQueue
Represents 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.WasmResult
enqueueSharedQueue(int queueId, byte[] value)
Adds a message (byte array) to the end of the specified queue.SimpleSharedQueueHandler.SharedQueue
getSharedQueue(int queueId)
Retrieves the internalSimpleSharedQueueHandler.SharedQueue
object associated with the given ID.int
registerSharedQueue(QueueName queueName)
Registers a new shared queue with the given name or returns the ID if it already exists.int
resolveSharedQueue(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.SharedQueue
object 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.SharedQueue
instance, ornull
if 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:
enqueueSharedQueue
in interfaceSharedQueueHandler
- Parameters:
queueId
- The ID of the target queue.value
- The message data to enqueue.- Returns:
WasmResult.OK
if successful, orWasmResult.NOT_FOUND
if the queue ID is invalid.
-
dequeueSharedQueue
public byte[] dequeueSharedQueue(int queueId) throws WasmException
Removes and returns the message at the front of the specified queue.- Specified by:
dequeueSharedQueue
in interfaceSharedQueueHandler
- Parameters:
queueId
- The ID of the target queue.- Returns:
- The dequeued message data as a byte array, or
null
if the queue is empty. - Throws:
WasmException
- withWasmResult.NOT_FOUND
if 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:
resolveSharedQueue
in interfaceSharedQueueHandler
- Parameters:
queueName
- TheQueueName
(VM ID and name string) to look up.- Returns:
- The integer ID of the existing queue.
- Throws:
WasmException
- withWasmResult.NOT_FOUND
if 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:
registerSharedQueue
in 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.)
-
-