Class CommandInterpreter
Represents interpreter of the log entries.
Inherited Members
Namespace: DotNext.Net.Cluster.Consensus.Raft.Commands
Assembly: DotNext.Net.Cluster.dll
Syntax
public class CommandInterpreter : Disposable, IDisposable, IBuildable<CommandInterpreter, CommandInterpreter.Builder>
Remarks
The interpreter can be constructed in two ways: using CommandInterpreter.Builder and through inheritance. If you choose the inheritance then command handlers must be declared as public instance methods marked with CommandInterpreter.CommandHandlerAttribute attribute. Otherwise, command handlers can be registered through the builder. Typically, the interpreter is aggregated by the class derived from PersistentState. All command types must be registered using CommandAttribute<TCommand> attributes applied to the derived type.
Constructors
| Edit this page View SourceCommandInterpreter()
Initializes a new interpreter and discovers methods marked with CommandInterpreter.CommandHandlerAttribute attribute.
Declaration
protected CommandInterpreter()
Methods
| Edit this page View SourceCreateLogEntry<TCommand>(TCommand, long)
Wraps the command to the log entry.
Declaration
public LogEntry<TCommand> CreateLogEntry<TCommand>(TCommand command, long term) where TCommand : notnull, ISerializable<TCommand>
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | The payload of the command. |
long | term | The term of the local node. |
Returns
Type | Description |
---|---|
LogEntry<TCommand> | The instance of the log entry containing the command. |
Type Parameters
Name | Description |
---|---|
TCommand | The type of the command. |
Exceptions
Type | Condition |
---|---|
GenericArgumentException |
|
InterpretAsync<TEntry>(TEntry, object?, CancellationToken)
Interprets log entry asynchronously.
Declaration
public ValueTask<int> InterpretAsync<TEntry>(TEntry entry, object? context, CancellationToken token = default) where TEntry : struct, IRaftLogEntry
Parameters
Type | Name | Description |
---|---|---|
TEntry | entry | The log entry to be interpreted. |
object | context | The context to be passed to the handler. |
CancellationToken | token | The token that can be used to cancel the interpretation. |
Returns
Type | Description |
---|---|
ValueTask<int> | The ID of the interpreted log entry. |
Type Parameters
Name | Description |
---|---|
TEntry | The type of the log entry to be interpreted. |
Remarks
Typically this method is called by the custom implementation of ApplyAsync(LogEntry) method.
Exceptions
Type | Condition |
---|---|
CommandInterpreter.UnknownCommandException | The command handler was not registered for the command represented by |
OperationCanceledException | The operation has been canceled. |
InterpretAsync<TEntry>(TEntry, CancellationToken)
Interprets log entry asynchronously.
Declaration
public ValueTask<int> InterpretAsync<TEntry>(TEntry entry, CancellationToken token = default) where TEntry : struct, IRaftLogEntry
Parameters
Type | Name | Description |
---|---|---|
TEntry | entry | The log entry to be interpreted. |
CancellationToken | token | The token that can be used to cancel the interpretation. |
Returns
Type | Description |
---|---|
ValueTask<int> | The ID of the interpreted log entry. |
Type Parameters
Name | Description |
---|---|
TEntry | The type of the log entry to be interpreted. |
Remarks
Typically this method is called by the custom implementation of ApplyAsync(LogEntry) method.
Exceptions
Type | Condition |
---|---|
CommandInterpreter.UnknownCommandException | The command handler was not registered for the command represented by |
OperationCanceledException | The operation has been canceled. |