Ejemplo n.º 1
0
 public CommittedEventWorkItem(
     CoreProjection projection, ProjectionSubscriptionMessage.CommittedEventReceived message, string partition)
     : base(projection, message.EventStreamId)
 {
     _message   = message;
     _partition = partition;
 }
Ejemplo n.º 2
0
 internal void ProcessCommittedEvent(
     CommittedEventWorkItem committedEventWorkItem, ProjectionSubscriptionMessage.CommittedEventReceived message,
     string partition)
 {
     EnsureState(State.Running);
     InternalProcessCommittedEvent(committedEventWorkItem, partition, message);
 }
Ejemplo n.º 3
0
        public void Handle(ProjectionSubscriptionMessage.CommittedEventReceived message)
        {
            if (IsOutOfOrderSubscriptionMessage(message))
            {
                return;
            }
            RegisterSubscriptionMessage(message);

            EnsureState(
                State.Running | State.Paused | State.Stopping | State.Stopped | State.FaultedStopping | State.Faulted);
            try
            {
                if (_state == State.Running || _state == State.Paused)
                {
                    CheckpointTag eventTag  = message.CheckpointTag;
                    string        partition = _checkpointStrategy.StatePartitionSelector.GetStatePartition(message);
                    var           committedEventWorkItem = new CommittedEventWorkItem(this, message, partition);
                    _processingQueue.EnqueueTask(committedEventWorkItem, eventTag);
                }
                _processingQueue.ProcessEvent();
            }
            catch (Exception ex)
            {
                SetFaulted(ex);
            }
        }
Ejemplo n.º 4
0
 private bool ProcessEventByHandler(
     string partition, ProjectionSubscriptionMessage.CommittedEventReceived message, out string newState,
     out EmittedEvent[] emittedEvents)
 {
     SetHandlerState(partition);
     return(_projectionStateHandler.ProcessEvent(
                message.Position, message.CheckpointTag, message.EventStreamId, message.Data.EventType,
                message.EventCategory, message.Data.EventId, message.EventSequenceNumber,
                Encoding.UTF8.GetString(message.Data.Metadata), Encoding.UTF8.GetString(message.Data.Data), out newState,
                out emittedEvents));
 }
Ejemplo n.º 5
0
        private void InternalProcessCommittedEvent(
            CommittedEventWorkItem committedEventWorkItem, string partition,
            ProjectionSubscriptionMessage.CommittedEventReceived message)
        {
            string newState = null;

            EmittedEvent[] emittedEvents = null;

            //TODO: not emitting (optimized) projection handlers can skip serializing state on each processed event
            bool hasBeenProcessed;

            try
            {
                hasBeenProcessed = ProcessEventByHandler(partition, message, out newState, out emittedEvents);
            }
            catch (Exception ex)
            {
                ProcessEventFaulted(
                    string.Format(
                        "The {0} projection failed to process an event.\r\nHandler: {1}\r\nEvent Position: {2}\r\n\r\nMessage:\r\n\r\n{3}",
                        _name, GetHandlerTypeName(), message.Position, ex.Message), ex);
                newState         = null;
                emittedEvents    = null;
                hasBeenProcessed = false;
            }
            newState = newState ?? "";
            if (hasBeenProcessed)
            {
                if (!ProcessEmittedEvents(committedEventWorkItem, emittedEvents))
                {
                    return;
                }

                var oldState = _partitionStateCache.GetLockedPartitionState(partition);
                if (oldState.Data != newState)
                // ensure state actually changed
                {
                    var lockPartitionStateAt = partition != "" ? message.CheckpointTag : null;
                    _partitionStateCache.CacheAndLockPartitionState(partition, new PartitionStateCache.State(newState, message.CheckpointTag), lockPartitionStateAt);
                    if (_projectionConfig.PublishStateUpdates)
                    {
                        EmitStateUpdated(committedEventWorkItem, partition, newState, message.CheckpointTag, oldState.CausedBy);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public abstract string GetStatePartition(ProjectionSubscriptionMessage.CommittedEventReceived @event);
Ejemplo n.º 7
0
 public void Handle(ProjectionSubscriptionMessage.CommittedEventReceived message)
 {
     _committedEventReceivedMessages.Add(message);
 }
 public override string GetStatePartition(ProjectionSubscriptionMessage.CommittedEventReceived @event)
 {
     return(@event.EventStreamId);
 }