KotlinState

@ApiStatus.Experimental
interface KotlinState

Interface for accessing Virtual Object/Workflow state in the reflection-based API.

This interface provides suspend-friendly state operations that can be used from within Restate handlers using the free-floating state() function.

Example usage:

@VirtualObject
class Counter {
companion object {
private val COUNT = stateKey<Long>("count")
}

@Handler
suspend fun increment(): Long {
val current = state().get(COUNT) ?: 0L
val next = current + 1
state().set(COUNT, next)
return next
}
}

Functions

Link copied to clipboard
@ApiStatus.Experimental
abstract suspend fun clear(key: StateKey<*>)

Clears the state stored under key.

Link copied to clipboard
@ApiStatus.Experimental
abstract suspend fun clearAll()

Clears all the state of this virtual object instance key-value state storage.

Link copied to clipboard
@ApiStatus.Experimental
abstract suspend fun <T : Any> get(key: StateKey<T>): T?

Gets the state stored under key, deserializing the raw value using the StateKey.serdeInfo.

Link copied to clipboard
@ApiStatus.Experimental
inline suspend fun <T : Any> KotlinState.get(key: String): T?

Gets the state stored under key.

Link copied to clipboard
@ApiStatus.Experimental
abstract suspend fun keys(): Collection<String>

Gets all the known state keys for this virtual object instance.

Link copied to clipboard
@ApiStatus.Experimental
abstract suspend fun <T : Any> set(key: StateKey<T>, value: T)

Sets the given value under the given key, serializing the value using the StateKey.serdeInfo.

Link copied to clipboard
@ApiStatus.Experimental
inline suspend fun <T : Any> KotlinState.set(key: String, value: T)

Sets the given value under the given key.