internal void ProcessCommittedEvent( CommittedEventWorkItem committedEventWorkItem, ProjectionSubscriptionMessage.CommittedEventReceived message, string partition) { EnsureState(State.Running); InternalProcessCommittedEvent(committedEventWorkItem, partition, message); }
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); } }
private void EmitStateUpdated(CommittedEventWorkItem committedEventWorkItem, string partition, string newState) { committedEventWorkItem.ScheduleEmitEvents( new[] { new EmittedEvent(MakePartitionStateStreamName(partition), Guid.NewGuid(), "StateUpdated", newState) }); }
private void EmitStateUpdated(CommittedEventWorkItem committedEventWorkItem, string partition, string newState, CheckpointTag eventTag, CheckpointTag expectedTag) { committedEventWorkItem.ScheduleEmitEvents( new[] { new EmittedEvent(MakePartitionStateStreamName(partition), Guid.NewGuid(), "StateUpdated", newState, eventTag, expectedTag) }); }
private void EmitEmittedEvents(CommittedEventWorkItem committedEventWorkItem, EmittedEvent[] emittedEvents) { bool result = emittedEvents != null && emittedEvents.Length > 0; if (result) { committedEventWorkItem.ScheduleEmitEvents(emittedEvents); } }
private void ProcessCommittedEvent( CommittedEventWorkItem committedEventWorkItem, ProjectionMessage.Projections.CommittedEventReceived message, string partition) { if (message.Data == null) { throw new NotSupportedException(); } EnsureState(State.Running); InternalProcessCommittedEvent(committedEventWorkItem, partition, message); }
private bool ProcessEmittedEvents(CommittedEventWorkItem committedEventWorkItem, EmittedEvent[] emittedEvents) { if (_projectionConfig.EmitEventEnabled) { EmitEmittedEvents(committedEventWorkItem, emittedEvents); } else if (emittedEvents != null && emittedEvents.Length > 0) { ProcessEventFaulted("emit_event is not enabled by the projection configuration/mode"); return(false); } return(true); }
private bool ProcessEmittedEvents(CommittedEventWorkItem committedEventWorkItem, EmittedEvent[] emittedEvents) { if (_projectionConfig.EmitEventEnabled && _checkpointStrategy.IsEmiEnabled()) { EmitEmittedEvents(committedEventWorkItem, emittedEvents); } else if (emittedEvents != null && emittedEvents.Length > 0) { ProcessEventFaulted("'emit' is not allowed by the projection/configuration/mode"); return(false); } return(true); }
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); } } } }
private void InternalProcessCommittedEvent( CommittedEventWorkItem committedEventWorkItem, string partition, ProjectionMessage.Projections.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 { bool passedFilter = EventPassesFilter(message); hasBeenProcessed = passedFilter && ProcessEventByHandler(partition, message, out newState, out emittedEvents); } catch (Exception ex) { ProcessEventFaulted(message, ex); newState = null; emittedEvents = null; hasBeenProcessed = false; } newState = newState ?? ""; if (hasBeenProcessed) { if (_projectionConfig.EmitEventEnabled) { EmitEmittedEvents(committedEventWorkItem, emittedEvents); } if (_partitionStateCache.GetLockedPartitionState(partition) != newState) // ensure state actually changed { var lockPartitionStateAt = partition != "" ? _checkpointStrategy.PositionTagger.MakeCheckpointTag(message) : null; _partitionStateCache.CacheAndLockPartitionState(partition, newState, lockPartitionStateAt); if (_projectionConfig.PublishStateUpdates) { EmitStateUpdated(committedEventWorkItem, partition, newState); } } } }
public void Handle(EventReaderSubscriptionMessage.CommittedEventReceived message) { //TODO: make sure this is no longer required : if (_state != State.StateLoaded) if (IsOutOfOrderSubscriptionMessage(message)) { return; } RegisterSubscriptionMessage(message); try { CheckpointTag eventTag = message.CheckpointTag; var committedEventWorkItem = new CommittedEventWorkItem(this, message, _statePartitionSelector); _processingQueue.EnqueueTask(committedEventWorkItem, eventTag); if (_state == PhaseState.Running) // prevent processing mostly one projection { EnsureTickPending(); } } catch (Exception ex) { _coreProjection.SetFaulted(ex); } }