예제 #1
0
        private void GoToState(State state)
        {
//            _logger.Trace("CP: {projection} {stateFrom} => {stateTo}", _name, _state, state);
            var wasStopped  = _state == State.Stopped || _state == State.Faulted || _state == State.PhaseCompleted;
            var wasStopping = _state == State.Stopping || _state == State.FaultedStopping ||
                              _state == State.CompletingPhase;
            var wasStarting = _state == State.LoadStateRequested || _state == State.StateLoaded ||
                              _state == State.Subscribed;
            var wasStarted = _state == State.Subscribed || _state == State.Running || _state == State.Stopping ||
                             _state == State.FaultedStopping || _state == State.CompletingPhase;
            var wasRunning   = _state == State.Running;
            var stateChanged = _state != state;

            _state = state; // set state before transition to allow further state change
            switch (state)
            {
            case State.Stopped:
            case State.Faulted:
            case State.PhaseCompleted:
                if (wasStarted && !wasStopped)
                {
                    _checkpointManager.Stopped();
                }
                break;

            case State.Stopping:
            case State.FaultedStopping:
            case State.CompletingPhase:
                if (wasStarted && !wasStopping)
                {
                    _checkpointManager.Stopping();
                }
                break;
            }


            if (_projectionProcessingPhase != null) // null while loading state
            {
                switch (state)
                {
                case State.LoadStateRequested:
                case State.StateLoaded:
                case State.Subscribed:
                    if (!wasStarting)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Starting);
                    }
                    break;

                case State.Running:
                    if (!wasRunning)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Running);
                    }
                    break;

                case State.Faulted:
                case State.FaultedStopping:
                    if (wasRunning)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Stopped);
                    }
                    break;

                case State.Stopped:
                case State.Stopping:
                case State.CompletingPhase:
                case State.PhaseCompleted:
                    if (wasRunning)
                    {
                        _projectionProcessingPhase.SetProjectionState(PhaseState.Stopped);
                    }
                    break;

                default:
                    _projectionProcessingPhase.SetProjectionState(PhaseState.Unknown);
                    break;
                }
            }
            switch (state)
            {
            case State.Initial:
                EnterInitial();
                break;

            case State.StartSlaveProjectionsRequested:
                EnterStartSlaveProjectionsRequested();
                break;

            case State.LoadStateRequested:
                EnterLoadStateRequested();
                break;

            case State.StateLoaded:
                EnterStateLoaded();
                break;

            case State.Subscribed:
                EnterSubscribed();
                break;

            case State.Running:
                EnterRunning();
                break;

            case State.Stopping:
                EnterStopping();
                break;

            case State.Stopped:
                EnterStopped();
                break;

            case State.FaultedStopping:
                EnterFaultedStopping();
                break;

            case State.Faulted:
                EnterFaulted();
                break;

            case State.CompletingPhase:
                EnterCompletingPhase();
                break;

            case State.PhaseCompleted:
                EnterPhaseCompleted();
                break;

            default:
                throw new Exception();
            }
            if (stateChanged)
            {
                UpdateStatistics();
            }
        }
예제 #2
0
        private void GoToState(State state)
        {
            var wasStopped  = _state == State.Stopped || _state == State.Faulted;
            var wasStopping = _state == State.Stopping || _state == State.FaultedStopping;
            var wasStarted  = _state == State.StateLoadedSubscribed || _state == State.Paused || _state == State.Resumed ||
                              _state == State.Running || _state == State.Stopping || _state == State.FaultedStopping;

            _state = state; // set state before transition to allow further state change
            switch (state)
            {
            case State.Running:
                _processingQueue.SetRunning();
                break;

            case State.Paused:
                _processingQueue.SetPaused();
                break;

            default:
                _processingQueue.SetStopped();
                break;
            }
            switch (state)
            {
            case State.Stopped:
            case State.Faulted:
                if (wasStarted && !wasStopped)
                {
                    _checkpointManager.Stopped();
                }
                break;

            case State.Stopping:
            case State.FaultedStopping:
                if (wasStarted && !wasStopping)
                {
                    _checkpointManager.Stopping();
                }
                break;
            }
            switch (state)
            {
            case State.Initial:
                EnterInitial();
                break;

            case State.LoadStateRequsted:
                EnterLoadStateRequested();
                break;

            case State.StateLoadedSubscribed:
                EnterStateLoadedSubscribed();
                break;

            case State.Running:
                EnterRunning();
                break;

            case State.Paused:
                EnterPaused();
                break;

            case State.Resumed:
                EnterResumed();
                break;

            case State.Stopping:
                EnterStopping();
                break;

            case State.Stopped:
                EnterStopped();
                break;

            case State.FaultedStopping:
                EnterFaultedStopping();
                break;

            case State.Faulted:
                EnterFaulted();
                break;

            default:
                throw new Exception();
            }
        }