All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cloudstate.javasupport.crdt.StreamedCommandContext Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
package io.cloudstate.javasupport.crdt;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Context for handling a streamed command.
 *
 * 

This may be passed to any {@link CommandHandler} annotated element that corresponds to a * command whose output is streamed. */ public interface StreamedCommandContext extends CommandContext { /** * Whether the call is actually streamed. * *

When a command is handled via the HTTP adapter, the command will not be streamed since the * HTTP adapter does not support streaming, and this will return false. In that case, * calls to {@link StreamedCommandContext#onChange(Function)} and {@link * StreamedCommandContext#onCancel(Consumer)} will fail. * * @return True if the command is actually streamed. */ boolean isStreamed(); /** * Register an on change callback for this command. * *

The callback will be invoked any time the CRDT changes. The callback may inspect the CRDT, * but any attempt to modify the CRDT will be ignored and the CRDT will crash. * *

If the callback returns a value, that value will be sent down the stream. Alternatively, the * callback may forward messages to other entities via the passed in {@link SubscriptionContext}. * The callback may also emit side effects to other entities via that context. * * @param subscriber The subscriber callback. */ void onChange(Function> subscriber); /** * Register an on cancel callback for this command. * *

This will be invoked if the client initiates a stream cancel. It will not be invoked if the * entity cancels the stream itself via {@link SubscriptionContext#endStream()} from an {@link * StreamedCommandContext#onChange(Function)} callback. * *

An on cancel callback may update the CRDT, and may emit side effects via the passed in * {@link StreamCancelledContext}. * * @param effect The effect to perform when this stream is cancelled. */ void onCancel(Consumer effect); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy