当前位置: 首页>>代码示例>>Java>>正文


Java GenericKeyedObjectPoolConfig.setJmxNamePrefix方法代码示例

本文整理汇总了Java中org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig.setJmxNamePrefix方法的典型用法代码示例。如果您正苦于以下问题:Java GenericKeyedObjectPoolConfig.setJmxNamePrefix方法的具体用法?Java GenericKeyedObjectPoolConfig.setJmxNamePrefix怎么用?Java GenericKeyedObjectPoolConfig.setJmxNamePrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig的用法示例。


在下文中一共展示了GenericKeyedObjectPoolConfig.setJmxNamePrefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:45,代码来源:PoolableManagedConnectionFactory.java

示例2: 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;
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:33,代码来源:PooledContextSource.java

示例3: 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);
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:60,代码来源:PoolableConnectionFactory.java


注:本文中的org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig.setJmxNamePrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。