public override void Close()
        {
            IsClosed = true;
            log.Info($"{logPrefix}Closing");

            Suspend();

            foreach (var kp in processors)
            {
                kp.Close();
            }

            partitionGrouper.Close();

            collector.Close();
            CloseStateManager();
            log.Info($"{logPrefix}Closed");
        }
        public override void Close()
        {
            log.LogInformation($"{logPrefix}Closing");

            Suspend();

            if (state == TaskState.CREATED || state == TaskState.RESTORING || state == TaskState.RUNNING)
            {
                throw new IllegalStateException($"Illegal state {state} while closing active task {Id}");
            }
            else if (state == TaskState.CLOSED)
            {
                log.LogInformation($"{logPrefix}Skip closing since state is {state}");
                return;
            }
            else if (state == TaskState.SUSPENDED)
            {
                foreach (var kp in processors)
                {
                    kp.Close();
                }

                partitionGrouper.Close();

                collector.Close();
                CloseStateManager();

                TransitTo(TaskState.CLOSED);

                closeTaskSensor.Record();
                log.LogInformation($"{logPrefix}Closed");
                IsClosed = true;
            }
            else
            {
                throw new IllegalStateException($"Unknow state {state} while suspending active task {Id}");
            }

            streamMetricsRegistry.RemoveTaskSensors(threadId, Id.ToString());
        }