public CompletableFuture < Void > unregisterEventProcessor ( ) { TRACE_LOGGER . info ( this . hostContext . withHost ( "Stopping event processing" ) ) ; if ( this . unregistered == null ) { // PartitionManager is created in constructor. If this object exists, then // this.partitionManager is not null. this . unregistered = this . partitionManager . stopPartitions ( ) ; // If we own the executor, stop it also. // Owned executor is also created in constructor. if ( this . weOwnExecutor ) { this . unregistered = this . unregistered . thenRunAsync ( ( ) -> { // IMPORTANT: run this last stage in the default threadpool! // If a task running in a threadpool waits for that threadpool to terminate, it's going to wait a long time... // It is OK to call shutdown() here even if threads are still running. // Shutdown() causes the executor to stop accepting new tasks, but existing tasks will // run to completion. The pool will terminate when all existing tasks finish. // By this point all new tasks generated by the shutdown have been submitted. this . executorService . shutdown ( ) ; try { this . executorService . awaitTermination ( 10 , TimeUnit . MINUTES ) ; } catch ( InterruptedException e ) { throw new CompletionException ( e ) ; } } , ForkJoinPool . commonPool ( ) ) ; } } return this . unregistered ; }
Stop processing events and shut down this host instance .