Interface SharedDataHandler

  • All Known Implementing Classes:
    SimpleSharedDataHandler

    public interface SharedDataHandler
    Defines the contract for handling shared key-value data accessible by Proxy-WASM modules. Implementations of this interface manage the storage, retrieval, and conditional update (using CAS - Compare-And-Swap) of data that can be shared across different WASM module instances or even different VMs, depending on the host environment's implementation.

    Shared data provides a mechanism for state sharing, caching, or coordination between plugins.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static SharedDataHandler DEFAULT
      A default, non-functional instance of SharedDataHandler.
    • Method Detail

      • getSharedData

        default SharedData getSharedData​(String key)
                                  throws WasmException
        Retrieves the shared data associated with the given key. The result includes the data itself and a CAS (Compare-And-Swap) value, which represents the version of the data. The CAS value is used for optimistic concurrency control during updates via setSharedData(String, byte[], int).
        Parameters:
        key - The key identifying the shared data item.
        Returns:
        A SharedData object containing the value and its CAS.
        Throws:
        WasmException - If the key is not found (WasmResult.NOT_FOUND), or if the operation is unimplemented by the host.
      • setSharedData

        default io.roastedroot.proxywasm.internal.WasmResult setSharedData​(String key,
                                                                           byte[] value,
                                                                           int cas)
        Sets or updates the shared data associated with the given key. This operation can be conditional based on the provided CAS value.

        The cas parameter enables Compare-And-Swap:

        • If cas is 0, the operation is unconditional (a blind write/overwrite).
        • If cas is non-zero, the operation only succeeds if the current CAS value stored in the host for the given key matches the provided cas. If they don't match, it means the data was modified by another actor since it was last read, and the operation fails with WasmResult.CAS_MISMATCH.
        Parameters:
        key - The key identifying the shared data item.
        value - The new data value to store (can be null or empty, depending on implementation). A null value might signify deletion.
        cas - The Compare-And-Swap value expected for a conditional update, or 0 for an unconditional update.
        Returns:
        A WasmResult indicating the outcome (e.g., WasmResult.OK, WasmResult.CAS_MISMATCH, WasmResult.UNIMPLEMENTED).