Class SimpleSharedQueueHandler

  • All Implemented Interfaces:
    SharedQueueHandler

    public class SimpleSharedQueueHandler
    extends Object
    implements SharedQueueHandler
    A basic, in-memory implementation of the SharedQueueHandler 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.

    • Constructor Detail

      • SimpleSharedQueueHandler

        public SimpleSharedQueueHandler()
        Default constructor.
    • Method Detail

      • 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 interface SharedQueueHandler
        Parameters:
        queueId - The ID of the target queue.
        value - The message data to enqueue.
        Returns:
        WasmResult.OK if successful, or WasmResult.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 interface SharedQueueHandler
        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 - with WasmResult.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 interface SharedQueueHandler
        Parameters:
        queueName - The QueueName (VM ID and name string) to look up.
        Returns:
        The integer ID of the existing queue.
        Throws:
        WasmException - with WasmResult.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 interface SharedQueueHandler
        Parameters:
        queueName - The QueueName (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.)