@Override public void close() { if (isOpen) { monitor.incConnectionClosed(getHost(), lastException); executor.submit(new Runnable() { @Override public void run() { final TestHostType type = TestHostType .get(getHost().getPort()); type.close(); isOpen = false; } }); } }
@Override public Connection<CL> borrowConnection(Operation<CL, R> operation) throws ConnectionException { pool = null; connection = BagOfConnectionsConnectionPoolImpl.this.borrowConnection(operation); pool = connection.getHostConnectionPool(); return connection; }
@Override public boolean closeConnection(Connection<CL> connection) { returnedCount.incrementAndGet(); monitor.incConnectionReturned(host); internalCloseConnection(connection); return true; }
@Override public void open() throws ConnectionException { TestHostType type = TestHostType.get(getHost().getPort()); try { type.open(0); isOpen = true; monitor.incConnectionCreated(getHost()); } catch (ConnectionException e) { lastException = e; e.setHost(getHost()); monitor.incConnectionCreateFailed(getHost(), e); throw e; } }
OperationResult<R> result = connection.execute(filteredOperation); result.setAttemptsCount(attemptCounter); monitor.incOperationSuccess(getCurrentHost(), result.getLatency()); return result; try { informException(ce); monitor.incFailover(ce.getHost(), ce); monitor.incOperationFailure(getCurrentHost(), ex); throw ex;
@SuppressWarnings("unchecked") public <R> ExecuteWithFailover<CL, R> newExecuteWithFailover(Operation<CL, R> operation) throws ConnectionException { try { if (operation.getPinnedHost() != null) { HostConnectionPool<CL> pool = hosts.get(operation.getPinnedHost()); if (pool == null) { throw new NoAvailableHostsException("Host " + operation.getPinnedHost() + " not active"); } return new RoundRobinExecuteWithFailover<CL, R>(config, monitor, Arrays.<HostConnectionPool<CL>> asList(pool), 0); } int index = roundRobinCounter.incrementAndGet(); if (index > MAX_RR_COUNTER) { roundRobinCounter.set(0); } return new RoundRobinExecuteWithFailover<CL, R>(config, monitor, topology.getAllPools().getPools(), index); } catch (ConnectionException e) { monitor.incOperationFailure(e.getHost(), e); throw e; } } }
if (null == hosts.putIfAbsent(host, pool)) { try { monitor.onHostAdded(host, pool); if (refresh) { topology.addPool(pool);
monitor .onHostDown(getHost(), reason);
@Override public void open() throws ConnectionException { TestHostType type = TestHostType.get(getHost().getPort()); try { type.open(0); isOpen = true; monitor.incConnectionCreated(getHost()); } catch (ConnectionException e) { lastException = e; e.setHost(getHost()); monitor.incConnectionCreateFailed(getHost(), e); throw e; } }
OperationResult<R> result = connection.execute(filteredOperation); result.setAttemptsCount(attemptCounter); monitor.incOperationSuccess(getCurrentHost(), result.getLatency()); return result; try { informException(ce); monitor.incFailover(ce.getHost(), ce); monitor.incOperationFailure(getCurrentHost(), ex); throw ex;
@SuppressWarnings("unchecked") public <R> ExecuteWithFailover<CL, R> newExecuteWithFailover(Operation<CL, R> operation) throws ConnectionException { try { if (operation.getPinnedHost() != null) { HostConnectionPool<CL> pool = hosts.get(operation.getPinnedHost()); if (pool == null) { throw new NoAvailableHostsException("Host " + operation.getPinnedHost() + " not active"); } return new RoundRobinExecuteWithFailover<CL, R>(config, monitor, Arrays.<HostConnectionPool<CL>> asList(pool), 0); } int index = roundRobinCounter.incrementAndGet(); if (index > MAX_RR_COUNTER) { roundRobinCounter.set(0); } return new RoundRobinExecuteWithFailover<CL, R>(config, monitor, topology.getAllPools().getPools(), index); } catch (ConnectionException e) { monitor.incOperationFailure(e.getHost(), e); throw e; } } }
if (null == hosts.putIfAbsent(host, pool)) { try { monitor.onHostAdded(host, pool); if (refresh) { topology.addPool(pool);
monitor .onHostDown(getHost(), reason);
monitor.incConnectionCreated(getHost()); ConnectionException ce = ThriftConverter.ToConnectionPoolException(e).setHost(getHost()) .setLatency(System.currentTimeMillis() - startTime); monitor.incConnectionCreateFailed(getHost(), ce); throw ce; ConnectionException ce = ThriftConverter.ToConnectionPoolException(new RuntimeException("Error openning connection", t)).setHost(getHost()) .setLatency(System.currentTimeMillis() - startTime); monitor.incConnectionCreateFailed(getHost(), ce); throw ce;
@Override public void close() { if (isOpen) { monitor.incConnectionClosed(getHost(), lastException); executor.submit(new Runnable() { @Override public void run() { final TestHostType type = TestHostType .get(getHost().getPort()); type.close(); isOpen = false; } }); } }
@Override public boolean closeConnection(Connection<CL> connection) { returnedCount.incrementAndGet(); monitor.incConnectionReturned(host); internalCloseConnection(connection); return true; }
@Override public Connection<CL> borrowConnection(Operation<CL, R> operation) throws ConnectionException { pool = null; connection = BagOfConnectionsConnectionPoolImpl.this.borrowConnection(operation); pool = connection.getHostConnectionPool(); return connection; }
monitor.incOperationFailure(e.getHost(), e); throw e;
monitor.incConnectionCreated(getHost()); ConnectionException ce = ThriftConverter.ToConnectionPoolException(e).setHost(getHost()) .setLatency(System.currentTimeMillis() - startTime); monitor.incConnectionCreateFailed(getHost(), ce); throw ce; ConnectionException ce = ThriftConverter.ToConnectionPoolException(new RuntimeException("Error openning connection", t)).setHost(getHost()) .setLatency(System.currentTimeMillis() - startTime); monitor.incConnectionCreateFailed(getHost(), ce); throw ce;
@Override public void close() { if (closed.compareAndSet(false, true)) { monitor.incConnectionClosed(getHost(), lastException); executor.submit(new Runnable() { @Override public void run() { try { closeClient(); } catch (Exception e) { } } }); } }