public void Setup()
 {
     _consumer = new TestHandler<Message>();
     _bus = new InMemoryBus("temp");
     _bus.Subscribe(_consumer);
     ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
     var ioDispatcher = new IODispatcher(_bus, new PublishEnvelope(_bus));
     _readerService = new EventReaderCoreService(_bus, ioDispatcher, 10, writerCheckpoint, runHeadingReader: true);
     _subscriptionDispatcher =
         new ReaderSubscriptionDispatcher(_bus);
     _spoolProcessingResponseDispatcher = new SpooledStreamReadingDispatcher(_bus);
     _timeoutScheduler = new TimeoutScheduler();
     _workerId = Guid.NewGuid();
     _service = new ProjectionCoreService(
         _workerId, _bus, _bus, _subscriptionDispatcher, new RealTimeProvider(), ioDispatcher,
         _spoolProcessingResponseDispatcher, _timeoutScheduler);
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CheckpointSuggested>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CommittedEventReceived>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.EofReached>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionEofReached>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionMeasured>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionDeleted>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ProgressChanged>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.SubscriptionStarted>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.NotAuthorized>());
     _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ReaderAssignedReader>());
     _bus.Subscribe(_spoolProcessingResponseDispatcher.CreateSubscriber<PartitionProcessingResult>());
     _readerService.Handle(new Messages.ReaderCoreServiceMessage.StartReader());
     _service.Handle(new ProjectionCoreServiceMessage.StartCore());
 }
예제 #2
0
        public void Setup()
        {
            _consumer = new TestHandler <Message>();
            _bus      = new InMemoryBus("temp");
            _bus.Subscribe(_consumer);
            ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
            var         ioDispatcher     = new IODispatcher(_bus, new PublishEnvelope(_bus));

            _readerService          = new EventReaderCoreService(_bus, ioDispatcher, 10, writerCheckpoint, runHeadingReader: true);
            _subscriptionDispatcher =
                new ReaderSubscriptionDispatcher(_bus);
            _spoolProcessingResponseDispatcher = new SpooledStreamReadingDispatcher(_bus);
            _timeoutScheduler = new TimeoutScheduler();
            _workerId         = Guid.NewGuid();
            _service          = new ProjectionCoreService(
                _workerId, _bus, _bus, _subscriptionDispatcher, new RealTimeProvider(), ioDispatcher,
                _spoolProcessingResponseDispatcher, _timeoutScheduler);
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CheckpointSuggested>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CommittedEventReceived>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.EofReached>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionEofReached>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionMeasured>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionDeleted>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ProgressChanged>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.SubscriptionStarted>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.NotAuthorized>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ReaderAssignedReader>());
            _bus.Subscribe(_spoolProcessingResponseDispatcher.CreateSubscriber <PartitionProcessingResult>());
            _readerService.Handle(new Messages.ReaderCoreServiceMessage.StartReader());
            _service.Handle(new ProjectionCoreServiceMessage.StartCore());
        }
