/** Thread constructor * @param connectionPartition partition to monitor * @param pool Pool handle. */ public PoolWatchThread(ConnectionPartition connectionPartition, BoneCP pool) { this.partition = connectionPartition; this.pool = pool; this.lazyInit = this.pool.getConfig().isLazyInit(); this.acquireRetryDelayInMs = this.pool.getConfig().getAcquireRetryDelayInMs(); this.poolAvailabilityThreshold = this.pool.getConfig().getPoolAvailabilityThreshold(); }
/** Sends any configured SQL init statement. * @throws SQLException on error */ public void sendInitSQL() throws SQLException { sendInitSQL(this.connection, this.pool.getConfig().getInitSQL()); }
@Override public int maximumPoolSize(DataSource dataSource, JsonObject config) { if (dataSource instanceof BoneCPDataSource) { BoneCPConfig cfg = ((BoneCPDataSource) dataSource).getPool().getConfig(); return cfg.getMaxConnectionsPerPartition() * cfg.getPartitionCount(); } return -1; }
public String toString(){ long timeMillis = System.currentTimeMillis(); return Objects.toStringHelper(this) .add("url", this.pool.getConfig().getJdbcUrl()) .add("user", this.pool.getConfig().getUsername()) .add("debugHandle", this.debugHandle) .add("lastResetAgoInSec", TimeUnit.MILLISECONDS.toSeconds(timeMillis-this.connectionLastResetInMs)) .add("lastUsedAgoInSec", TimeUnit.MILLISECONDS.toSeconds(timeMillis-this.connectionLastUsedInMs)) .add("creationTimeAgoInSec", TimeUnit.MILLISECONDS.toSeconds(timeMillis-this.connectionCreationTimeInMs)) .toString(); }
this.connectionHook = pool.getConfig().getConnectionHook(); this.url = pool.getConfig().getJdbcUrl(); this.finalizableRefs = pool.getFinalizableRefs(); this.defaultReadOnly = pool.getConfig().getDefaultReadOnly(); this.defaultCatalog = pool.getConfig().getDefaultCatalog(); this.defaultTransactionIsolationValue = pool.getConfig().getDefaultTransactionIsolationValue(); this.defaultAutoCommit = pool.getConfig().getDefaultAutoCommit(); this.resetConnectionOnClose = pool.getConfig().isResetConnectionOnClose(); this.connectionTrackingDisabled = pool.getConfig().isDisableConnectionTracking(); this.statisticsEnabled = pool.getConfig().isStatisticsEnabled(); this.statistics = pool.getStatistics(); this.detectUnresolvedTransactions = pool.getConfig().isDetectUnresolvedTransactions(); this.detectUnclosedStatements = pool.getConfig().isDetectUnclosedStatements(); this.closeOpenStatements = pool.getConfig().isCloseOpenStatements(); if (this.closeOpenStatements){ trackedStatement = new MapMaker().makeMap(); this.connectionHook = this.pool.getConfig().getConnectionHook(); this.maxConnectionAgeInMs = pool.getConfig().getMaxConnectionAge(TimeUnit.MILLISECONDS); this.doubleCloseCheck = pool.getConfig().isCloseConnectionWatch(); this.logStatementsEnabled = pool.getConfig().isLogStatementsEnabled(); int cacheSize = pool.getConfig().getStatementsCacheSize(); if ( (cacheSize > 0) && newConnection ) { this.preparedStatementCache = new StatementCache(cacheSize, pool.getConfig().isStatisticsEnabled(), pool.getStatistics()); this.callableStatementCache = new StatementCache(cacheSize, pool.getConfig().isStatisticsEnabled(), pool.getStatistics()); this.statementCachingEnabled = true;
/** Private -- used solely for unit testing. * @param connection * @param preparedStatementCache * @param callableStatementCache * @param pool * @return Connection Handle */ protected static ConnectionHandle createTestConnectionHandle(Connection connection, IStatementCache preparedStatementCache, IStatementCache callableStatementCache, BoneCP pool){ ConnectionHandle handle = new ConnectionHandle(); handle.connection = connection; handle.preparedStatementCache = preparedStatementCache; handle.callableStatementCache = callableStatementCache; handle.connectionLastUsedInMs = System.currentTimeMillis(); handle.connectionLastResetInMs = System.currentTimeMillis(); handle.connectionCreationTimeInMs = System.currentTimeMillis(); handle.recoveryResult = new TransactionRecoveryResult(); handle.trackedStatement = new MapMaker().makeMap(); handle.url = "foo"; handle.closeOpenStatements = true; handle.pool = pool; handle.url=null; int cacheSize = pool.getConfig().getStatementsCacheSize(); if (cacheSize > 0) { handle.statementCachingEnabled = true; } return handle; }
Connection result = null; Connection oldRawConnection = connectionHandle.getInternalConnection(); String url = this.getConfig().getJdbcUrl(); int acquireRetryAttempts = this.getConfig().getAcquireRetryAttempts(); long acquireRetryDelayInMs = this.getConfig().getAcquireRetryDelayInMs(); AcquireFailConfig acquireConfig = new AcquireFailConfig(); acquireConfig.setAcquireRetryAttempts(new AtomicInteger(acquireRetryAttempts)); acquireConfig.setAcquireRetryDelayInMs(acquireRetryDelayInMs); acquireConfig.setLogMessage("Failed to acquire connection to "+url); ConnectionHook connectionHook = this.getConfig().getConnectionHook(); do{ result = null; tryAgain = false; if (acquireRetryAttempts != this.getConfig().getAcquireRetryAttempts()){ logger.info("Successfully re-established connection to "+url); ConnectionHandle.sendInitSQL(result, this.getConfig().getInitSQL()); } catch (SQLException e) {
Connection result; Connection oldRawConnection = connectionHandle.getInternalConnection(); String url = this.getConfig().getJdbcUrl(); int acquireRetryAttempts = this.getConfig().getAcquireRetryAttempts(); long acquireRetryDelayInMs = this.getConfig().getAcquireRetryDelayInMs(); AcquireFailConfig acquireConfig = new AcquireFailConfig(); acquireConfig.setAcquireRetryAttempts(new AtomicInteger(acquireRetryAttempts)); acquireConfig.setAcquireRetryDelayInMs(acquireRetryDelayInMs); acquireConfig.setLogMessage("Failed to acquire connection to " + url); ConnectionHook connectionHook = this.getConfig().getConnectionHook(); do { result = null; tryAgain = false; if (acquireRetryAttempts != this.getConfig().getAcquireRetryAttempts()) { LOGGER.info("Successfully re-established connection to " + url); ConnectionHandle.sendInitSQL(result, this.getConfig().getInitSQL()); } catch (SQLException e) {
ConnectionHook connectionHook = con.getPool().getConfig().getConnectionHook(); int acquireRetryAttempts = con.getPool().getConfig().getAcquireRetryAttempts(); long acquireRetryDelay = con.getPool().getConfig().getAcquireRetryDelayInMs(); AcquireFailConfig acquireConfig = new AcquireFailConfig(); acquireConfig.setAcquireRetryAttempts(new AtomicInteger(acquireRetryAttempts));
@Override public String toString() { return Objects.toStringHelper(this) .add("url", this.pool.getConfig().getJdbcUrl()) .add("user", this.pool.getConfig().getUsername()) .add("minConnections", this.getMinConnections()) .add("maxConnections", this.getMaxConnections()) .add("acquireIncrement", this.acquireIncrement) .add("createdConnections", this.createdConnections) .add("freeConnections", this.getFreeConnections()) .toString(); } }
/** * Partition constructor * * @param pool handle to connection pool */ public ConnectionPartition(BoneCP pool) { BoneCPConfig config = pool.getConfig(); this.minConnections = config.getMinConnectionsPerPartition(); this.maxConnections = config.getMaxConnectionsPerPartition(); this.acquireIncrement = config.getAcquireIncrement(); this.url = config.getJdbcUrl(); this.username = config.getUsername(); this.password = config.getPassword(); this.poolName = config.getPoolName() != null ? "(in pool '"+config.getPoolName()+"') " : ""; this.pool = pool; this.disableTracking = config.isDisableConnectionTracking(); this.queryExecuteTimeLimitInNanoSeconds = TimeUnit.NANOSECONDS.convert(config.getQueryExecuteTimeLimitInMs(), TimeUnit.MILLISECONDS); }
this.connectionHandle = connectionHandle; this.logStatementsEnabled = logStatementsEnabled; BoneCPConfig config = connectionHandle.getPool().getConfig(); this.connectionHook = config.getConnectionHook(); this.statistics = connectionHandle.getPool().getStatistics();