| | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_ENABLED; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEBUG_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.DEFAULT_SCHEDULER; |
| | | import static com.forgerock.opendj.util.StaticUtils.getStackTraceIfDebugEnabled; |
| | | import static com.forgerock.opendj.util.StaticUtils.logIfDebugEnabled; |
| | |
| | | import java.util.concurrent.Semaphore; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.logging.Level; |
| | | |
| | | import org.forgerock.opendj.ldap.requests.AbandonRequest; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | |
| | | // Connection attempt failed, so decrease the pool size. |
| | | availableConnections.release(); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection attempt failed: %s, availableConnections=%d, maxPoolSize=%d", |
| | | error.getMessage(), currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection attempt failed: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize, error); |
| | | |
| | | QueueElement holder; |
| | | synchronized (queue) { |
| | |
| | | |
| | | @Override |
| | | public void handleResult(final Connection connection) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection attempt succeeded: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection attempt succeeded: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | publishConnection(connection); |
| | | } |
| | | } |
| | |
| | | connection.close(); |
| | | factory.getConnectionAsync(connectionResultHandler); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection no longer valid: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection no longer valid: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | } |
| | | |
| | | // Invoke listeners. |
| | |
| | | |
| | | // Close the idle connections. |
| | | if (!idleConnections.isEmpty()) { |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format("Closing %d idle pooled connections: " |
| | | + "availableConnections=%d, maxPoolSize=%d", idleConnections.size(), |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Closing {} idle pooled connections: availableConnections={}, maxPoolSize={}", |
| | | idleConnections.size(), currentPoolSize(), maxPoolSize); |
| | | for (final Connection connection : idleConnections) { |
| | | connection.close(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection pool is closing: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection pool is closing: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | |
| | | if (idleTimeoutFuture != null) { |
| | | idleTimeoutFuture.cancel(false); |
| | |
| | | connection.close(); |
| | | availableConnections.release(); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection no longer valid: availableConnections=%d, poolSize=%d", |
| | | currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection no longer valid: availableConnections={}, poolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | } |
| | | } else { |
| | | // Grow the pool if needed. |
| | |
| | | availableConnections.release(); |
| | | connection.close(); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Closing connection because connection pool is closing: " |
| | | + "availableConnections=%d, maxPoolSize=%d", currentPoolSize(), |
| | | maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug( |
| | | "Closing connection because connection pool is closing: availableConnections={}, maxPoolSize={}", |
| | | currentPoolSize(), maxPoolSize); |
| | | |
| | | if (holder != null) { |
| | | final ErrorResultException e = |
| | |
| | | ERR_CONNECTION_POOL_CLOSING.get(toString()).toString()); |
| | | holder.getWaitingFuture().handleErrorResult(e); |
| | | |
| | | if (DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | DEBUG_LOG.fine(String.format( |
| | | "Connection attempt failed: %s, availableConnections=%d, poolSize=%d", |
| | | e.getMessage(), currentPoolSize(), maxPoolSize)); |
| | | } |
| | | DEFAULT_LOG.debug("Connection attempt failed: availableConnections={}, poolSize={}", |
| | | currentPoolSize(), maxPoolSize, e); |
| | | } |
| | | } else { |
| | | holder.getWaitingFuture().handleResult( |