Package dev.restate.sdk
Interface ServiceHandle<SVC>
- Type Parameters:
SVC- the service interface type
@Experimental
public interface ServiceHandle<SVC>
EXPERIMENTAL API: This interface is part of the new reflection-based API and may change in
future releases.
Advanced API handle for invoking Restate services, virtual objects, or workflows with full control. This handle provides advanced invocation capabilities including:
- Composable futures for asynchronous request handling
- Invocation options such as idempotency keys
- Fire-and-forget requests via
send() - Deferred response handling
Use this handle to perform requests with method references:
// 1. Use call() with method reference and await the result
GreetingResponse response = Restate.serviceHandle(Greeter.class)
.call(Greeter::greet, new Greeting("Alice"))
.await();
// 2. Use send() for one-way invocation without waiting
InvocationHandle<GreetingResponse> handle = Restate.serviceHandle(Greeter.class)
.send(Greeter::greet, new Greeting("Alice"));
Create instances using Restate.serviceHandle(Class), Restate.virtualObjectHandle(Class, String), or Restate.workflowHandle(Class, String).
For simple synchronous request-response interactions, consider using the simple proxy API
instead: Restate.service(Class), Restate.virtualObject(Class, String), or Restate.workflow(Class, String).
-
Method Summary
Modifier and TypeMethodDescriptiondefault <I> DurableFuture<Void> call(BiConsumer<SVC, I> methodReference, I input) EXPERIMENTAL API: Likecall(BiFunction, Object), for methods without a return value.<I> DurableFuture<Void> call(BiConsumer<SVC, I> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likecall(BiConsumer, Object), with invocation options.default <I> DurableFuture<Void> call(BiConsumer<SVC, I> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(BiConsumer, Object), with invocation options.default <I,O> DurableFuture <O> call(BiFunction<SVC, I, O> methodReference, I input) EXPERIMENTAL API: Invoke a service method with input and return a future for the result.<I,O> DurableFuture <O> call(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likecall(BiFunction, Object), with invocation options.default <I,O> DurableFuture <O> call(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(BiFunction, Object), with invocation options.default DurableFuture<Void> EXPERIMENTAL API: Likecall(BiFunction, Object), for methods without input or return value.call(Consumer<SVC> methodReference, InvocationOptions options) EXPERIMENTAL API: Likecall(Consumer), with invocation options.default DurableFuture<Void> call(Consumer<SVC> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(Consumer), with invocation options.default <O> DurableFuture<O> EXPERIMENTAL API: Invoke a service method without input and return a future for the result.<O> DurableFuture<O> call(Function<SVC, O> methodReference, InvocationOptions options) EXPERIMENTAL API: Likecall(Function), with invocation options.default <O> DurableFuture<O> call(Function<SVC, O> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(Function), with invocation options.default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input) EXPERIMENTAL API: Likesend(BiFunction, Object), for methods without a return value.default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with invocation options.default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with invocation options.default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, Duration delay) EXPERIMENTAL API: Likesend(BiConsumer, Object), with a delay.<I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with a delay and invocation options.default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with a delay and invocation options.default <I,O> InvocationHandle <O> send(BiFunction<SVC, I, O> methodReference, I input) EXPERIMENTAL API: Send a one-way invocation without waiting for the response.default <I,O> InvocationHandle <O> send(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likesend(BiFunction, Object), with invocation options.default <I,O> InvocationHandle <O> send(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiFunction, Object), with invocation options.default <I,O> InvocationHandle <O> send(BiFunction<SVC, I, O> methodReference, I input, Duration delay) EXPERIMENTAL API: Likesend(BiFunction, Object), with a delay.<I,O> InvocationHandle <O> send(BiFunction<SVC, I, O> methodReference, I input, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(BiFunction, Object), with a delay and invocation options.default <I,O> InvocationHandle <O> send(BiFunction<SVC, I, O> methodReference, I input, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiFunction, Object), with a delay and invocation options.default InvocationHandle<Void> EXPERIMENTAL API: Likesend(BiFunction, Object), for methods without input or return value.default InvocationHandle<Void> send(Consumer<SVC> methodReference, InvocationOptions options) EXPERIMENTAL API: Likesend(Consumer), with invocation options.default InvocationHandle<Void> send(Consumer<SVC> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Consumer), with invocation options.default InvocationHandle<Void> EXPERIMENTAL API: Likesend(Consumer), with a delay.send(Consumer<SVC> methodReference, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(Consumer), with a delay and invocation options.default InvocationHandle<Void> send(Consumer<SVC> methodReference, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Consumer), with a delay and invocation options.default <O> InvocationHandle<O> EXPERIMENTAL API: Likesend(BiFunction, Object), for methods without input.default <O> InvocationHandle<O> send(Function<SVC, O> s, InvocationOptions options) EXPERIMENTAL API: Likesend(Function), with invocation options.default <O> InvocationHandle<O> send(Function<SVC, O> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Function), with invocation options.default <O> InvocationHandle<O> EXPERIMENTAL API: Likesend(Function), with a delay.<O> InvocationHandle<O> send(Function<SVC, O> methodReference, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(Function), with a delay and invocation options.default <O> InvocationHandle<O> send(Function<SVC, O> methodReference, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Function), with a delay and invocation options.
-
Method Details
-
call
EXPERIMENTAL API: Invoke a service method with input and return a future for the result.// Call with method reference and input GreetingResponse response = Restate.service(Greeter.class) .call(Greeter::greet, new Greeting("Alice")) .await();- Parameters:
methodReference- method reference (e.g.,Greeter::greet)input- the input parameter to pass to the method- Returns:
- a
DurableFuturewrapping the result
-
call
@Experimental default <I,O> DurableFuture<O> call(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(BiFunction, Object), with invocation options.// Call with custom options var options = InvocationOptions.builder() .idempotencyKey("unique-key") .build(); GreetingResponse response = Restate.service(Greeter.class) .call(Greeter::greet, new Greeting("Alice"), options) .await(); -
call
@Experimental <I,O> DurableFuture<O> call(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likecall(BiFunction, Object), with invocation options. -
call
EXPERIMENTAL API: Likecall(BiFunction, Object), for methods without a return value. -
call
@Experimental default <I> DurableFuture<Void> call(BiConsumer<SVC, I> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(BiConsumer, Object), with invocation options. -
call
@Experimental <I> DurableFuture<Void> call(BiConsumer<SVC, I> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likecall(BiConsumer, Object), with invocation options. -
call
EXPERIMENTAL API: Invoke a service method without input and return a future for the result.// Call method without input int count = Restate.virtualObject(Counter.class, "my-counter") .call(Counter::get) .await(); -
call
@Experimental default <O> DurableFuture<O> call(Function<SVC, O> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(Function), with invocation options. -
call
EXPERIMENTAL API: Likecall(Function), with invocation options. -
call
EXPERIMENTAL API: Likecall(BiFunction, Object), for methods without input or return value. -
call
@Experimental default DurableFuture<Void> call(Consumer<SVC> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likecall(Consumer), with invocation options. -
call
EXPERIMENTAL API: Likecall(Consumer), with invocation options. -
send
EXPERIMENTAL API: Send a one-way invocation without waiting for the response.// Send without waiting for response InvocationHandle<GreetingResponse> handle = Restate.service(Greeter.class) .send(Greeter::greet, new Greeting("Alice")); String invocationId = handle.invocationId(); // Send with a delay InvocationHandle<GreetingResponse> handle = Restate.service(Greeter.class) .send(Greeter::greet, new Greeting("Alice"), Duration.ofMinutes(5));- Parameters:
methodReference- method reference (e.g.,Greeter::greet)input- the input parameter to pass to the method- Returns:
- an
InvocationHandlefor the invocation
-
send
@Experimental default <I,O> InvocationHandle<O> send(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiFunction, Object), with invocation options. -
send
@Experimental default <I,O> InvocationHandle<O> send(BiFunction<SVC, I, O> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likesend(BiFunction, Object), with invocation options. -
send
@Experimental default <I,O> InvocationHandle<O> send(BiFunction<SVC, I, O> methodReference, I input, Duration delay) EXPERIMENTAL API: Likesend(BiFunction, Object), with a delay. -
send
@Experimental default <I,O> InvocationHandle<O> send(BiFunction<SVC, I, O> methodReference, I input, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiFunction, Object), with a delay and invocation options. -
send
@Experimental <I,O> InvocationHandle<O> send(BiFunction<SVC, I, O> methodReference, I input, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(BiFunction, Object), with a delay and invocation options. -
send
EXPERIMENTAL API: Likesend(BiFunction, Object), for methods without a return value. -
send
@Experimental default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with invocation options. -
send
@Experimental default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, InvocationOptions options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with invocation options. -
send
@Experimental default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, Duration delay) EXPERIMENTAL API: Likesend(BiConsumer, Object), with a delay. -
send
@Experimental default <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with a delay and invocation options. -
send
@Experimental <I> InvocationHandle<Void> send(BiConsumer<SVC, I> methodReference, I input, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(BiConsumer, Object), with a delay and invocation options. -
send
EXPERIMENTAL API: Likesend(BiFunction, Object), for methods without input. -
send
@Experimental default <O> InvocationHandle<O> send(Function<SVC, O> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Function), with invocation options. -
send
EXPERIMENTAL API: Likesend(Function), with invocation options. -
send
EXPERIMENTAL API: Likesend(Function), with a delay. -
send
@Experimental default <O> InvocationHandle<O> send(Function<SVC, O> methodReference, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Function), with a delay and invocation options. -
send
@Experimental <O> InvocationHandle<O> send(Function<SVC, O> methodReference, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(Function), with a delay and invocation options. -
send
EXPERIMENTAL API: Likesend(BiFunction, Object), for methods without input or return value. -
send
@Experimental default InvocationHandle<Void> send(Consumer<SVC> methodReference, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Consumer), with invocation options. -
send
@Experimental default InvocationHandle<Void> send(Consumer<SVC> methodReference, InvocationOptions options) EXPERIMENTAL API: Likesend(Consumer), with invocation options. -
send
EXPERIMENTAL API: Likesend(Consumer), with a delay. -
send
@Experimental default InvocationHandle<Void> send(Consumer<SVC> methodReference, Duration delay, InvocationOptions.Builder options) EXPERIMENTAL API: Likesend(Consumer), with a delay and invocation options. -
send
@Experimental InvocationHandle<Void> send(Consumer<SVC> methodReference, Duration delay, InvocationOptions options) EXPERIMENTAL API: Likesend(Consumer), with a delay and invocation options.
-