@Override public void cleanup() { if (sender != null) { try { sender.close().whenComplete((voidargs, error) -> { try { if (error != null) { logger.error("Exception during sender cleanup phase" + error.toString()); } ehClient.closeSync(); } catch (Exception e) { logger.error("Exception during ehclient cleanup phase" + e.toString()); } }).get(); } catch (InterruptedException e) { logger.error("Exception occured during cleanup phase" + e.toString()); } catch (ExecutionException e) { logger.error("Exception occured during cleanup phase" + e.toString()); } logger.info("Eventhub Bolt cleaned up"); sender = null; ehClient = null; } }
@Override public synchronized void stop() { LOG.info("Stopping producer."); streamPartitionSenders.values().forEach((streamPartitionSender) -> { List<CompletableFuture<Void>> futures = new ArrayList<>(); streamPartitionSender.forEach((key, value) -> futures.add(value.close())); CompletableFuture<Void> future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])); try { future.get(DEFAULT_SHUTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); } catch (ExecutionException | InterruptedException | TimeoutException e) { LOG.error("Closing the partition sender failed ", e); } }); perStreamEventHubClientManagers.values() .parallelStream() .forEach(ehClient -> ehClient.close(DEFAULT_SHUTDOWN_TIMEOUT_MILLIS)); perStreamEventHubClientManagers.clear(); if (config.getPerPartitionConnection(systemName)) { perPartitionEventHubClients.values() .stream() .flatMap(map -> map.values().stream()) .forEach(ehClient -> ehClient.close(DEFAULT_SHUTDOWN_TIMEOUT_MILLIS)); perPartitionEventHubClients.clear(); } isStarted = false; isInitialized = false; LOG.info("EventHubSystemProducer stopped."); }