Class Reducers

Namespace
Cratis.Chronicle.Reducers
Assembly
Cratis.Chronicle.dll

Represents an implementation of IReducers.

public class Reducers : IReducers
Inheritance
Reducers
Implements
Inherited Members
Extension Methods

Constructors

Reducers(IEventStore, IClientArtifactsProvider, IServiceProvider, IClientArtifactsActivator, IReducerValidator, IEventTypes, INamingPolicy, JsonSerializerOptions, IIdentityProvider, IReducerObservers, IActivitySource<Reducers>, ILogger<Reducers>)

Initializes a new instance of the Reducers class.

public Reducers(IEventStore eventStore, IClientArtifactsProvider clientArtifacts, IServiceProvider serviceProvider, IClientArtifactsActivator artifactActivator, IReducerValidator reducerValidator, IEventTypes eventTypes, INamingPolicy namingPolicy, JsonSerializerOptions jsonSerializerOptions, IIdentityProvider identityProvider, IReducerObservers reducerObservers, IActivitySource<Reducers> activitySource, ILogger<Reducers> logger)

Parameters

eventStore IEventStore

IEventStore the reducers belong to.

clientArtifacts IClientArtifactsProvider

IClientArtifactsProvider for discovery.

serviceProvider IServiceProvider

IServiceProvider to get instances of types.

artifactActivator IClientArtifactsActivator

IClientArtifactsActivator for creating artifact instances.

reducerValidator IReducerValidator

IReducerValidator for validating reducer types.

eventTypes IEventTypes

Registered IEventTypes.

namingPolicy INamingPolicy

INamingPolicy for converting names during serialization.

jsonSerializerOptions JsonSerializerOptions

JsonSerializerOptions for JSON serialization.

identityProvider IIdentityProvider

IIdentityProvider for managing identity context.

reducerObservers IReducerObservers

IReducerObservers for managing reducer observers.

activitySource IActivitySource<Reducers>

IActivitySource<T> for tracing reducer event handling.

logger ILogger<Reducers>

ILogger for logging.

Methods

Discover()

Discover all reducers from the entry assembly and dependencies.

public Task Discover()

Returns

Task

Awaitable task.

FastForward(ReducerId)

Fast forward a specific reducer 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(ReducerId reducerId)

Parameters

reducerId ReducerId

ReducerId to fast forward.

Returns

Task<FastForwardResult>

The FastForwardResult describing what happened.

FastForward<TReducer>()

Fast forward a reducer to the tail of the event log, skipping every event it has not yet handled without invoking it.

public Task<FastForwardResult> FastForward<TReducer>() where TReducer : IReducer

Returns

Task<FastForwardResult>

The FastForwardResult describing what happened.

Type Parameters

TReducer

Type of reducer to fast forward.

GetAllHandlers()

Get all registered handlers.

public IEnumerable<IReducerHandler> GetAllHandlers()

Returns

IEnumerable<IReducerHandler>

Collection of IReducerHandler.

GetClrType(ReducerId)

Get the CLR type for a specific reducer.

public Type GetClrType(ReducerId reducerId)

Parameters

reducerId ReducerId

ReducerId to get for.

Returns

Type

The type.

GetFailedPartitionsFor(Type)

Get any failed partitions for a specific reducer.

public Task<IEnumerable<FailedPartition>> GetFailedPartitionsFor(Type reducerType)

Parameters

reducerType Type

Type of reducer.

Returns

Task<IEnumerable<FailedPartition>>

Collection of FailedPartition, if any.

GetFailedPartitionsFor<TReducer>()

Get any failed partitions for a specific reducer.

public Task<IEnumerable<FailedPartition>> GetFailedPartitionsFor<TReducer>() where TReducer : IReducer

Returns

Task<IEnumerable<FailedPartition>>

Collection of FailedPartition, if any.

Type Parameters

TReducer

Type of reducer.

GetHandlerById(ReducerId)

Get all registered reducers by its identifier.

public IReducerHandler GetHandlerById(ReducerId reducerId)

Parameters

reducerId ReducerId

The identifier of the reducer to get.

Returns

IReducerHandler

IReducerHandler instance.

GetHandlerFor(Type)

Gets a specific handler by its reducer type.

public IReducerHandler GetHandlerFor(Type reducerType)

Parameters

reducerType Type

