Esempio n. 1
0
        public void Handle(CoreProjectionManagementMessage.CreatePrepared message)
        {
            try
            {
                var name              = message.Name;
                var sourceDefinition  = ProjectionSourceDefinition.From(message.SourceDefinition);
                var projectionVersion = message.Version;
                var projectionConfig  = message.Config;
                var namesBuilder      = new ProjectionNamesBuilder(name, sourceDefinition);

                var projectionProcessingStrategy = _processingStrategySelector.CreateProjectionProcessingStrategy(
                    name,
                    projectionVersion,
                    namesBuilder,
                    sourceDefinition,
                    projectionConfig,
                    null,
                    message.HandlerType,
                    message.Query);

                CreateCoreProjection(message.ProjectionId, projectionConfig.RunAs, projectionProcessingStrategy);
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Prepared(
                        message.ProjectionId, sourceDefinition));
            }
            catch (Exception ex)
            {
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Faulted(message.ProjectionId, ex.Message));
            }
        }
        public void Handle(CoreProjectionManagementMessage.CreatePrepared message)
        {
            try
            {
                var name             = message.Name;
                var sourceDefinition = ProjectionSourceDefinition.From(
                    name, message.SourceDefinition, message.HandlerType, message.Query);
                var projectionVersion = message.Version;
                var projectionConfig  = message.Config;
                var namesBuilder      = new ProjectionNamesBuilder(name, sourceDefinition);

                var projectionProcessingStrategy = _processingStrategySelector.CreateProjectionProcessingStrategy(
                    name, projectionVersion, namesBuilder, sourceDefinition, projectionConfig, null, null);

                var slaveProjections = projectionProcessingStrategy.GetSlaveProjections();
                CreateCoreProjection(message.ProjectionId, projectionConfig.RunAs, projectionProcessingStrategy);
                message.Envelope.ReplyWith(
                    new CoreProjectionManagementMessage.Prepared(
                        message.ProjectionId, sourceDefinition, slaveProjections));
            }
            catch (Exception ex)
            {
                message.Envelope.ReplyWith(
                    new CoreProjectionManagementMessage.Faulted(message.ProjectionId, ex.Message));
            }
        }
Esempio n. 3
0
        private void BeginCreatePrepared(ProjectionConfig config, Action onPrepared)
        {
            _onPrepared = onPrepared;
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            //TODO: which states are allowed here?
            if (_state >= ManagedProjectionState.Preparing)
            {
                DisposeCoreProjection();
                _state = ManagedProjectionState.Loaded;
            }

            //TODO: load configuration from the definition

            if (_persistedState.SourceDefinition == null)
            {
                throw new Exception(
                          "The projection cannot be loaded as stopped as it was stored in the old format.  Update the projection query text to force prepare");
            }

            var createProjectionMessage =
                new CoreProjectionManagementMessage.CreatePrepared(
                    new PublishEnvelope(_inputQueue), Id, _name,
                    new ProjectionVersion(_projectionId, _persistedState.Epoch ?? 0, _persistedState.Version ?? 1),
                    config, _persistedState.SourceDefinition, HandlerType, Query);

            //note: set running before start as coreProjection.start() can respond with faulted
            _state = ManagedProjectionState.Preparing;
            _coreQueue.Publish(createProjectionMessage);
        }
Esempio n. 4
0
        private CoreProjectionManagementMessage.CreatePrepared CreateBeginCreatePreparedMessage(ProjectionConfig config)
        {
            if (_persistedState.SourceDefinition == null)
            {
                throw new Exception(
                          "The projection cannot be loaded as stopped as it was stored in the old format.  Update the projection query text to force prepare");
            }

            var createProjectionMessage = new CoreProjectionManagementMessage.CreatePrepared(
                Id,
                _workerId,
                _name,
                new ProjectionVersion(_projectionId, _persistedState.Epoch ?? 0, _persistedState.Version ?? 1),
                config,
                QuerySourcesDefinition.From(_persistedState.SourceDefinition),
                HandlerType,
                Query);

            return(createProjectionMessage);
        }
Esempio n. 5
0
 public void Handle(CoreProjectionManagementMessage.CreatePrepared message)
 {
     try
     {
         //TODO: factory method can throw!
         // constructor can fail if wrong source defintion
         ProjectionSourceDefinition sourceDefinition;
         var projection = CoreProjection.CreatePrepared(
             message.Name, message.Version, message.ProjectionId, _publisher, message.SourceDefinition, message.Config,
             _readDispatcher, _writeDispatcher, _subscriptionDispatcher, _logger, _timeProvider, out sourceDefinition);
         _projections.Add(message.ProjectionId, projection);
         message.Envelope.ReplyWith(
             new CoreProjectionManagementMessage.Prepared(message.ProjectionId, sourceDefinition));
     }
     catch (Exception ex)
     {
         message.Envelope.ReplyWith(
             new CoreProjectionManagementMessage.Faulted(message.ProjectionId, ex.Message));
     }
 }