private ConnectionPool getConnectionPool(MaxwellBootstrapUtilityConfig config) { String name = "MaxwellBootstrapConnectionPool"; int maxPool = 10; int maxSize = 0; int idleTimeout = 10; String connectionURI = config.getConnectionURI(); return new ConnectionPool(name, maxPool, maxSize, idleTimeout, connectionURI, config.mysql.user, config.mysql.password); }
public Connection getMaxwellConnection() throws SQLException { return this.maxwellConnectionPool.getConnection(); }
private void shutdown(AtomicBoolean complete) { try { taskManager.stop(this.error); this.replicationConnectionPool.release(); this.maxwellConnectionPool.release(); this.rawMaxwellConnectionPool.release(); complete.set(true); } catch (Exception e) { LOGGER.error("Exception occurred during shutdown:", e); } }
pool = new ConnectionPool(poolName, minPool, maxPool, maxSize, idleTimeout, url, poolProps); else pool = new ConnectionPool(poolName, minPool, maxPool, maxSize, idleTimeout, url, user, pass); pool.registerMBean(); else if (!f.exists() && !f.createNewFile()) log_warn("Invalid logfile specified for pool " + poolName + " - cannot create file " + f.getAbsolutePath()); pool.setLog(new PrintWriter(new FileOutputStream(f, true), true)); pool.setLog(logUtil.getLogWriter()); pool.setLog(logUtil.getLogWriter()); if (poolDebug) log_info("Enabling debug info on pool " + poolName); pool.getCustomLogger().setDateFormat(df); pool.setCaching(!noCache); if (async) log_info("Enabling asynchronous destruction on pool " + poolName); pool.setAsyncDestroy(async); if (releaseTimeout > -1) log_info(String.format("Enabling release timeout (%dms) on pool %s", releaseTimeout, poolName)); if (recycleAfterDelegateUse) log_info("Enabling recycling after raw connection use on pool " + poolName); pool.setRecycleAfterDelegateUse(recycleAfterDelegateUse);
pool = new ConnectionPool(poolName, getMinPool(), getMaxPool(), getMaxSize(), getIdleTimeout(), getUrl(), props); pool.addConnectionPoolListener(this); if (getLogWriter() != null) pool.setLog(getLogWriter()); if (shutdownHook) pool.registerShutdownHook(); pool.setValidator(cv); pool.setValidator(cv); pool.setPasswordDecoder(pd); pool.setSelectionStrategy(ObjectPool.Strategy.SELECT_FIFO); break; case "RANDOM": pool.setSelectionStrategy(ObjectPool.Strategy.SELECT_RANDOM); break; case "LIFO":
this.metrics = new MaxwellMetrics(config); this.replicationConnectionPool = new ConnectionPool("ReplicationConnectionPool", 10, 0, 10, config.replicationMysql.getConnectionURI(false), config.replicationMysql.user, config.replicationMysql.password); this.schemaConnectionPool = null; } else { this.schemaConnectionPool = new ConnectionPool( "SchemaConnectionPool", 10, this.rawMaxwellConnectionPool = new ConnectionPool("RawMaxwellConnectionPool", 1, 2, 100, config.maxwellMysql.getConnectionURI(false), config.maxwellMysql.user, config.maxwellMysql.password); this.maxwellConnectionPool = new ConnectionPool("MaxwellConnectionPool", 10, 0, 10, config.maxwellMysql.getConnectionURI(), config.maxwellMysql.user, config.maxwellMysql.password); this.maxwellConnectionPool.setCaching(false);
/** * Sets the minimum number of pooled connections in the underlying {@link ConnectionPool}. * @param minPool minimum number of pooled connections */ public synchronized void setMinPool(int minPool) { this.minPool = minPool; if (pool != null) pool.setParameters(this.minPool, pool.getMaxPool(), pool.getMaxSize(), pool.getIdleTimeout()); }
/** * Sets the maximum number of connections in the underlying {@link ConnectionPool}. * @param maxSize maximum number of connections */ public synchronized void setMaxSize(int maxSize) { this.maxSize = maxSize; if (pool != null) pool.setParameters(pool.getMinPool(), pool.getMaxPool(), this.maxSize, pool.getIdleTimeout()); }
@Override public synchronized void poolParametersChanged(ConnectionPoolEvent evt) { synchronized(pool) { this.minPool = pool.getMinPool(); this.maxPool = pool.getMaxPool(); this.maxSize = pool.getMaxSize(); this.idleTimeout = (int)pool.getIdleTimeout(); } }
/** * Sets the maximum number of pooled connections in the underlying {@link ConnectionPool}. * @param maxPool maximum number of pooled connections */ public synchronized void setMaxPool(int maxPool) { this.maxPool = maxPool; if (pool != null) pool.setParameters(pool.getMinPool(), this.maxPool, pool.getMaxSize(), pool.getIdleTimeout()); }
/** * Creates a new {@code ConnectionPool} instance. * @param name pool name * @param minPool minimum number of pooled connections, or 0 for none * @param maxPool maximum number of pooled connections, or 0 for none * @param maxSize maximum number of possible connections, or 0 for no limit * @param idleTimeout idle timeout (seconds) for idle pooled connections, or 0 for no timeout * @param url JDBC connection URL * @param username database username * @param password password for the database username supplied */ public ConnectionPool(String name, int minPool, int maxPool, int maxSize, long idleTimeout, String url, String username, String password) { super(name, minPool, maxPool, maxSize, idleTimeout); this.url = url; this.user = username; this.pass = password; this.props = null; setCaching(true); addObjectPoolListener(new EventRelay<>()); }
pool.releaseImmediately(); else pool.release(timeout);
/** * Creates a new {@link CacheConnection} object, using the supplied {@link Connection}. * @param pool {@link ConnectionPool} to which this {@code CacheConnection} belongs * @param con {@link Connection} instance to which database calls should be delegated */ public CacheConnection(ConnectionPool pool, Connection con) { this.pool = pool; this.con = con; setCacheAll(true); ssReq = ssHit = psReq = psHit = csReq = csHit = 0; // Send log output to same logger as the pool uses. logger = LoggerFactory.getLogger(pool.getClass().getName() + "." + pool.getName()); logUtil = pool.getCustomLogger(); }
/** * Validates a {@link CacheConnection} object. * @param cc connection to validate * @return true if cc is valid, false otherwise */ @Override protected boolean isValid(final CacheConnection cc) { if (cc == null) return false; if (validator == null) return true; try { boolean valid = validator.isValid(cc.getRawConnection()); if (!valid) firePoolEvent(ConnectionPoolEvent.Type.VALIDATION_ERROR); return valid; } catch (SQLException sqlx) { log_debug("SQLException during validation", sqlx); return false; } }
/** * Overrides method to provide caching support. */ @Override public void close() throws SQLException { if (!open) return; // Uphold the descriptive contract of Connection interface. open = false; closing = true; // Hand connection (self) back to the pool for reuse. pool.freeConnection(this); closing = false; }
public Connection getReplicationConnection() throws SQLException { return this.replicationConnectionPool.getConnection(); }
/** * Releases the delegate {@link ConnectionPool} instance. */ public void release() { if (pool != null) pool.release(); }
public Connection getRawMaxwellConnection() throws SQLException { return rawMaxwellConnectionPool.getConnection(); }
/** * Releases the delegate {@link ConnectionPool} instance allowing the * specified timeout before forcibly destroying connections. * A negative timeout is equivalent to no timeout, and the method will wait * for items to be checked in before destruction. If timeout >= 0 then * items will be forcibly destroyed after the specified time has elapsed. * @param timeout timeout after which to forcibly destroy items (-1 for no timeout) */ public void release(long timeout) { if (pool != null) pool.release(timeout); }
protected List<RecoveryInfo> getAllRecoveryInfos() throws SQLException { try ( Connection c = connectionPool.getConnection() ) { return getAllRecoveryInfos(c); } }