/** * Releases the {@link BlockWorkerClient} back to the client pool, or destroys it if it was a * remote client. * * @param blockWorkerClient the worker client to release, the client should not be accessed after * this method is called */ public void releaseWorkerClient(BlockWorkerClient blockWorkerClient) { // If the client is local and the pool exists, release the client to the pool, otherwise just // close the client. if (blockWorkerClient.isLocal()) { // Return local worker client to its resource pool. WorkerNetAddress address = blockWorkerClient.getWorkerNetAddress(); if (!mLocalBlockWorkerClientPoolMap.containsKey(address)) { LOG.error( "The client to worker at {} to release is no longer registered in the context.", address); blockWorkerClient.close(); } else { mLocalBlockWorkerClientPoolMap.get(address).release(blockWorkerClient); } } else { // Destroy remote worker client. blockWorkerClient.close(); } }