The reducer type to get for.

Returns

IReducerHandler

IReducerHandler.

GetHandlerForReadModelType(Type)

Get a specific handler for a specific model type.

public IReducerHandler GetHandlerForReadModelType(Type readModelType)

Parameters

readModelType Type

Model type to get for.

Returns

IReducerHandler

IReducerHandler instance.

GetHandlerFor<TReducer>()

Get a specific handler for a specific reducer.

public IReducerHandler GetHandlerFor<TReducer>() where TReducer : IReducer

Returns

IReducerHandler

IReducerHandler.

Type Parameters

TReducer

Type of reducer to get for.

GetInstanceById(Type, ReadModelKey)

Get a reduced read model instance by key by replaying events in-process.

public Task<object?> GetInstanceById(Type readModelType, ReadModelKey readModelKey)

Parameters

readModelType Type

The read model type to get an instance for.

readModelKey ReadModelKey

The read model key to get.

Returns

Task<object>

The reduced read model instance, or null if no events exist for the key.

GetInstances(Type, EventCount?)

Get reduced read model instances by replaying events in-process.

public Task<IEnumerable<object>> GetInstances(Type readModelType, EventCount? eventCount = null)

Parameters

readModelType Type

The read model type to get instances for.

eventCount EventCount

Optional limit for number of events to replay from the beginning.

Returns

Task<IEnumerable<object>>

Collection of reduced read model instances.

GetStateFor(Type)

Gets a registered reducer's state.

public Task<ReducerState> GetStateFor(Type reducerType)

Parameters

reducerType Type

The reducer CLR type.

Returns

Task<ReducerState>

The reducer state.

Exceptions

TypeBasedArtifactRegistrationNotSupported

The custom registry does not support type-based state lookup.

GetStateFor<TReducer>()

Get the state of a specific reactor.

public Task<ReducerState> GetStateFor<TReducer>() where TReducer : IReducer

Returns

Task<ReducerState>

ReducerState.

Type Parameters

TReducer

Type of reactor get for.

HasFor(Type)

Check if there is a reducer for a specific read model type.

public bool HasFor(Type readModelType)

Parameters

readModelType Type

The read model type to check for.

Returns

bool

True if it has, false if not.

HasFor<TReadModel>()

Check if there is a reducer for a specific read model type.

public bool HasFor<TReadModel>()

Returns

bool

True if it has, false if not.

Type Parameters

TReadModel

The read model type to check for.

HasReducerFor(Type)

Check if there is a reducer for a specific model type.

public bool HasReducerFor(Type readModelType)

Parameters

readModelType Type

Model type to check for.

Returns

bool

True if it has, false if not.

Register()

Register all reducers with Chronicle.

public Task Register()

Returns

Task

Awaitable task.

Register(Type)

Registers a reducer with its inferred read model.

public Task<IReducerHandler> Register(Type reducerType)

Parameters

reducerType Type

The reducer CLR type.

Returns

Task<IReducerHandler>

The registered handler.

Exceptions

TypeBasedArtifactRegistrationNotSupported

The custom registry does not support type-based registration.

Register<TReducer, TReadModel>()

Registers a TReducer reducer with Chronicle.

public Task<IReducerHandler> Register<TReducer, TReadModel>() where TReducer : IReducerFor<TReadModel> where TReadModel : class

Returns

Task<IReducerHandler>

Awaitable task.

Type Parameters

TReducer

The reactor type.

TReadModel

The model type the reducer is for.

Replay(ReducerId)

Replay a specific reducer by its identifier.

public Task<JobId> Replay(ReducerId reducerId)

Parameters

reducerId ReducerId

ReducerId to replay.

Returns

Task<JobId>

The JobId of the replay job that was started or resumed, or NotSet if the reducer 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 reducer CLR type.

public Task<JobId> Replay(Type reducerType)

Parameters

reducerType Type

The reducer CLR type.

Returns

Task<JobId>

The replay job identifier.

Exceptions

TypeBasedArtifactRegistrationNotSupported

The custom registry does not support type-based replay.

Replay<TReducer>()

Replay a specific reducer.

public Task<JobId> Replay<TReducer>() where TReducer : IReducer

Returns

Task<JobId>

The JobId of the replay job that was started or resumed, or NotSet if the reducer 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

TReducer

Type of reducer to replay.