private <T, K extends Exception> T applyAndRelease(Semaphore semaphore, FunctionCheckedException<F, T, K> function) throws K { try { return function.apply(delegate); } finally { semaphore.release(); } } }
Void runTruncateOnClient(Collection<TableReference> tablesToTruncate, CassandraClient client) throws TException { truncationFunction(tablesToTruncate).apply(client); return null; }
@Override public <V, K extends Exception> V runWithPooledResource(FunctionCheckedException<T, V, K> f) throws K { T resource = getResource(); try { return f.apply(resource); } finally { returnResource(resource); } }
try { resource = clientPool.borrowObject(); return fn.apply(resource); } catch (Exception e) { if (isInvalidClientConnection(resource)) {
Void runTruncateOnClient(Collection<TableReference> tablesToTruncate, CassandraClient client) throws TException { truncationFunction(tablesToTruncate).apply(client); return null; }
@Override public <V, K extends Exception> V runWithPooledResource(FunctionCheckedException<T, V, K> f) throws K { T resource = getResource(); try { return f.apply(resource); } finally { returnResource(resource); } }
@SuppressWarnings("unchecked") private <V, K extends Exception> V runWithGoodResource(FunctionCheckedException<Client, V, K> f) throws K { boolean shouldReuse = true; Client resource = getGoodClient(); try { return f.apply(resource); } catch (Exception e) { if (e instanceof TTransportException || e instanceof TProtocolException) { log.warn("Not reusing resource {} due to {}", resource, e); shouldReuse = false; } if (e instanceof TTransportException && ((TTransportException) e).getType() == TTransportException.END_OF_FILE) { // If we have an end of file this is most likely due to this cassandra node being bounced. discardCurrentPool(); } throw (K) e; } finally { if (shouldReuse) { log.info("Returning {} to pool", resource); returnResource(resource); } else { log.info("Discarding: {}", resource); cleanupForDiscard(resource); } } }
try { resource = clientPool.borrowObject(); return fn.apply(resource); } catch (Exception e) { if (isInvalidClientConnection(resource)) {