public void Handle(ProjectionMessage.CoreService.Management.Create message)
 {
     try
     {
         //TODO: factory method can throw!
         IProjectionStateHandler stateHandler = message.HandlerFactory();
         // constructor can fail if wrong source defintion
         //TODO: revise it
         var projection = new CoreProjection(message.Name, message.CorrelationId, _publisher, stateHandler, message.Config, _readDispatcher, _writeDispatcher, _logger);
         _projections.Add(message.CorrelationId, projection);
     }
     catch (Exception ex)
     {
         message.Envelope.ReplyWith(new ProjectionMessage.Projections.StatusReport.Faulted(message.CorrelationId, ex.Message));
     }
 }
Beispiel #2
0
        private void Start(ProjectionStateHandlerFactory handlerFactory, ProjectionConfig config)
        {
            if (handlerFactory == null)
            {
                throw new ArgumentNullException("handlerFactory");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (_state == ManagedProjectionState.Running)
            {
                throw new InvalidOperationException("Already started");
            }

            //TODO: load configuration from the definition


            var createProjectionMessage = new ProjectionMessage.CoreService.Management.Create(new PublishEnvelope(_inputQueue), _id, _name, config, delegate
            {
                IProjectionStateHandler stateHandler = null;
                try
                {
                    stateHandler = handlerFactory.Create(this.HandlerType, this.Query, Console.WriteLine);
                    var checkpointStrategyBuilder = new CheckpointStrategy.Builder();
                    stateHandler.ConfigureSourceProcessingStrategy(checkpointStrategyBuilder);
                    checkpointStrategyBuilder.Validate(Mode);     // avoid future exceptions in coreprojection
                    return(stateHandler);
                }
                catch (Exception ex)
                {
                    SetFaulted(String.Format("Cannot create a projection state handler.\r\n\r\nHandler type: {0}\r\nQuery:\r\n\r\n{1}\r\n\r\nMessage:\r\n\r\n{2}", HandlerType, Query, ex.Message), ex);
                    if (stateHandler != null)
                    {
                        stateHandler.Dispose();
                    }
                    throw;
                }
            });

            //note: set runnign before start as coreProjection.start() can respond with faulted
            _state = ManagedProjectionState.Running;
            _coreQueue.Publish(createProjectionMessage);
            _coreQueue.Publish(new ProjectionMessage.Projections.Management.Start(_id));
        }
Beispiel #3
0
        private void Start(ProjectionStateHandlerFactory handlerFactory, ProjectionConfig config)
        {
            if (handlerFactory == null) throw new ArgumentNullException("handlerFactory");
            if (config == null) throw new ArgumentNullException("config");

            if (_state == ManagedProjectionState.Running)
                throw new InvalidOperationException("Already started");

            //TODO: load configuration from the definition

            var createProjectionMessage = new ProjectionMessage.CoreService.Management.Create(new PublishEnvelope(_inputQueue), _id, _name, config, delegate
                {
                    IProjectionStateHandler stateHandler = null;
                    try
                    {
                        stateHandler = handlerFactory.Create(this.HandlerType, this.Query, Console.WriteLine);
                        var checkpointStrategyBuilder = new CheckpointStrategy.Builder();
                        stateHandler.ConfigureSourceProcessingStrategy(checkpointStrategyBuilder);
                        checkpointStrategyBuilder.Validate(Mode); // avoid future exceptions in coreprojection
                        return stateHandler;
                    }
                    catch (Exception ex)
                    {
                        SetFaulted(String.Format("Cannot create a projection state handler.\r\n\r\nHandler type: {0}\r\nQuery:\r\n\r\n{1}\r\n\r\nMessage:\r\n\r\n{2}", HandlerType, Query, ex.Message), ex);
                        if (stateHandler != null)
                            stateHandler.Dispose();
                        throw;
                    }
                });

            //note: set runnign before start as coreProjection.start() can respond with faulted
            _state = ManagedProjectionState.Running;
            _coreQueue.Publish(createProjectionMessage);
            _coreQueue.Publish(new ProjectionMessage.Projections.Management.Start(_id));
        }