예제 #3
0
 public ManagedProjection(
     IPublisher coreQueue, Guid id, int projectionId, string name, bool enabledToRun, ILogger logger,
     RequestResponseDispatcher <ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
     RequestResponseDispatcher
     <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
     IPublisher inputQueue, IPublisher output, ProjectionStateHandlerFactory projectionStateHandlerFactory,
     ITimeProvider timeProvider, ISingletonTimeoutScheduler timeoutScheduler = null, bool isSlave = false,
     IPublisher slaveResultsPublisher = null, Guid slaveMasterCorrelationId = default(Guid))
 {
     if (coreQueue == null)
     {
         throw new ArgumentNullException("coreQueue");
     }
     if (id == Guid.Empty)
     {
         throw new ArgumentException("id");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (output == null)
     {
         throw new ArgumentNullException("output");
     }
     if (name == "")
     {
         throw new ArgumentException("name");
     }
     _coreQueue       = coreQueue;
     _id              = id;
     _projectionId    = projectionId;
     _name            = name;
     _enabledToRun    = enabledToRun;
     _logger          = logger;
     _writeDispatcher = writeDispatcher;
     _readDispatcher  = readDispatcher;
     _inputQueue      = inputQueue;
     _output          = output;
     _projectionStateHandlerFactory = projectionStateHandlerFactory;
     _timeProvider             = timeProvider;
     _timeoutScheduler         = timeoutScheduler;
     _isSlave                  = isSlave;
     _slaveResultsPublisher    = slaveResultsPublisher;
     _slaveMasterCorrelationId = slaveMasterCorrelationId;
     _getStateDispatcher       =
         new RequestResponseDispatcher
         <CoreProjectionManagementMessage.GetState, CoreProjectionManagementMessage.StateReport>(
             coreQueue, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_inputQueue));
     _getResultDispatcher =
         new RequestResponseDispatcher
         <CoreProjectionManagementMessage.GetResult, CoreProjectionManagementMessage.ResultReport>(
             coreQueue, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_inputQueue));
     _lastAccessed = _timeProvider.Now;
 }
예제 #4
0
        public ProjectionWorkerNode(
            Guid workerId,
            TFChunkDb db,
            IQueuedHandler inputQueue,
            ITimeProvider timeProvider,
            ISingletonTimeoutScheduler timeoutScheduler,
            ProjectionType runProjections,
            bool faultOutOfOrderProjections)
        {
            _runProjections = runProjections;
            Ensure.NotNull(db, "db");

            _coreOutput = new InMemoryBus("Core Output");

            IPublisher publisher = CoreOutput;

            _subscriptionDispatcher            = new ReaderSubscriptionDispatcher(publisher);
            _spoolProcessingResponseDispatcher = new SpooledStreamReadingDispatcher(publisher);

            _ioDispatcher           = new IODispatcher(publisher, new PublishEnvelope(inputQueue));
            _eventReaderCoreService = new EventReaderCoreService(
                publisher,
                _ioDispatcher,
                10,
                db.Config.WriterCheckpoint,
                runHeadingReader: runProjections >= ProjectionType.System,
                faultOutOfOrderProjections: faultOutOfOrderProjections);

            _feedReaderService = new FeedReaderService(_subscriptionDispatcher, timeProvider);
            if (runProjections >= ProjectionType.System)
            {
                _projectionCoreServiceCommandReader = new ProjectionCoreServiceCommandReader(
                    publisher,
                    _ioDispatcher,
                    workerId.ToString("N"));

                var multiStreamWriter = new MultiStreamMessageWriter(_ioDispatcher);
                _slaveProjectionResponseWriter = new SlaveProjectionResponseWriter(multiStreamWriter);

                _projectionCoreService = new ProjectionCoreService(
                    workerId,
                    inputQueue,
                    publisher,
                    _subscriptionDispatcher,
                    timeProvider,
                    _ioDispatcher,
                    _spoolProcessingResponseDispatcher,
                    timeoutScheduler);

                var responseWriter = new ResponseWriter(_ioDispatcher);
                _coreResponseWriter = new ProjectionCoreResponseWriter(responseWriter);
            }
        }
