PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider);
private TxClientPool getClientPool() { if (clients != null) { return clients; } synchronized (this) { if (clients == null) { try { initializePool(); } catch (TException e) { throw new RuntimeException("Failed to initialize transaction client provider: " + this, e); } } } return clients; } }
@Override protected TransactionServiceThriftClient create() throws TException { return newClient(); }
@Override public void returnClient(TransactionServiceThriftClient client) { getClientPool().release(client); }
@Override public CloseableThriftClient getCloseableClient() throws TException, TimeoutException, InterruptedException { TransactionServiceThriftClient client = getClientPool().obtain(obtainClientTimeoutMs, TimeUnit.MILLISECONDS); return new CloseableThriftClient(this, client); }
@Override public ThriftClientProvider get() { // configure the client provider String provider = cConf.get(TxConstants.Service.CFG_DATA_TX_CLIENT_PROVIDER, TxConstants.Service.DEFAULT_DATA_TX_CLIENT_PROVIDER); ThriftClientProvider clientProvider; if ("pool".equals(provider)) { clientProvider = new PooledClientProvider(cConf, discoveryServiceClient); } else if ("thread-local".equals(provider)) { clientProvider = new ThreadLocalClientProvider(cConf, discoveryServiceClient); } else { String message = "Unknown Transaction Service Client Provider '" + provider + "'."; throw new IllegalArgumentException(message); } return clientProvider; } }
@Override public ThriftClientProvider get() { // configure the client provider String provider = cConf.get(TxConstants.Service.CFG_DATA_TX_CLIENT_PROVIDER, TxConstants.Service.DEFAULT_DATA_TX_CLIENT_PROVIDER); ThriftClientProvider clientProvider; if ("pool".equals(provider)) { clientProvider = new PooledClientProvider(hConf, discoveryServiceClient); } else if ("thread-local".equals(provider)) { clientProvider = new ThreadLocalClientProvider(hConf, discoveryServiceClient); } else { String message = "Unknown Transaction Service Client Provider '" + provider + "'."; LOG.error(message); throw new IllegalArgumentException(message); } return clientProvider; } }
@Override public ThriftClientProvider get() { // configure the client provider String provider = cConf.get(TxConstants.Service.CFG_DATA_TX_CLIENT_PROVIDER, TxConstants.Service.DEFAULT_DATA_TX_CLIENT_PROVIDER); ThriftClientProvider clientProvider; if ("pool".equals(provider)) { clientProvider = new PooledClientProvider(hConf, discoveryServiceClient); } else if ("thread-local".equals(provider)) { clientProvider = new ThreadLocalClientProvider(hConf, discoveryServiceClient); } else { String message = "Unknown Transaction Service Client Provider '" + provider + "'."; LOG.error(message); throw new IllegalArgumentException(message); } return clientProvider; } }
PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider);
PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider);