Class Reactors
- Namespace
- Cratis.Chronicle.Reactors
- Assembly
- Cratis.Chronicle.dll
Represents an implementation of IReactors.
public class Reactors : IReactors, IReactorPartitionRecovery
- Inheritance
-
Reactors
- Implements
- Inherited Members
- Extension Methods
Constructors
Reactors(IEventStore, IEventTypes, IClientArtifactsProvider, IServiceProvider, IClientArtifactsActivator, IActivateReactorMiddlewares, IEventSerializer, ICausationManager, IIdentityProvider, IActivitySource<Reactors>, IReactorSideEffectHandlers, IReactorContextValuesBuilder, IReactorMethodArgumentsResolver, ILogger<Reactors>, ILoggerFactory)
Initializes a new instance of the Reactors class.
public Reactors(IEventStore eventStore, IEventTypes eventTypes, IClientArtifactsProvider clientArtifactsProvider, IServiceProvider serviceProvider, IClientArtifactsActivator artifactActivator, IActivateReactorMiddlewares middlewaresActivator, IEventSerializer eventSerializer, ICausationManager causationManager, IIdentityProvider identityProvider, IActivitySource<Reactors> activitySource, IReactorSideEffectHandlers sideEffectHandlers, IReactorContextValuesBuilder reactorContextValuesBuilder, IReactorMethodArgumentsResolver argumentsResolver, ILogger<Reactors> logger, ILoggerFactory loggerFactory)
Parameters
eventStoreIEventStoreIEventStore the Reactors belong to.
eventTypesIEventTypesIEventTypes for resolving event types.
clientArtifactsProviderIClientArtifactsProviderIClientArtifactsProvider for getting client artifacts.
serviceProviderIServiceProviderIServiceProvider to get instances of types.
artifactActivatorIClientArtifactsActivatorIClientArtifactsActivator for creating artifact instances.
middlewaresActivatorIActivateReactorMiddlewaresIReactorMiddlewares to call.
eventSerializerIEventSerializerIEventSerializer for serializing of events.
causationManagerICausationManagerICausationManager for working with causation.
identityProviderIIdentityProviderIIdentityProvider for managing identity context.
activitySourceIActivitySource<Reactors>IActivitySource<T> for tracing reactor event handling.
sideEffectHandlersIReactorSideEffectHandlersIReactorSideEffectHandlers for processing return values as side effects.
reactorContextValuesBuilderIReactorContextValuesBuilderIReactorContextValuesBuilder for resolving append-metadata for side-effect events.
argumentsResolverIReactorMethodArgumentsResolverIReactorMethodArgumentsResolver for resolving handler method arguments.
loggerILogger<Reactors>ILogger for logging.
loggerFactoryILoggerFactoryILoggerFactory for creating loggers.
Methods
ClearFailedPartitionQuarantineFor(Type, Partition, bool)
Clear the quarantine of a failed partition for a registered reactor and reset its retry budget, keeping its attempt history.
public Task<ReactorPartitionQuarantineClearResult> ClearFailedPartitionQuarantineFor(Type reactorType, Partition partition, bool retryImmediately = true)
Parameters
reactorTypeTypeThe registered reactor type.
partitionPartitionThe quarantined partition.
retryImmediatelyboolWhether to start recovering the partition right away.
Returns
- Task<ReactorPartitionQuarantineClearResult>
The bounded outcome of the request.
Define(ReactorId, Action<IReactorBuilder>)
Define a reactor fluently, without registering it.
public IReactorDefinition Define(ReactorId id, Action<IReactorBuilder> define)
Parameters
idReactorIdThe stable reactor identifier.
defineAction<IReactorBuilder>Declares the reactor's handlers, event sequence and replay policy on an IReactorBuilder.
Returns
- IReactorDefinition
The IReactorDefinition, which can be inspected and then registered with Register(IReactorDefinition).
Remarks
Event types are resolved against the event types this client knows at the time of the call, which is also what an all-events subscription is expanded to.
Exceptions
- NoEventTypesForReactor
Thrown when the definition subscribes to no event types.
- TypeIsNotAnEventType
Thrown when a typed handler names a type that is not a known event type.
Discover()
Discover all Reactors from the entry assembly and dependencies.
public Task Discover()
Returns
- Task
Awaitable task.
FastForward(ReactorId)
Fast forward a specific reactor by its identifier to the tail of the event log, skipping every event it has not yet handled without invoking it.
public Task<FastForwardResult> FastForward(ReactorId reactorId)
Parameters
Returns
- Task<FastForwardResult>
The FastForwardResult describing what happened.
FastForward<TReactor>()
Fast forward a reactor to the tail of the event log, skipping every event it has not yet handled without invoking it.
public Task<FastForwardResult> FastForward<TReactor>() where TReactor : IReactor
Returns
- Task<FastForwardResult>
The FastForwardResult describing what happened.
Type Parameters
TReactorType of reactor to fast forward.
GetFailedPartitionsFor(Type)
Get any failed partitions for a specific reactor.
public Task<IEnumerable<FailedPartition>> GetFailedPartitionsFor(Type reactorType)
Parameters
reactorTypeTypeType of reducer.
Returns
- Task<IEnumerable<FailedPartition>>
Collection of FailedPartition, if any.
GetFailedPartitionsFor<TReactor>()
Get any failed partitions for a specific reactor.
public Task<IEnumerable<FailedPartition>> GetFailedPartitionsFor<TReactor>()
Returns
- Task<IEnumerable<FailedPartition>>
Collection of FailedPartition, if any.
Type Parameters
TReactorType of reducer.
GetHandlerById(ReactorId)
Gets a specific handler by its ReactorId.
public IReactorHandler GetHandlerById(ReactorId id)
Parameters
Returns
- IReactorHandler
ReactorHandler instance.
GetHandlerFor(Type)
Gets the registered handler for a reactor CLR type.
public IReactorHandler GetHandlerFor(Type reactorType)
Parameters
reactorTypeTypeThe reactor CLR type.
Returns
- IReactorHandler
The registered handler.
Exceptions
- TypeBasedArtifactRegistrationNotSupported
The custom registry does not support type-based lookup.
GetHandlerFor<TReactor>()
Gets a specific handler by its TReactor type.
public IReactorHandler GetHandlerFor<TReactor>() where TReactor : IReactor
Returns
- IReactorHandler
ReactorHandler instance.
Type Parameters
TReactorThe reactor type.
GetStateFor(Type)
Gets a registered reactor's state.
public Task<ReactorState> GetStateFor(Type reactorType)
Parameters
reactorTypeTypeThe reactor CLR type.
Returns
- Task<ReactorState>
The reactor state.
Exceptions
- TypeBasedArtifactRegistrationNotSupported
The custom registry does not support type-based state lookup.
GetStateFor<TReactor>()
Get the state of a specific reactor.
public Task<ReactorState> GetStateFor<TReactor>() where TReactor : IReactor
Returns
Type Parameters
TReactorType of reactor get for.
Register()
Register all Reactors with Chronicle.
public Task Register()
Returns
- Task
Awaitable task.
Register(IReactorDefinition)
Register a reactor from a fluent definition.
public Task<IReactorHandler> Register(IReactorDefinition definition)
Parameters
definitionIReactorDefinitionThe IReactorDefinition to register.
Returns
- Task<IReactorHandler>
The registered handler, which can be inspected for state and failed partitions.
Remarks
The reactor is an ordinary Chronicle reactor: it has an observer of its own, subscribed to exactly the definition's EventTypes, and it has state, failed partitions and replay like a discovered reactor has. Each delivered event is deserialized to its CLR type and passed to Handle(object, EventContext). The registration is sent to Chronicle immediately, and is sent again whenever the connection is re-established. Delegate handlers report ReactorType as object.
Exceptions
- ReactorAlreadyRegistered
Thrown when the identifier already belongs to a reactor in this client.
Register(ReactorId, Action<IReactorBuilder>)
Define and register a reactor fluently, with typed and catch-all handlers.
public Task<IReactorHandler> Register(ReactorId id, Action<IReactorBuilder> define)
Parameters
idReactorIdThe stable reactor identifier.
defineAction<IReactorBuilder>Declares the reactor's handlers, event sequence and replay policy on an IReactorBuilder.
Returns
- Task<IReactorHandler>
The registered handler, which can be inspected for state and failed partitions.
Remarks
This is Define(ReactorId, Action<IReactorBuilder>) followed by Register(IReactorDefinition).
Exceptions
- NoEventTypesForReactor
Thrown when the definition subscribes to no event types.
- TypeIsNotAnEventType
Thrown when a typed handler names a type that is not a known event type.
- ReactorAlreadyRegistered
Thrown when the identifier already belongs to a reactor in this client.
Register(ReactorId, Action<IReactorDefinitionBuilder>, Func<ReactorEvent, CancellationToken, Task>)
Registers a reactor from an explicit event subscription and an awaited callback.
public Task<IReactorHandler> Register(ReactorId id, Action<IReactorDefinitionBuilder> configure, Func<ReactorEvent, CancellationToken, Task> handle)
Parameters
idReactorIdThe stable reactor identifier.
configureAction<IReactorDefinitionBuilder>Configures the event types, sequence, and replay policy.
handleFunc<ReactorEvent, CancellationToken, Task>Handles each delivered event; successful completion acknowledges the event.
Returns
- Task<IReactorHandler>
The registered handler, which can be inspected for state and failed partitions.
Remarks
Delegate handlers report ReactorType as object.
Exceptions
- NoEventTypesForReactor
Thrown when no event types are configured.
- ReactorAlreadyRegistered
Thrown when the identifier already belongs to a reactor in this client.
Register(Type)
Registers a reactor type using this store's declarations.
public Task<IReactorHandler> Register(Type reactorType)
Parameters
reactorTypeTypeThe reactor CLR type.
Returns
- Task<IReactorHandler>
The registered handler.
Exceptions
- TypeBasedArtifactRegistrationNotSupported
The custom registry does not support type-based registration.
Register<TReactor>()
Registers a TReactor reactor with Chronicle.
public Task<IReactorHandler> Register<TReactor>() where TReactor : IReactor
Returns
- Task<IReactorHandler>
Awaitable task.
Type Parameters
TReactorThe reactor type.
Replay(ReactorId)
Replay a specific reactor by its identifier.
public Task<JobId> Replay(ReactorId reactorId)
Parameters
Returns
- Task<JobId>
The JobId of the replay job that was started or resumed, or NotSet if the reactor is not replayable or its observer is not in a state it can replay from (disconnected, quarantined); reconnect or release it before replaying.
Replay(Type)
Replays a registered reactor CLR type.
public Task<JobId> Replay(Type reactorType)
Parameters
reactorTypeTypeThe reactor CLR type.
Returns
Exceptions
- TypeBasedArtifactRegistrationNotSupported
The custom registry does not support type-based replay.
Replay<TReactor>()
Replay a specific reactor.
public Task<JobId> Replay<TReactor>() where TReactor : IReactor
Returns
- Task<JobId>
The JobId of the replay job that was started or resumed, or NotSet if the reactor is not replayable or its observer is not in a state it can replay from (disconnected, quarantined); reconnect or release it before replaying.
Type Parameters
TReactorType of reactor to replay.
RetryFailedPartitionFor(Type, Partition)
Retry a failed partition for a registered reactor.
public Task<ReactorPartitionRetryOutcome> RetryFailedPartitionFor(Type reactorType, Partition partition)
Parameters
Returns
- Task<ReactorPartitionRetryOutcome>
The bounded outcome of the retry request.
Unregister(ReactorId)
Unregisters a reactor in this client, disconnecting its observation stream. An unknown identifier is ignored.
public void Unregister(ReactorId id)
Parameters
idReactorIdThe reactor identifier to unregister.