예제 #5
0
        public ProjectionWorkerNode(
            Guid workerId,
            TFChunkDb db,
            QueuedHandler inputQueue,
            ITimeProvider timeProvider,
            ISingletonTimeoutScheduler timeoutScheduler,
            ProjectionType runProjections)
        {
            _runProjections = runProjections;
            Ensure.NotNull(db, "db");

            _coreOutput = new InMemoryBus("Core Output");

            IPublisher publisher = CoreOutput;
            _subscriptionDispatcher = new ReaderSubscriptionDispatcher(publisher);
            _spoolProcessingResponseDispatcher = new SpooledStreamReadingDispatcher(publisher);

            _ioDispatcher = new IODispatcher(publisher, new PublishEnvelope(inputQueue));
            _eventReaderCoreService = new EventReaderCoreService(
                publisher,
                _ioDispatcher,
                10,
                db.Config.WriterCheckpoint,
                runHeadingReader: runProjections >= ProjectionType.System);

            _feedReaderService = new FeedReaderService(_subscriptionDispatcher, timeProvider);
            if (runProjections >= ProjectionType.System)
            {
                _projectionCoreServiceCommandReader = new ProjectionCoreServiceCommandReader(
                    publisher,
                    _ioDispatcher,
                    workerId.ToString("N"));

                var multiStreamWriter = new MultiStreamMessageWriter(_ioDispatcher);
                _slaveProjectionResponseWriter = new SlaveProjectionResponseWriter(multiStreamWriter);

                _projectionCoreService = new ProjectionCoreService(
                    workerId,
                    inputQueue,
                    publisher,
                    _subscriptionDispatcher,
                    timeProvider,
                    _ioDispatcher,
                    _spoolProcessingResponseDispatcher,
                    timeoutScheduler);

                var responseWriter = new ResponseWriter(_ioDispatcher);
                _coreResponseWriter = new ProjectionCoreResponseWriter(responseWriter);
            }
        }
예제 #6
0
        public static IProjectionStateHandler CreateStateHandler(
            ISingletonTimeoutScheduler singletonTimeoutScheduler,
            ILogger logger,
            string handlerType,
            string query)
        {
            var stateHandler = new ProjectionStateHandlerFactory().Create(
                handlerType,
                query,
                logger: logger.Trace,
                cancelCallbackFactory:
                singletonTimeoutScheduler == null ? (Action <int, Action>)null : singletonTimeoutScheduler.Schedule);

            return(stateHandler);
        }
예제 #7
0
        public static IProjectionStateHandler CreateStateHandler(ProjectionStateHandlerFactory factory,
                                                                 ISingletonTimeoutScheduler singletonTimeoutScheduler,
                                                                 ILogger logger,
                                                                 string handlerType,
                                                                 string query,
                                                                 bool enableContentTypeValidation)
        {
            var stateHandler = factory.Create(
                handlerType,
                query,
                enableContentTypeValidation,
                logger: logger.Verbose,
                cancelCallbackFactory:
                singletonTimeoutScheduler == null ? null : singletonTimeoutScheduler.Schedule);

            return(stateHandler);
        }
예제 #8
0
 public ProjectionCoreService(
     Guid workerId,
     IPublisher inputQueue,
     IPublisher publisher,
     ReaderSubscriptionDispatcher subscriptionDispatcher,
     ITimeProvider timeProvider,
     IODispatcher ioDispatcher,
     ISingletonTimeoutScheduler timeoutScheduler)
 {
     _workerId                   = workerId;
     _inputQueue                 = inputQueue;
     _publisher                  = publisher;
     _ioDispatcher               = ioDispatcher;
     _timeoutScheduler           = timeoutScheduler;
     _subscriptionDispatcher     = subscriptionDispatcher;
     _timeProvider               = timeProvider;
     _processingStrategySelector = new ProcessingStrategySelector(_subscriptionDispatcher);
 }
예제 #9
0
        public ProjectionWorkerNode(
            Guid workerId,
            TFChunkDb db,
            IQueuedHandler inputQueue,
            ITimeProvider timeProvider,
            ISingletonTimeoutScheduler timeoutScheduler,
            ProjectionType runProjections,
            bool faultOutOfOrderProjections,
            IPublisher leaderOutputBus,
            ProjectionsStandardComponents configuration)
        {
            _runProjections = runProjections;
            Ensure.NotNull(db, "db");

            _coreOutput      = new InMemoryBus("Core Output");
            _leaderOutputBus = leaderOutputBus;

            IPublisher publisher = CoreOutput;

            _subscriptionDispatcher = new ReaderSubscriptionDispatcher(publisher);

            _ioDispatcher           = new IODispatcher(publisher, new PublishEnvelope(inputQueue), true);
            _eventReaderCoreService = new EventReaderCoreService(
                publisher,
                _ioDispatcher,
                10,
                db.Config.WriterCheckpoint,
                runHeadingReader: runProjections >= ProjectionType.System,
                faultOutOfOrderProjections: faultOutOfOrderProjections);

            _feedReaderService = new FeedReaderService(_subscriptionDispatcher, timeProvider);
            if (runProjections >= ProjectionType.System)
            {
                _projectionCoreService = new ProjectionCoreService(
                    workerId,
                    inputQueue,
                    publisher,
                    _subscriptionDispatcher,
                    timeProvider,
                    _ioDispatcher,
                    timeoutScheduler,
                    configuration);
            }
        }
