public synchronized void shutdown(boolean force) {

        if (shutdown) {
            return;
        }

        String ltransactionListenerProcessorHandle = transactionListenerProcessorHandle;
        transactionListenerProcessorHandle = null;
        if (null != ltransactionListenerProcessorHandle) {

            try {
                unregisterBlockListener(ltransactionListenerProcessorHandle);
            } catch (Exception e) {
                logger.error(format("Shutting down channel %s transactionListenerProcessorHandle", name), e);
            }
        }

        String lchaincodeEventUpgradeListenerHandle = chaincodeEventUpgradeListenerHandle;
        chaincodeEventUpgradeListenerHandle = null;
        if (null != lchaincodeEventUpgradeListenerHandle) {

            try {
                unregisterChaincodeEventListener(lchaincodeEventUpgradeListenerHandle);
            } catch (Exception e) {
                logger.error(format("Shutting down channel %s chaincodeEventUpgradeListenr", name), e);
            }
        }

        initialized = false;
        shutdown = true;

        final ServiceDiscovery lserviceDiscovery = serviceDiscovery;
        serviceDiscovery = null;
        if (null != lserviceDiscovery) {
            lserviceDiscovery.shutdown();
        }

        if (chainCodeListeners != null) {
            chainCodeListeners.clear();

        }

        if (blockListeners != null) {
            blockListeners.clear();
        }

        if (client != null) {
            client.removeChannel(this);
        }

        client = null;

        for (Peer peer : new ArrayList<>(getPeers())) {

            try {
                removePeerInternal(peer);
                peer.shutdown(force);
            } catch (Exception e) {
                // Best effort.
            }
        }
        peers.clear(); // make sure.

        peerEndpointMap.clear();
        ordererEndpointMap.clear();

        //Make sure
        for (Set<Peer> peerRoleSet : peerRoleSetMap.values()) {
            peerRoleSet.clear();
        }

        for (Orderer orderer : getOrderers()) {
            orderer.shutdown(force);
        }

        orderers.clear();

        if (null != eventQueueThread) {
            eventQueueThread.interrupt();
            eventQueueThread = null;
        }
        ScheduledFuture<?> lsweeper = sweeper;
        sweeper = null;

        if (null != lsweeper) {
            lsweeper.cancel(true);
        }

        ScheduledExecutorService lse = sweeperExecutorService;
        sweeperExecutorService = null;
        if (null != lse) {
            lse.shutdownNow();
        }
    }
public synchronized void shutdown ( boolean force ) { if ( shutdown ) { return ; } String ltransactionListenerProcessorHandle = transactionListenerProcessorHandle ; transactionListenerProcessorHandle = null ; if ( null != ltransactionListenerProcessorHandle ) { try { unregisterBlockListener ( ltransactionListenerProcessorHandle ) ; } catch ( Exception e ) { logger . error ( format ( "Shutting down channel %s transactionListenerProcessorHandle" , name ) , e ) ; } } String lchaincodeEventUpgradeListenerHandle = chaincodeEventUpgradeListenerHandle ; chaincodeEventUpgradeListenerHandle = null ; if ( null != lchaincodeEventUpgradeListenerHandle ) { try { unregisterChaincodeEventListener ( lchaincodeEventUpgradeListenerHandle ) ; } catch ( Exception e ) { logger . error ( format ( "Shutting down channel %s chaincodeEventUpgradeListenr" , name ) , e ) ; } } initialized = false ; shutdown = true ; final ServiceDiscovery lserviceDiscovery = serviceDiscovery ; serviceDiscovery = null ; if ( null != lserviceDiscovery ) { lserviceDiscovery . shutdown ( ) ; } if ( chainCodeListeners != null ) { chainCodeListeners . clear ( ) ; } if ( blockListeners != null ) { blockListeners . clear ( ) ; } if ( client != null ) { client . removeChannel ( this ) ; } client = null ; for ( Peer peer : new ArrayList < > ( getPeers ( ) ) ) { try { removePeerInternal ( peer ) ; peer . shutdown ( force ) ; } catch ( Exception e ) { } } peers . clear ( ) ; peerEndpointMap . clear ( ) ; ordererEndpointMap . clear ( ) ; for ( Set < Peer > peerRoleSet : peerRoleSetMap . values ( ) ) { peerRoleSet . clear ( ) ; } for ( Orderer orderer : getOrderers ( ) ) { orderer . shutdown ( force ) ; } orderers . clear ( ) ; if ( null != eventQueueThread ) { eventQueueThread . interrupt ( ) ; eventQueueThread = null ; } ScheduledFuture < ? > lsweeper = sweeper ; sweeper = null ; if ( null != lsweeper ) { lsweeper . cancel ( true ) ; } ScheduledExecutorService lse = sweeperExecutorService ; sweeperExecutorService = null ; if ( null != lse ) { lse . shutdownNow ( ) ; } }
Shutdown the channel with all resources released.

@param force force immediate shutdown.