public void gracefullyShutdownClientChannels ( ) { LOG . warn ( "Gracefully shutting down all client channels" ) ; try { List < ChannelFuture > futures = new ArrayList <> ( ) ; channels . forEach ( channel -> { ConnectionCloseType . setForChannel ( channel , ConnectionCloseType . DELAYED_GRACEFUL ) ; ChannelFuture f = channel . pipeline ( ) . close ( ) ; futures . add ( f ) ; } ) ; LOG . warn ( "Waiting for " + futures . size ( ) + " client channels to be closed." ) ; for ( ChannelFuture f : futures ) { f . await ( ) ; } LOG . warn ( futures . size ( ) + " client channels closed." ) ; } catch ( InterruptedException ie ) { LOG . warn ( "Interrupted while shutting down client channels" ) ; } }
Note this blocks until all the channels have finished closing .