/** * Note: This is a private/internal method with package level access solely for testing purposes. * Update state based on information about: task success, current state, and shutdown info. * * @param taskOutcome The outcome of the last task */ void updateState(TaskOutcome taskOutcome) { if (taskOutcome == TaskOutcome.END_OF_SHARD) { markForShutdown(ShutdownReason.TERMINATE); } if (isShutdownRequested() && taskOutcome != TaskOutcome.FAILURE) { currentState = currentState.shutdownTransition(shutdownReason); } else if (taskOutcome == TaskOutcome.SUCCESSFUL) { if (currentState.getTaskType() == currentTask.getTaskType()) { currentState = currentState.successTransition(); } else { LOG.error("Current State task type of '" + currentState.getTaskType() + "' doesn't match the current tasks type of '" + currentTask.getTaskType() + "'. This shouldn't happen, and indicates a programming error. " + "Unable to safely transition to the next state."); } } // // Don't change state otherwise // }
/** * Figure out next task to run based on current state, task, and shutdown context. * * @return Return next task to run */ private ITask getNextTask() { ITask nextTask = currentState.createTask(this); if (nextTask == null) { return null; } else { return new MetricsCollectingTaskDecorator(nextTask, metricsFactory); } }
/** * Used (by Worker) to check if this ShardConsumer instance has been shutdown * RecordProcessor shutdown() has been invoked, as appropriate. * * @return true if shutdown is complete */ boolean isShutdown() { return currentState.isTerminal(); }
/** * Private/Internal method - has package level access solely for testing purposes. * * @return the currentState */ ConsumerStates.ShardConsumerState getCurrentState() { return currentState.getState(); }