Package io.roastedroot.proxywasm
Interface SharedDataHandler
-
- All Known Implementing Classes:
SimpleSharedDataHandler
public interface SharedDataHandlerDefines 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 SharedDataHandlerDEFAULTA default, non-functional instance ofSharedDataHandler.
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default SharedDatagetSharedData(String key)Retrieves the shared data associated with the given key.default io.roastedroot.proxywasm.internal.WasmResultsetSharedData(String key, byte[] value, int cas)Sets or updates the shared data associated with the given key.
-
-
-
Field Detail
-
DEFAULT
static final SharedDataHandler DEFAULT
A default, non-functional instance ofSharedDataHandler. This instance throwsWasmExceptionwithWasmResult.UNIMPLEMENTEDforgetSharedData(String)and returnsWasmResult.UNIMPLEMENTEDforsetSharedData(String, byte[], int). Useful as a placeholder or base when shared data functionality is not supported or needed.
-
-
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 viasetSharedData(String, byte[], int).- Parameters:
key- The key identifying the shared data item.- Returns:
- A
SharedDataobject 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
casparameter enables Compare-And-Swap:- If
casis 0, the operation is unconditional (a blind write/overwrite). - If
casis non-zero, the operation only succeeds if the current CAS value stored in the host for the givenkeymatches the providedcas. If they don't match, it means the data was modified by another actor since it was last read, and the operation fails withWasmResult.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
WasmResultindicating the outcome (e.g.,WasmResult.OK,WasmResult.CAS_MISMATCH,WasmResult.UNIMPLEMENTED).
- If
-
-