Class ModelCommitHandlerRegistry

java.lang.Object
io.fluxzero.sdk.modeling.ModelCommitHandlerRegistry
All Implemented Interfaces:
HandlerFactory, HandlerRegistry, HasLocalHandlers, AutoCloseable

public final class ModelCommitHandlerRegistry extends Object implements HandlerRegistry, HandlerFactory, AutoCloseable
Registration and dispatch facade for independent-model handlers.

This type registers models and delegates application-bound definition lookup to MutationPlan. It owns no evaluation, commit, retry, batching or completion state; every invocation delegates to the single ModelPipeline lifecycle.

  • Constructor Details

    • ModelCommitHandlerRegistry

      public ModelCommitHandlerRegistry(DefaultModelRepository repository, EventStoreClient eventStoreClient, Serializer serializer, Serializer snapshotSerializer, DocumentSerializer documentSerializer, DispatchInterceptor commandDispatchInterceptor, DispatchInterceptor eventDispatchInterceptor, String source, List<io.fluxzero.common.handling.ParameterResolver<? super DeserializingMessage>> parameterResolvers, HandlerDecorator handlerDecorator, io.fluxzero.common.api.modeling.ModelConflictPolicy conflictPolicy, io.fluxzero.common.api.modeling.ModelConflictPolicy creationConflictPolicy, ModelConflictResolver conflictResolver, int maxConflictRetries, AutomaticModelHandling automaticHandling, GraphProjectionCompletion graphProjectionCompletion)
      Creates the automatic model registration facade and its single execution pipeline. creationConflictPolicy is the inherited policy for targets first created by an attempt; explicit Model/Apply policies still take precedence. The command dispatch interceptor finalizes deferred external-only side effects when a durable Model handler is actually selected; ordinary local handlers keep their dispatch-local state.
  • Method Details

    • repository

      public DefaultModelRepository repository()
      Returns the repository shared by automatic handling and public model loads.
    • routingTarget

      public String routingTarget(Message message)
      Returns the canonical target of a statically unambiguous single-Model apply, or null.
    • registeredModelTypes

      public List<Class<?>> registeredModelTypes()
      Returns the model types registered as handlers in this application.
    • knownModelTypes

      public List<Class<?>> knownModelTypes()
      Returns registered or structurally referenced concrete model types.
    • registerMigrationTypes

      public io.fluxzero.common.Registration registerMigrationTypes(Collection<Class<?>> modelTypes)
      Registers Model definitions for migration without enabling command tracking or Graph projections.
    • assertAndApply

      public CompletableFuture<Void> assertAndApply(Message update)
      Executes one explicit update through the model pipeline.
    • assertAndApply

      public CompletableFuture<Void> assertAndApply(Message update, String modelId, Class<?> modelType)
      Executes one explicit update against the selected persisted model.
    • assertAndApplyAll

      public CompletableFuture<Void> assertAndApplyAll(List<Message> updates)
      Executes independent explicit updates with shared transport batching.
    • assertLegal

      public CompletableFuture<Void> assertLegal(Message update)
      Runs interceptors and immediate assertions without applying or committing.
    • applyStoredEvent

      public CompletableFuture<Void> applyStoredEvent(Message event)
      Replays one already accepted event without command assertions or interception.
    • migratePublishedEvent

      public CompletableFuture<Void> migratePublishedEvent(Message event, long eventIndex)
      Applies one existing globally published event without republishing it.
    • handle

      Description copied from interface: HandlerRegistry
      Attempts to handle the given message using local handlers.
      Specified by:
      handle in interface HandlerRegistry
      Parameters:
      message - the deserialized message to dispatch
      Returns:
      an optional future containing the result, or empty if no handler was found
    • canHandle

      public boolean canHandle(DeserializingMessage message)
      Description copied from interface: HandlerRegistry
      Returns whether this registry has a local handler that can process the given message.
      Specified by:
      canHandle in interface HandlerRegistry
      Parameters:
      message - the message to inspect
      Returns:
      true if a local handler can handle the message, false otherwise
    • registerHandler

      public io.fluxzero.common.Registration registerHandler(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter)
      Description copied from interface: HasLocalHandlers
      Registers a handler object, including only those methods that match the provided HandlerFilter.

      This method offers fine-grained control over which handler methods are registered, based on custom logic applied to method annotations and/or signatures.

      Specified by:
      registerHandler in interface HasLocalHandlers
      Parameters:
      target - the handler object containing annotated methods
      handlerFilter - the filter used to determine which methods should be registered
      Returns:
      a Registration which can be used to unregister the handlers
    • trackingTargets

      public List<?> trackingTargets(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter)
      Description copied from interface: HandlerFactory
      Expands a registered target into the targets that should participate in tracking and consumer selection.

      Most handlers track the registered target itself. Handler vocabularies whose receiver differs from the incoming payload can expose the payload type here, ensuring that package- and class-scoped consumer configuration is resolved from the message being consumed.

      Specified by:
      trackingTargets in interface HandlerFactory
      Parameters:
      target - registered handler target
      handlerFilter - filter used for this tracking message type
      Returns:
      targets to assign to consumers
    • createHandler

      public Optional<io.fluxzero.common.handling.Handler<DeserializingMessage>> createHandler(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter, List<HandlerInterceptor> extraInterceptors)
      Description copied from interface: HandlerFactory
      Attempts to create a message handler for the given target object.

      This method analyzes the given object (or class) to discover message-handling methods (e.g. @HandleCommand, @HandleQuery, @HandleEvent, etc.) that match the provided HandlerFilter. If any matching handler methods are found, a new Handler instance is constructed to wrap them.

      This is a central mechanism in Fluxzero used to support:

      • Tracking handlers for stateful components
      • Mutable, dynamic, or self-handling types
      • In-memory @LocalHandlers
      Specified by:
      createHandler in interface HandlerFactory
      Parameters:
      target - The handler target object or class. Can be a class (e.g. MyHandler.class) or an instantiated object.
      handlerFilter - A filter to determine which methods are valid handler methods. Only methods that pass this filter are included.
      extraInterceptors - A list of additional HandlerInterceptors to apply around message dispatch. These can be used to customize behavior with logging, retry logic, etc.
      Returns:
      An Optional containing a Handler if any suitable methods were found; otherwise, an empty Optional.
    • hasLocalHandlers

      public boolean hasLocalHandlers()
      Description copied from interface: HasLocalHandlers
      Indicates whether any local handlers are currently registered for this gateway.
      Specified by:
      hasLocalHandlers in interface HasLocalHandlers
      Returns:
      true if local handlers are present, false otherwise
    • canSkipLocalHandling

      public boolean canSkipLocalHandling(io.fluxzero.common.MessageType messageType, Class<?> payloadType)
      Description copied from interface: HandlerRegistry
      Conservatively reports whether local handling can be skipped without first materializing a message.

      Custom registries default to false. Returning true is an explicit promise that invoking this registry cannot produce a local result for the supplied message shape.

      Specified by:
      canSkipLocalHandling in interface HandlerRegistry
      Parameters:
      messageType - the message type
      payloadType - the runtime payload type
      Returns:
      true only when local handling can safely be skipped
    • supportsDeferredExternalization

      public boolean supportsDeferredExternalization()
      Description copied from interface: HandlerRegistry
      Returns whether this registry supports messages whose external-only dispatch side effects are deferred until local handler selection has completed.

      The default is false to preserve the contract of custom registries. Fluxzero's local registry overrides this because its handler and dispatch interceptor chains coordinate deferred externalization.

      Specified by:
      supportsDeferredExternalization in interface HandlerRegistry
    • setSelfHandlerFilter

      public void setSelfHandlerFilter(io.fluxzero.common.handling.HandlerFilter selfHandlerFilter)
      Description copied from interface: HasLocalHandlers
      Sets a custom filter to control whether a handler method is considered a local handler for the current application. This is typically used internally to ensure that handlers are associated with the correct application or component.
      Specified by:
      setSelfHandlerFilter in interface HasLocalHandlers
      Parameters:
      selfHandlerFilter - a HandlerFilter to apply to registered handlers
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable