예제 #1
0
        private void SetState(GlobalThreadState newState)
        {
            GlobalThreadState oldState;

            lock (stateLock)
            {
                oldState = State;

                if (oldState == GlobalThreadState.PENDING_SHUTDOWN && newState == GlobalThreadState.PENDING_SHUTDOWN)
                {
                    // when the state is already in PENDING_SHUTDOWN, its transition to itself
                    // will be refused but we do not throw exception here
                    return;
                }
                else if (oldState == GlobalThreadState.DEAD)
                {
                    // when the state is already in NOT_RUNNING, all its transitions
                    // will be refused but we do not throw exception here
                    return;
                }
                else if (!oldState.IsValidTransition(newState))
                {
                    log.Error($"{logPrefix}Unexpected state transition from {oldState} to {newState}");
                    throw new StreamsException($"Unexpected state transition from {oldState} to {newState}");
                }
                else
                {
                    log.Info($"{logPrefix}State transition from {oldState} to {newState}");
                }

                State = newState;
            }

            StateChanged?.Invoke(this, oldState, State);
        }
예제 #2
0
        public GlobalStreamThread(string threadClientId,
                                  IConsumer <byte[], byte[]> globalConsumer,
                                  IStreamConfig configuration,
                                  IGlobalStateMaintainer globalStateMaintainer)
        {
            logPrefix = $"global-stream-thread {threadClientId} ";

            this.globalConsumer        = globalConsumer;
            this.configuration         = configuration;
            this.globalStateMaintainer = globalStateMaintainer;

            thread = new Thread(Run);
            State  = GlobalThreadState.CREATED;
        }
예제 #3
0
        internal void OnGlobalThreadStateChange(GlobalStreamThread thread, IThreadStateTransitionValidator old, IThreadStateTransitionValidator @new)
        {
            lock (threadStatesLock)
            {
                if (thread != null)
                {
                    GlobalThreadState newState = (GlobalThreadState)@new;
                    globalThreadState = newState;

                    if (newState == GlobalThreadState.RUNNING)
                    {
                        MaybeSetRunning();
                    }
                    else if (newState == GlobalThreadState.DEAD && stream.SetState(KafkaStream.State.ERROR))
                    {
                        log.Error("Global thread has died. The instance will be in error state and should be closed.");
                    }
                }
            }
        }
 public StreamStateManager(KafkaStream stream, Dictionary <long, ThreadState> threadState, GlobalThreadState globalThreadState)
 {
     this.globalThreadState = globalThreadState;
     this.threadState       = threadState;
     this.stream            = stream;
 }