Interface Context

All Known Subinterfaces:
ObjectContext, SharedObjectContext, SharedWorkflowContext, WorkflowContext

public interface Context
This interface exposes the Restate functionalities to Restate services. It can be used to interact with other Restate services, record non-deterministic closures, execute timers and synchronize with external systems.

Error handling

All methods of this interface, and related interfaces, throws either TerminalException or AbortedExecutionException, where the former can be caught and acted upon, while the latter MUST NOT be caught, but simply propagated for clean up purposes.

Serialization and Deserialization

The methods of this interface that need to serialize or deserialize payloads have an overload both accepting Class or TypeTag. Depending on your case, you might use the Class overload for simple types, and TypeRef for generic types:

 String result = ctx.run(
    "my-http-request",
    String.class,
    () -> doHttpRequest().getResult()
 ).await();

 List<String> result = ctx.run(
    "my-http-request",
    new TypeRef<>(){ },
    () -> doHttpRequest().getResult()
 ).await();
 
By default, Jackson Databind will be used for all serialization/deserialization. Check SerdeFactory for more details on how to customize that.

Thread safety

This interface MUST NOT be accessed concurrently since it can lead to different orderings of user actions, corrupting the execution of the invocation.