예제 #10
0
 public ProjectionCoreService(
     Guid workerId,
     IPublisher inputQueue,
     IPublisher publisher,
     ReaderSubscriptionDispatcher subscriptionDispatcher,
     ITimeProvider timeProvider,
     IODispatcher ioDispatcher,
     ISingletonTimeoutScheduler timeoutScheduler, ProjectionsStandardComponents configuration)
 {
     _workerId                   = workerId;
     _inputQueue                 = inputQueue;
     _publisher                  = publisher;
     _ioDispatcher               = ioDispatcher;
     _timeoutScheduler           = timeoutScheduler;
     _subscriptionDispatcher     = subscriptionDispatcher;
     _timeProvider               = timeProvider;
     _processingStrategySelector = new ProcessingStrategySelector(_subscriptionDispatcher);
     _factory = new ProjectionStateHandlerFactory(TimeSpan.FromMilliseconds(configuration.ProjectionCompilationTimeout),
                                                  TimeSpan.FromMilliseconds(configuration.ProjectionExecutionTimeout), configuration.ProjectionRuntime);
 }
예제 #11
0
        public virtual void Setup()
        {
            _consumer = new TestHandler <Message>();
            _bus      = new InMemoryBus("temp");
            _bus.Subscribe(_consumer);
            ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
            var         ioDispatcher     = new IODispatcher(_bus, new PublishEnvelope(_bus), true);

            _readerService = new EventReaderCoreService(_bus, ioDispatcher, 10, writerCheckpoint,
                                                        runHeadingReader: true, faultOutOfOrderProjections: true);
            _subscriptionDispatcher =
                new ReaderSubscriptionDispatcher(_bus);
            _timeoutScheduler = new TimeoutScheduler();
            _workerId         = Guid.NewGuid();
            var guardBus      = new GuardBusToTriggerFixingIfUsed();
            var configuration = new ProjectionsStandardComponents(1, ProjectionType.All, guardBus, guardBus, guardBus, true,
                                                                  500, 250);

            _service = new ProjectionCoreService(
                _workerId, _bus, _bus, _subscriptionDispatcher, new RealTimeProvider(), ioDispatcher, _timeoutScheduler, configuration);
            _bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CheckpointSuggested>());
            _bus.Subscribe(_subscriptionDispatcher
                           .CreateSubscriber <EventReaderSubscriptionMessage.CommittedEventReceived>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.EofReached>());
            _bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionEofReached>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionDeleted>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ProgressChanged>());
            _bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.SubscriptionStarted>());
            _bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.NotAuthorized>());
            _bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ReaderAssignedReader>());

            var instanceCorrelationId = Guid.NewGuid();

            _readerService.Handle(new ReaderCoreServiceMessage.StartReader(instanceCorrelationId));
            _service.Handle(new ProjectionCoreServiceMessage.StartCore(instanceCorrelationId));
        }
        private void SetUpCoreServices(
            Guid workerId,
            IBus bus,
            IPublisher inputQueue,
            InMemoryBus output_,
            ISingletonTimeoutScheduler timeoutScheduler)
        {
            var output = (output_ ?? inputQueue);
            ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
            var readerService = new EventReaderCoreService(
                output,
                _ioDispatcher,
                10,
                writerCheckpoint,
                runHeadingReader: true);
            _subscriptionDispatcher = new ReaderSubscriptionDispatcher(inputQueue);
            var spoolProcessingResponseDispatcher = new SpooledStreamReadingDispatcher(GetInputQueue());

            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CheckpointSuggested>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.CommittedEventReceived>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.EofReached>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionEofReached>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionMeasured>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.PartitionDeleted>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ProgressChanged>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.SubscriptionStarted>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.NotAuthorized>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber<EventReaderSubscriptionMessage.ReaderAssignedReader>());
            bus.Subscribe(spoolProcessingResponseDispatcher.CreateSubscriber<PartitionProcessingResult>());

            var ioDispatcher = new IODispatcher(output, new PublishEnvelope(inputQueue));
//            var coreServiceCommandReader = new ProjectionCoreServiceCommandReader(
//                output,
//                ioDispatcher,
//                workerId.ToString("N"));

            var coreService = new ProjectionCoreService(
                workerId,
                inputQueue,
                output,
                _subscriptionDispatcher,
                _timeProvider,
                ioDispatcher,
                spoolProcessingResponseDispatcher,
                timeoutScheduler);

            bus.Subscribe<CoreProjectionManagementMessage.CreateAndPrepare>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.CreatePrepared>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.CreateAndPrepareSlave>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.Dispose>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.Start>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.LoadStopped>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.Stop>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.Kill>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.GetState>(coreService);
            bus.Subscribe<CoreProjectionManagementMessage.GetResult>(coreService);
            bus.Subscribe<CoreProjectionProcessingMessage.CheckpointCompleted>(coreService);
            bus.Subscribe<CoreProjectionProcessingMessage.CheckpointLoaded>(coreService);
            bus.Subscribe<CoreProjectionProcessingMessage.PrerecordedEventsLoaded>(coreService);
            bus.Subscribe<CoreProjectionProcessingMessage.RestartRequested>(coreService);
            bus.Subscribe<CoreProjectionProcessingMessage.Failed>(coreService);
            bus.Subscribe<ClientMessage.ReadStreamEventsForwardCompleted>(ioDispatcher.ForwardReader);
            bus.Subscribe<ClientMessage.ReadStreamEventsBackwardCompleted>(ioDispatcher.BackwardReader);
            bus.Subscribe<ClientMessage.WriteEventsCompleted>(ioDispatcher.Writer);
            bus.Subscribe<ClientMessage.DeleteStreamCompleted>(ioDispatcher.StreamDeleter);
            bus.Subscribe<IODispatcherDelayedMessage>(ioDispatcher.Awaker);
            bus.Subscribe<IODispatcherDelayedMessage>(ioDispatcher);
            bus.Subscribe<ProjectionCoreServiceMessage.StartCore>(coreService);
            bus.Subscribe<ProjectionCoreServiceMessage.StopCore>(coreService);
            bus.Subscribe<ReaderCoreServiceMessage.StartReader>(readerService);
            bus.Subscribe<ReaderCoreServiceMessage.StopReader>(readerService);
            bus.Subscribe<ProjectionCoreServiceMessage.CoreTick>(coreService);
            bus.Subscribe<ProjectionManagementMessage.SlaveProjectionsStarted>(coreService);
            bus.Subscribe<ReaderCoreServiceMessage.ReaderTick>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.CommittedEventDistributed>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderEof>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderPartitionEof>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderPartitionDeleted>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderPartitionMeasured>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderNotAuthorized>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderIdle>(readerService);
            bus.Subscribe<ReaderSubscriptionMessage.EventReaderStarting>(readerService);
            bus.Subscribe<ReaderSubscriptionManagement.Pause>(readerService);
            bus.Subscribe<ReaderSubscriptionManagement.Resume>(readerService);
            bus.Subscribe<ReaderSubscriptionManagement.Subscribe>(readerService);
            bus.Subscribe<ReaderSubscriptionManagement.Unsubscribe>(readerService);
            bus.Subscribe<ReaderSubscriptionManagement.SpoolStreamReadingCore>(readerService);
            bus.Subscribe<ReaderSubscriptionManagement.CompleteSpooledStreamReading>(readerService);

            if (output_ != null)
            {
                bus.Subscribe(new UnwrapEnvelopeHandler());
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.StateReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.ResultReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.StatisticsReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.Started>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.Stopped>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.Faulted>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.Prepared>(GetInputQueue()));
                output_.Subscribe(
                    Forwarder.Create<CoreProjectionManagementMessage.SlaveProjectionReaderAssigned>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<CoreProjectionStatusMessage.ProjectionWorkerStarted>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<ProjectionManagementMessage.Command.ControlMessage>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<AwakeServiceMessage.SubscribeAwake>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<AwakeServiceMessage.UnsubscribeAwake>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<PartitionProcessingResultBase>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<ReaderSubscriptionManagement.SpoolStreamReading>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<PartitionProcessingResultOutputBase>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create<Message>(inputQueue)); // forward all

                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: inputQueue,
                    externalRequestQueue: GetInputQueue());
                // forwarded messages
                output_.Subscribe<ClientMessage.ReadEvent>(forwarder);
                output_.Subscribe<ClientMessage.ReadStreamEventsBackward>(forwarder);
                output_.Subscribe<ClientMessage.ReadStreamEventsForward>(forwarder);
                output_.Subscribe<ClientMessage.ReadAllEventsForward>(forwarder);
                output_.Subscribe<ClientMessage.WriteEvents>(forwarder);

            }
        }
        private void SetUpCoreServices(
            Guid workerId,
            IBus bus,
            IPublisher inputQueue,
            InMemoryBus output_,
            ISingletonTimeoutScheduler timeoutScheduler)
        {
            var         output           = (output_ ?? inputQueue);
            ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
            var         readerService    = new EventReaderCoreService(
                output,
                _ioDispatcher,
                10,
                writerCheckpoint,
                runHeadingReader: true, faultOutOfOrderProjections: true);

            _subscriptionDispatcher = new ReaderSubscriptionDispatcher(inputQueue);

            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CheckpointSuggested>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CommittedEventReceived>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.EofReached>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionEofReached>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionDeleted>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ProgressChanged>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.SubscriptionStarted>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.NotAuthorized>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ReaderAssignedReader>());

            var ioDispatcher = new IODispatcher(output, new PublishEnvelope(inputQueue), true);
