Source:
private JobCoordinatorListener createJobCoordinatorListener() { return new JobCoordinatorListener() { @Override public void onJobModelExpired() { synchronized (lock) { if (state == State.STARTED || state == State.RUNNING) { state = State.IN_REBALANCE; LOGGER.info("Job model expired. Shutting down the container: of stream processor: {}.", container, processorId); boolean hasContainerShutdown = stopSamzaContainer(); if (!hasContainerShutdown) { LOGGER.warn("Container: shutdown was unsuccessful. Stopping the stream processor: {}.", container, processorId); state = State.STOPPING; jobCoordinator.stop(); } else { LOGGER.info("Container: shutdown completed for stream processor: {}.", container, processorId); } } else { LOGGER.info("Container: of the stream processor: is not running.", container, processorId); } } } @Override public void onNewJobModel(String processorId, JobModel jobModel) { synchronized (lock) { if (state == State.IN_REBALANCE) { containerShutdownLatch = new CountDownLatch(1); container = createSamzaContainer(processorId, jobModel); container.setContainerListener(new ContainerListener()); LOGGER.info("Starting the container: for the stream processor: {}.", container, processorId); executorService.submit(container); } else { LOGGER.info("Ignoring onNewJobModel invocation since the current state is and not {}.", state, State.IN_REBALANCE); } } } @Override public void onCoordinatorStop() { synchronized (lock) { LOGGER.info("Shutting down the executor service of the stream processor: {}.", processorId); stopSamzaContainer(); executorService.shutdownNow(); state = State.STOPPED; } if (containerException != null) processorListener.onFailure(containerException); else processorListener.onShutdown(); } @Override public void onCoordinatorFailure(Throwable throwable) { synchronized (lock) { LOGGER.info(String.format("Coordinator: %s failed with an exception. Stopping the stream processor: %s. Original exception:", jobCoordinator, processorId), throwable); stopSamzaContainer(); executorService.shutdownNow(); state = State.STOPPED; } processorListener.onFailure(throwable); } }; }

Target:
private JobCoordinatorListener createJobCoordinatorListener() { return new JobCoordinatorListener() { @Override public void onJobModelExpired() { synchronized (lock) { if (state == State.STARTED || state == State.RUNNING) { state = State.IN_REBALANCE; LOGGER.info("Job model expired. Shutting down the container: of stream processor: {}.", container, processorId); boolean hasContainerShutdown = stopSamzaContainer(); if (!hasContainerShutdown) { LOGGER.warn("Container: shutdown was unsuccessful. Stopping the stream processor: {}.", container, processorId); state = State.STOPPING; jobCoordinator.stop(); } else { LOGGER.info("Container: shutdown completed for stream processor: {}.", container, processorId); } } else { LOGGER.info("Ignoring onJobModelExpired invocation since the current state is and not in {}.", state, ImmutableList.of(State.RUNNING, State.STARTED)); } } } @Override public void onNewJobModel(String processorId, JobModel jobModel) { synchronized (lock) { if (state == State.IN_REBALANCE) { containerShutdownLatch = new CountDownLatch(1); container = createSamzaContainer(processorId, jobModel); container.setContainerListener(new ContainerListener()); LOGGER.info("Starting the container: for the stream processor: {}.", container, processorId); executorService.submit(container); } else { LOGGER.info("Ignoring onNewJobModel invocation since the current state is and not {}.", state, State.IN_REBALANCE); } } } @Override public void onCoordinatorStop() { synchronized (lock) { LOGGER.info("Shutting down the executor service of the stream processor: {}.", processorId); stopSamzaContainer(); executorService.shutdownNow(); state = State.STOPPED; } if (containerException != null) processorListener.onFailure(containerException); else processorListener.onShutdown(); } @Override public void onCoordinatorFailure(Throwable throwable) { synchronized (lock) { LOGGER.info(String.format("Coordinator: %s failed with an exception. Stopping the stream processor: %s. Original exception:", jobCoordinator, processorId), throwable); stopSamzaContainer(); executorService.shutdownNow(); state = State.STOPPED; } processorListener.onFailure(throwable); } }; }