private String format(final CPoolEntry entry) { final StringBuilder buf = new StringBuilder(); buf.append("[id: ").append(entry.getId()).append("]"); buf.append("[route: ").append(entry.getRoute()).append("]"); final Object state = entry.getState(); if (state != null) { buf.append("[state: ").append(state).append("]"); } return buf.toString(); }
@Override protected CPoolEntry createEntry(final HttpRoute route, final ManagedHttpClientConnection conn) { final String id = Long.toString(COUNTER.getAndIncrement()); return new CPoolEntry(this.log, id, route, conn, this.timeToLive, this.tunit); }
public void close() throws IOException { final CPoolEntry local = this.poolEntry; if (local != null) { local.closeConnection(); } }
return; final ManagedHttpClientConnection conn = entry.getConnection(); try { if (conn.isOpen()) { final TimeUnit effectiveUnit = tunit != null ? tunit : TimeUnit.MILLISECONDS; entry.setState(state); entry.updateExpiry(keepalive, effectiveUnit); if (this.log.isDebugEnabled()) { final String s; this.pool.release(entry, conn.isOpen() && entry.isRouteComplete()); if (this.log.isDebugEnabled()) { this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
ManagedHttpClientConnection getConnection() { final CPoolEntry local = this.poolEntry; if (local == null) { return null; } return local.getConnection(); }
protected HttpClientConnection leaseConnection( final Future<CPoolEntry> future, final long timeout, final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { final CPoolEntry entry; try { entry = future.get(timeout, tunit); if (entry == null || future.isCancelled()) { throw new InterruptedException(); } Asserts.check(entry.getConnection() != null, "Pool entry with no connection"); if (this.log.isDebugEnabled()) { this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute())); } return CPoolProxy.newProxy(entry); } catch (final TimeoutException ex) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool"); } }
public void routeComplete( final HttpClientConnection managedConn, final HttpRoute route, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed Connection"); Args.notNull(route, "HTTP route"); synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); entry.markRouteComplete(); } }
@Override public boolean isExpired(final long now) { final boolean expired = super.isExpired(now); if (expired && this.log.isDebugEnabled()) { this.log.debug("Connection " + this + " expired @ " + new Date(getExpiry())); } return expired; }
@Override public boolean isOpen() { final CPoolEntry local = this.poolEntry; if (local != null) { return !local.isClosed(); } else { return false; } }
@Override protected HttpClientConnection leaseConnection(Future<CPoolEntry> future, long timeout, TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { final Optional<ScheduledFuture<?>> warnFuture; if (warnTimeMs > 0 && warnTimeMs < timeout) { final Runnable warnCommand = () -> lastBlockedAt = Instant.now(); warnFuture = Optional.of(scheduler.schedule(warnCommand, warnTimeMs, TimeUnit.MILLISECONDS)); } else { warnFuture = Optional.empty(); } final Instant start = Instant.now(); final HttpClientConnection result = super.leaseConnection(future, timeout, tunit); final Duration time = Duration.between(start, Instant.now()); if (future.isDone()) { knownRoutes.add(future.get().getRoute()); } warnFuture.ifPresent(f -> f.cancel(false)); if (time.toMillis() > warnTimeMs) { // Log stack trace only if TRACE enabled Throwable t = null; if (LOG.isTraceEnabled()) { t = new Throwable(); t.fillInStackTrace(); } LOG.warn("Checkout from pool \"{}\" took {}", clientName, time, t); } return result; }
return; final ManagedHttpClientConnection conn = entry.getConnection(); try { if (conn.isOpen()) { final TimeUnit effectiveUnit = tunit != null ? tunit : TimeUnit.MILLISECONDS; entry.setState(state); entry.updateExpiry(keepalive, effectiveUnit); if (this.log.isDebugEnabled()) { final String s; this.pool.release(entry, conn.isOpen() && entry.isRouteComplete()); if (this.log.isDebugEnabled()) { this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
ManagedHttpClientConnection getConnection() { final CPoolEntry local = this.poolEntry; if (local == null) { return null; } return local.getConnection(); }
protected HttpClientConnection leaseConnection( final Future<CPoolEntry> future, final long timeout, final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { final CPoolEntry entry; try { entry = future.get(timeout, tunit); if (entry == null || future.isCancelled()) { throw new InterruptedException(); } Asserts.check(entry.getConnection() != null, "Pool entry with no connection"); if (this.log.isDebugEnabled()) { this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute())); } return CPoolProxy.newProxy(entry); } catch (final TimeoutException ex) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool"); } }
@Override public void routeComplete( final HttpClientConnection managedConn, final HttpRoute route, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed Connection"); Args.notNull(route, "HTTP route"); synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); entry.markRouteComplete(); } }
@Override public boolean isExpired(final long now) { final boolean expired = super.isExpired(now); if (expired && this.log.isDebugEnabled()) { this.log.debug("Connection " + this + " expired @ " + new Date(getExpiry())); } return expired; }
@Override public boolean isOpen() { final CPoolEntry local = this.poolEntry; if (local != null) { return !local.isClosed(); } else { return false; } }
return; final ManagedHttpClientConnection conn = entry.getConnection(); try { if (conn.isOpen()) { final TimeUnit effectiveUnit = tunit != null ? tunit : TimeUnit.MILLISECONDS; entry.setState(state); entry.updateExpiry(keepalive, effectiveUnit); if (this.log.isDebugEnabled()) { final String s; this.pool.release(entry, conn.isOpen() && entry.isRouteComplete()); if (this.log.isDebugEnabled()) { this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
private String format(final CPoolEntry entry) { final StringBuilder buf = new StringBuilder(); buf.append("[id: ").append(entry.getId()).append("]"); buf.append("[route: ").append(entry.getRoute()).append("]"); final Object state = entry.getState(); if (state != null) { buf.append("[state: ").append(state).append("]"); } return buf.toString(); }
ManagedHttpClientConnection getConnection() { final CPoolEntry local = this.poolEntry; if (local == null) { return null; } return local.getConnection(); }
protected HttpClientConnection leaseConnection( final Future<CPoolEntry> future, final long timeout, final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { final CPoolEntry entry; try { entry = future.get(timeout, tunit); if (entry == null || future.isCancelled()) { throw new InterruptedException(); } Asserts.check(entry.getConnection() != null, "Pool entry with no connection"); if (this.log.isDebugEnabled()) { this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute())); } return CPoolProxy.newProxy(entry); } catch (final TimeoutException ex) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool"); } }