Source:
private AbstractScheduledService getThreadWatcherService() { return new AbstractScheduledService() { private final String _name = "offsetsFetcherWatcher-" + _connectorTaskName + "-" + _classInstantiationCount; @Override protected void startUp() throws Exception { LOG.info("Thread watcher for - Starting up", _connectorTaskName); _offsetsFetcher.awaitRunning(); } @Override protected void shutDown() throws Exception { LOG.info("Thread watcher for - Shutting down", _connectorTaskName); } @Override protected String serviceName() { return _name; } @Override protected void runOneIteration() throws Exception { if (!_isConnectorTaskAlive.get()) { LOG.warn("Detected that connector task thread for is no longer alive. " + "Shutting down the thread watcher and offset fetcher service.", _connectorTaskName); _offsetsFetcher.stopAsync(); this.stopAsync(); return; } if (!_offsetsFetcher.isRunning()) { LOG.warn("Detected that offset fetcher crashed - restarting it", _offsetsFetcher); _lastRpcUpdate = Instant.now(); _offsetsFetcher = getOffsetsFetcherService(); _offsetsFetcher.startAsync(); return; } final Instant rpcSlaExpiration = _lastRpcUpdate.plus(LAST_CONSUMER_RPC_TERMINATED_TIMEOUT); if (Instant.now().isAfter(rpcSlaExpiration)) { LOG.warn("Detected that offset fetcher has not successfully made an RPC call for an extended time - " + "killing and restarting it", _offsetsFetcher); _lastRpcUpdate = Instant.now(); _offsetsFetcher.stopAsync(); _offsetsFetcher = getOffsetsFetcherService(); _offsetsFetcher.startAsync(); } } @Override protected Scheduler scheduler() { return Scheduler.newFixedRateSchedule(0, 1, TimeUnit.SECONDS); } }; }

Target:
private AbstractScheduledService getThreadWatcherService() { return new AbstractScheduledService() { private final String _name = "offsetsFetcherWatcher-" + _connectorTaskName + "-" + _classInstantiationCount; @Override protected void startUp() throws Exception { LOG.info("Thread watcher for - Starting up", _connectorTaskName); _offsetsFetcher.awaitRunning(); } @Override protected void shutDown() throws Exception { LOG.info("Thread watcher for - Shutting down", _connectorTaskName); } @Override protected String serviceName() { return _name; } @Override protected void runOneIteration() throws Exception { if (!_isConnectorTaskAlive.get()) { LOG.warn("Detected that connector task thread for is no longer alive. " + "Shutting down the thread watcher and offset fetcher service.", _connectorTaskName); _offsetsFetcher.stopAsync(); this.stopAsync(); return; } if (!_offsetsFetcher.isRunning()) { LOG.warn("Detected that offset fetcher crashed - restarting it", _offsetsFetcher); _lastRpcUpdate = Instant.now(); _offsetsFetcher = getOffsetsFetcherService(); _offsetsFetcher.startAsync(); return; } final Instant rpcSlaExpiration = _lastRpcUpdate.plus(LAST_CONSUMER_RPC_TERMINATED_TIMEOUT); if (Instant.now().isAfter(rpcSlaExpiration)) { LOG.warn("Detected that offset fetcher has not successfully made an RPC call for an extended time - " + "killing and restarting it", _offsetsFetcher); _lastRpcUpdate = Instant.now(); _offsetsFetcher.stopAsync(); _offsetsFetcher = getOffsetsFetcherService(); _offsetsFetcher.startAsync(); } } @Override protected Scheduler scheduler() { return Scheduler.newFixedRateSchedule(0, 1, TimeUnit.MINUTES); } }; }