/** * This constructor does not create a copy of the configuration. */ protected ClientContext(ClientContext ctx) { mSubject = ctx.getSubject(); mConf = ctx.getConf(); }
/** * Releases a block worker client to the client pools. * * @param workerNetAddress the address of the channel * @param client the client to release */ public void releaseBlockWorkerClient(WorkerNetAddress workerNetAddress, BlockWorkerClient client) { SocketAddress address = NetworkAddressUtils.getDataPortSocketAddress(workerNetAddress, getConf()); ClientPoolKey key = new ClientPoolKey(address, SaslParticipantProviderUtils.getImpersonationUser(mClientContext.getSubject(), getConf())); if (mBlockWorkerClientPool.containsKey(key)) { mBlockWorkerClientPool.get(key).release(client); } else { LOG.warn("No client pool for key {}, closing client instead. Context is closed: {}", key, mClosed.get()); try { client.close(); } catch (IOException e) { LOG.warn("Error closing block worker client for key {}", key, e); } } }
/** * Acquires a block worker client from the client pools. If there is no available client instance * available in the pool, it tries to create a new one. And an exception is thrown if it fails to * create a new one. * * @param workerNetAddress the network address of the channel * @return the acquired block worker */ public BlockWorkerClient acquireBlockWorkerClient(final WorkerNetAddress workerNetAddress) throws IOException { SocketAddress address = NetworkAddressUtils.getDataPortSocketAddress(workerNetAddress, getConf()); ClientPoolKey key = new ClientPoolKey(address, SaslParticipantProviderUtils.getImpersonationUser(mClientContext.getSubject(), getConf())); return mBlockWorkerClientPool.computeIfAbsent(key, k -> new BlockWorkerClientPool(mClientContext.getSubject(), address, getConf().getInt(PropertyKey.USER_BLOCK_WORKER_CLIENT_POOL_SIZE), getConf()) ).acquire(); }
mChannel = GrpcChannelBuilder .newBuilder(mAddress, mContext.getConf()) .setSubject(mContext.getSubject()) .build();