本文整理汇总了Java中org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig.setJmxEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java GenericKeyedObjectPoolConfig.setJmxEnabled方法的具体用法?Java GenericKeyedObjectPoolConfig.setJmxEnabled怎么用?Java GenericKeyedObjectPoolConfig.setJmxEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig
的用法示例。
在下文中一共展示了GenericKeyedObjectPoolConfig.setJmxEnabled方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Before
public void init() throws InterruptedException {
this.appKey = "proxytest" + NumUtil.nextNum();
ServiceFactoryTest serviceFactoryTest = new ServiceFactoryTest();
ServerArgs serverArgs = serviceFactoryTest.getServerArgs(this.appKey, "127.0.0.1", NumUtil.nextPort());
ZkRegistry zkRegistry = serviceFactoryTest.getZkRegistry();
serverArgs.setRegistrys(ImmutableList.of(zkRegistry));
ThriftServerPublisher publisher = new ThriftServerPublisher(serverArgs);
Thread thread = new Thread(publisher::init);
thread.setDaemon(true);
thread.start();
TimeUnit.MILLISECONDS.sleep(400);
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotal(MAX_CONN);
poolConfig.setMaxTotalPerKey(MAX_CONN);
poolConfig.setMaxIdlePerKey(MAX_CONN);
poolConfig.setMinIdlePerKey(MIN_CONN);
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setJmxEnabled(false);
}
示例2: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Before
public void init() throws InterruptedException {
ServiceFactoryTest serviceFactoryTest = new ServiceFactoryTest();
ServerArgs serverArgs = serviceFactoryTest.getServerArgs(appKey, "127.0.0.1", port);
ThriftServerPublisher publisher = new ThriftServerPublisher(serverArgs);
Thread thread = new Thread(publisher::init);
thread.setDaemon(true);
thread.start();
TimeUnit.MILLISECONDS.sleep(400);
poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotal(MAX_CONN);
poolConfig.setMaxTotalPerKey(MAX_CONN);
poolConfig.setMaxIdlePerKey(MAX_CONN);
poolConfig.setMinIdlePerKey(MIN_CONN);
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
poolConfig.setJmxEnabled(false);
}
示例3: init
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Before
public void init() {
this.port = RandomUtils.nextInt(10000, 20000);
new DemoServer().startDaemon(this.port);
config = new GenericKeyedObjectPoolConfig();
config.setMaxTotal(MAX_CONN);
config.setMaxTotalPerKey(MAX_CONN);
config.setMaxIdlePerKey(MAX_CONN);
config.setMinIdlePerKey(MIN_CONN);
config.setTestOnBorrow(true);
config.setMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
config.setSoftMinEvictableIdleTimeMillis(MINUTES.toMillis(1));
config.setJmxEnabled(false);
}
示例4: makeObject
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
/**
* Uses the configured XAConnectionFactory to create a {@link PoolableManagedConnection}.
* Throws <code>IllegalStateException</code> if the connection factory returns null.
* Also initializes the connection using configured initialization sql (if provided)
* and sets up a prepared statement pool associated with the PoolableManagedConnection
* if statement pooling is enabled.
*/
@Override
synchronized public PooledObject<PoolableConnection> makeObject() throws Exception {
Connection conn = getConnectionFactory().createConnection();
if (conn == null) {
throw new IllegalStateException("Connection factory returned null from createConnection");
}
initializeConnection(conn);
if (getPoolStatements()) {
conn = new PoolingConnection(conn);
final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
config.setMaxTotalPerKey(-1);
config.setBlockWhenExhausted(false);
config.setMaxWaitMillis(0);
config.setMaxIdlePerKey(1);
config.setMaxTotal(getMaxOpenPreparedStatements());
final ObjectName dataSourceJmxName = getDataSourceJmxName();
final long connIndex = getConnectionIndex().getAndIncrement();
if (dataSourceJmxName != null) {
final StringBuilder base = new StringBuilder(dataSourceJmxName.toString());
base.append(Constants.JMX_CONNECTION_BASE_EXT);
base.append(Long.toString(connIndex));
config.setJmxNameBase(base.toString());
config.setJmxNamePrefix(Constants.JMX_STATEMENT_POOL_PREFIX);
} else {
config.setJmxEnabled(false);
}
final KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> stmtPool =
new GenericKeyedObjectPool<>((PoolingConnection)conn, config);
((PoolingConnection)conn).setStatementPool(stmtPool);
((PoolingConnection) conn).setCacheState(getCacheState());
}
final PoolableManagedConnection pmc =
new PoolableManagedConnection(transactionRegistry, conn, getPool(),
getDisconnectionSqlCodes(), isFastFailValidation());
pmc.setCacheState(getCacheState());
return new DefaultPooledObject<PoolableConnection>(pmc);
}
示例5: getConfig
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
private GenericKeyedObjectPoolConfig getConfig(PoolConfig poolConfig) {
GenericKeyedObjectPoolConfig objectPoolConfig = new GenericKeyedObjectPoolConfig();
objectPoolConfig.setMaxTotalPerKey(poolConfig.getMaxTotalPerKey());
objectPoolConfig.setMaxTotal(poolConfig.getMaxTotal());
objectPoolConfig.setMaxIdlePerKey(poolConfig.getMaxIdlePerKey());
objectPoolConfig.setMinIdlePerKey(poolConfig.getMinIdlePerKey());
objectPoolConfig.setTestWhileIdle(poolConfig.isTestWhileIdle());
objectPoolConfig.setTestOnReturn(poolConfig.isTestOnReturn());
objectPoolConfig.setTestOnCreate(poolConfig.isTestOnCreate());
objectPoolConfig.setTestOnBorrow(poolConfig.isTestOnBorrow());
objectPoolConfig.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
objectPoolConfig.setEvictionPolicyClassName(poolConfig.getEvictionPolicyClassName());
objectPoolConfig.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
objectPoolConfig.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
objectPoolConfig.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
objectPoolConfig.setJmxEnabled(poolConfig.isJmxEnabled());
objectPoolConfig.setJmxNameBase(poolConfig.getJmxNameBase());
objectPoolConfig.setJmxNamePrefix(poolConfig.getJmxNamePrefix());
objectPoolConfig.setMaxWaitMillis(poolConfig.getMaxWaitMillis());
objectPoolConfig.setFairness(poolConfig.isFairness());
objectPoolConfig.setBlockWhenExhausted(poolConfig.isBlockWhenExhausted());
objectPoolConfig.setLifo(poolConfig.isLifo());
return objectPoolConfig;
}
示例6: initConnectionsPool
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
public void initConnectionsPool() {
if (this.connectionsPool == null) {
final GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setJmxEnabled(false);
this.connectionsPool = new GenericKeyedObjectPool<PooledConnectionKey, PooledConnection>(
new KeyedPooledObjectFactory<PooledConnectionKey, PooledConnection>() {
@Override
public PooledObject<PooledConnection> makeObject(PooledConnectionKey connectionKey) throws Exception {
Connection delegate = createProviderConnection(connectionKey);
PooledConnection connection = createPooledConnection(delegate);
connection.setIdleTimeout(getIdleTimeout());
connection.setExpiryTimeout(getExpiryTimeout());
connection.setMaximumActiveSessionPerConnection(getMaximumActiveSessionPerConnection());
connection.setBlockIfSessionPoolIsFull(isBlockIfSessionPoolIsFull());
if (isBlockIfSessionPoolIsFull() && getBlockIfSessionPoolIsFullTimeout() > 0) {
connection.setBlockIfSessionPoolIsFullTimeout(getBlockIfSessionPoolIsFullTimeout());
}
connection.setUseAnonymousProducers(isUseAnonymousProducers());
connection.setReconnectOnException(isReconnectOnException());
LOG.trace("Created new connection: {}", connection);
JmsPoolConnectionFactory.this.mostRecentlyCreated.set(connection);
return new DefaultPooledObject<PooledConnection>(connection);
}
@Override
public void destroyObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) throws Exception {
PooledConnection connection = pooledObject.getObject();
try {
LOG.trace("Destroying connection: {}", connection);
connection.close();
} catch (Exception e) {
LOG.warn("Close connection failed for connection: " + connection + ". This exception will be ignored.",e);
}
}
@Override
public boolean validateObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) {
PooledConnection connection = pooledObject.getObject();
if (connection != null && connection.expiredCheck()) {
LOG.trace("Connection has expired: {} and will be destroyed", connection);
return false;
}
return true;
}
@Override
public void activateObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) throws Exception {
}
@Override
public void passivateObject(PooledConnectionKey connectionKey, PooledObject<PooledConnection> pooledObject) throws Exception {
}
}, poolConfig);
// Set max idle (not max active) since our connections always idle in the pool.
this.connectionsPool.setMaxIdlePerKey(DEFAULT_MAX_CONNECTIONS);
this.connectionsPool.setLifo(false);
// We always want our validate method to control when idle objects are evicted.
this.connectionsPool.setTestOnBorrow(true);
this.connectionsPool.setTestWhileIdle(true);
}
}
示例7: initTask
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Override
public void initTask() {
super.initTask();
stageClassLoaders = runtimeInfo.getStageLibraryClassLoaders();
if (!stageClassLoaders.isEmpty()) {
resolveClassLoaderMethods(stageClassLoaders.get(0));
}
if(configuration.get(CONFIG_CP_VALIDATION, DEFAULT_CP_VALIDATION)) {
validateStageClasspaths();
}
// Load all stages and other objects from the libraries
json = ObjectMapperFactory.get();
stageList = new ArrayList<>();
stageMap = new HashMap<>();
lineagePublisherDefinitions = new ArrayList<>();
lineagePublisherDefinitionMap = new HashMap<>();
credentialStoreDefinitions = new ArrayList<>();
serviceList = new ArrayList<>();
serviceMap = new HashMap<>();
loadStages();
stageList = ImmutableList.copyOf(stageList);
stageMap = ImmutableMap.copyOf(stageMap);
lineagePublisherDefinitions = ImmutableList.copyOf(lineagePublisherDefinitions);
lineagePublisherDefinitionMap = ImmutableMap.copyOf(lineagePublisherDefinitionMap);
credentialStoreDefinitions = ImmutableList.copyOf(credentialStoreDefinitions);
serviceList = ImmutableList.copyOf(serviceList);
serviceMap = ImmutableMap.copyOf(serviceMap);
// Various validations
validateAllServicesAvailable();
// localization cache for definitions
localizedStageList = CacheBuilder.newBuilder().build(new CacheLoader<Locale, List<StageDefinition>>() {
@Override
public List<StageDefinition> load(Locale key) throws Exception {
List<StageDefinition> list = new ArrayList<>();
for (StageDefinition stage : stageList) {
list.add(stage.localize());
}
return list;
}
});
validateStageVersions(stageList);
validateServices(stageList, serviceList);
// initializing the list of targets that can be used for error handling
ErrorHandlingChooserValues.setErrorHandlingOptions(this);
// initializing the list of targets that can be used as aggregating sink
StatsTargetChooserValues.setStatsTargetOptions(this);
// initializing the list of targets that can be used for pipeline lifecycle events
PipelineLifecycleStageChooserValues.setHandlingOptions(this);
// initializing the pool of private stage classloaders
GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setJmxEnabled(false);
poolConfig.setMaxTotal(configuration.get(MAX_PRIVATE_STAGE_CLASS_LOADERS_KEY,
MAX_PRIVATE_STAGE_CLASS_LOADERS_DEFAULT));
poolConfig.setMinEvictableIdleTimeMillis(-1);
poolConfig.setNumTestsPerEvictionRun(0);
poolConfig.setMaxIdlePerKey(-1);
poolConfig.setMinIdlePerKey(0);
poolConfig.setMaxTotalPerKey(-1);
poolConfig.setBlockWhenExhausted(false);
poolConfig.setMaxWaitMillis(0);
privateClassLoaderPool = new GenericKeyedObjectPool<>(new ClassLoaderFactory(stageClassLoaders), poolConfig);
}
示例8: JSchClient
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
public JSchClient(final Settings componentSettings,
final RepositorySettings repositorySettings,
final ThreadPool threadPool) throws JSchException {
SshConfig config = new SshConfig();
config.setHost(repositorySettings.settings().get("host", componentSettings.get("host")));
config.setPort(
repositorySettings.settings().getAsInt("port", componentSettings.getAsInt("port", 22)));
config.setUsername(
repositorySettings.settings().get("username", componentSettings.get("username")));
config.setPassword(
repositorySettings.settings().get("password", componentSettings.get("password")));
config.setLocation(
repositorySettings.settings().get("location", componentSettings.get("location", "~/")));
config.setPrivateKey(
repositorySettings.settings().get("private_key", componentSettings.get("private_key")));
config.setPassphrase(
repositorySettings.settings().get("passphrase", componentSettings.get("passphrase")));
config.setKnownHosts(
repositorySettings.settings().get("known_hosts", componentSettings.get("known_hosts")));
config.setIgnoreHostKeyChecking(repositorySettings.settings()
.getAsBoolean("ignore_host_key",
componentSettings.getAsBoolean("ignore_host_key", false)));
if (config.getPassword() == null && config.getPrivateKey() == null) {
throw new JSchException(
"A password and private key for SSH are empty.");
}
this.config = config;
GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotalPerKey(5);
poolConfig.setMinEvictableIdleTimeMillis(repositorySettings.settings()
.getAsLong("session_expire", componentSettings.getAsLong("session_expire", 60000L)));
TimeValue cleanInterval = repositorySettings.settings().getAsTime("clean_interval",
componentSettings.getAsTime("clean_interval", TimeValue.timeValueMinutes(1)));
poolConfig.setJmxEnabled(false);
poolConfig.setTimeBetweenEvictionRunsMillis(cleanInterval.getMillis());
this.sshPool = new SshPool(config, poolConfig);
}
示例9: makeObject
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; //导入方法依赖的package包/类
@Override
public PooledObject<PoolableConnection> makeObject() throws Exception {
Connection conn = _connFactory.createConnection();
if (conn == null) {
throw new IllegalStateException("Connection factory returned null from createConnection");
}
try {
initializeConnection(conn);
} catch (final SQLException sqle) {
// Make sure the connection is closed
try {
conn.close();
} catch (final SQLException ignore) {
// ignore
}
// Rethrow original exception so it is visible to caller
throw sqle;
}
final long connIndex = connectionIndex.getAndIncrement();
if(poolStatements) {
conn = new PoolingConnection(conn);
final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
config.setMaxTotalPerKey(-1);
config.setBlockWhenExhausted(false);
config.setMaxWaitMillis(0);
config.setMaxIdlePerKey(1);
config.setMaxTotal(maxOpenPreparedStatements);
if (dataSourceJmxName != null) {
final StringBuilder base = new StringBuilder(dataSourceJmxName.toString());
base.append(Constants.JMX_CONNECTION_BASE_EXT);
base.append(Long.toString(connIndex));
config.setJmxNameBase(base.toString());
config.setJmxNamePrefix(Constants.JMX_STATEMENT_POOL_PREFIX);
} else {
config.setJmxEnabled(false);
}
final KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> stmtPool =
new GenericKeyedObjectPool<>((PoolingConnection)conn, config);
((PoolingConnection)conn).setStatementPool(stmtPool);
((PoolingConnection) conn).setCacheState(_cacheState);
}
// Register this connection with JMX
ObjectName connJmxName;
if (dataSourceJmxName == null) {
connJmxName = null;
} else {
connJmxName = new ObjectName(dataSourceJmxName.toString() +
Constants.JMX_CONNECTION_BASE_EXT + connIndex);
}
final PoolableConnection pc = new PoolableConnection(conn, _pool, connJmxName,
_disconnectionSqlCodes, _fastFailValidation);
pc.setCacheState(_cacheState);
return new DefaultPooledObject<>(pc);
}