//            var coreServiceCommandReader = new ProjectionCoreServiceCommandReader(
//                output,
//                ioDispatcher,
//                workerId.ToString("N"));

            var coreService = new ProjectionCoreService(
                workerId,
                inputQueue,
                output,
                _subscriptionDispatcher,
                _timeProvider,
                ioDispatcher,
                timeoutScheduler);

            bus.Subscribe <CoreProjectionManagementMessage.CreateAndPrepare>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.CreatePrepared>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Dispose>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Start>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.LoadStopped>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Stop>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Kill>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.GetState>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.GetResult>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.CheckpointCompleted>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.CheckpointLoaded>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.PrerecordedEventsLoaded>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.RestartRequested>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.Failed>(coreService);
            bus.Subscribe <ClientMessage.ReadStreamEventsForwardCompleted>(ioDispatcher.ForwardReader);
            bus.Subscribe <ClientMessage.ReadStreamEventsBackwardCompleted>(ioDispatcher.BackwardReader);
            bus.Subscribe <ClientMessage.WriteEventsCompleted>(ioDispatcher.Writer);
            bus.Subscribe <ClientMessage.DeleteStreamCompleted>(ioDispatcher.StreamDeleter);
            bus.Subscribe <IODispatcherDelayedMessage>(ioDispatcher.Awaker);
            bus.Subscribe <IODispatcherDelayedMessage>(ioDispatcher);
            bus.Subscribe <ProjectionCoreServiceMessage.StartCore>(coreService);
            bus.Subscribe <ProjectionCoreServiceMessage.StopCore>(coreService);
            bus.Subscribe <ReaderCoreServiceMessage.StartReader>(readerService);
            bus.Subscribe <ReaderCoreServiceMessage.StopReader>(readerService);
            bus.Subscribe <ProjectionCoreServiceMessage.CoreTick>(coreService);
            bus.Subscribe <ReaderSubscriptionMessage.CommittedEventDistributed>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderEof>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderPartitionEof>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderPartitionDeleted>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderNotAuthorized>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderIdle>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderStarting>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Pause>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Resume>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Subscribe>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Unsubscribe>(readerService);

            if (output_ != null)
            {
                bus.Subscribe(new UnwrapEnvelopeHandler());
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.StateReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.ResultReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.StatisticsReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Started>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Stopped>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Faulted>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Prepared>(GetInputQueue()));
                output_.Subscribe(
                    Forwarder.Create <ProjectionManagementMessage.Command.ControlMessage>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <AwakeServiceMessage.SubscribeAwake>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <AwakeServiceMessage.UnsubscribeAwake>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <Message>(inputQueue));                // forward all

                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: inputQueue,
                    externalRequestQueue: GetInputQueue());
                // forwarded messages
                output_.Subscribe <ClientMessage.ReadEvent>(forwarder);
                output_.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                output_.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                output_.Subscribe <ClientMessage.ReadAllEventsForward>(forwarder);
                output_.Subscribe <ClientMessage.WriteEvents>(forwarder);
            }
        }
예제 #14
0
 public ManagedProjection(
     IPublisher coreQueue, Guid id, int projectionId, string name, bool enabledToRun, ILogger logger,
     RequestResponseDispatcher<ClientMessage.WriteEvents, ClientMessage.WriteEventsCompleted> writeDispatcher,
     RequestResponseDispatcher
         <ClientMessage.ReadStreamEventsBackward, ClientMessage.ReadStreamEventsBackwardCompleted> readDispatcher,
     IPublisher inputQueue, IPublisher output, ProjectionStateHandlerFactory projectionStateHandlerFactory,
     ITimeProvider timeProvider, ISingletonTimeoutScheduler timeoutScheduler = null, bool isSlave = false,
     IPublisher slaveResultsPublisher = null, Guid slaveMasterCorrelationId = default(Guid))
 {
     if (coreQueue == null) throw new ArgumentNullException("coreQueue");
     if (id == Guid.Empty) throw new ArgumentException("id");
     if (name == null) throw new ArgumentNullException("name");
     if (output == null) throw new ArgumentNullException("output");
     if (name == "") throw new ArgumentException("name");
     _coreQueue = coreQueue;
     _id = id;
     _projectionId = projectionId;
     _name = name;
     _enabledToRun = enabledToRun;
     _logger = logger;
     _writeDispatcher = writeDispatcher;
     _readDispatcher = readDispatcher;
     _inputQueue = inputQueue;
     _output = output;
     _projectionStateHandlerFactory = projectionStateHandlerFactory;
     _timeProvider = timeProvider;
     _timeoutScheduler = timeoutScheduler;
     _isSlave = isSlave;
     _slaveResultsPublisher = slaveResultsPublisher;
     _slaveMasterCorrelationId = slaveMasterCorrelationId;
     _getStateDispatcher =
         new RequestResponseDispatcher
             <CoreProjectionManagementMessage.GetState, CoreProjectionManagementMessage.StateReport>(
             coreQueue, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_inputQueue));
     _getResultDispatcher =
         new RequestResponseDispatcher
             <CoreProjectionManagementMessage.GetResult, CoreProjectionManagementMessage.ResultReport>(
             coreQueue, v => v.CorrelationId, v => v.CorrelationId, new PublishEnvelope(_inputQueue));
     _lastAccessed = _timeProvider.Now;
 }