Search in sources :

Example 11 with DefaultPooledObject

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project cuba by cuba-platform.

the class AbstractScripting method getPool.

private synchronized GenericKeyedObjectPool<String, Script> getPool() {
    if (pool == null) {
        GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
        poolConfig.setMaxTotalPerKey(-1);
        poolConfig.setMaxIdlePerKey(globalConfig.getGroovyEvaluationPoolMaxIdle());
        pool = new GenericKeyedObjectPool<>(new BaseKeyedPooledObjectFactory<String, Script>() {

            @Override
            public Script create(String key) throws Exception {
                return createScript(key);
            }

            @Override
            public PooledObject<Script> wrap(Script value) {
                return new DefaultPooledObject<>(value);
            }
        }, poolConfig);
    }
    return pool;
}
Also used : GenericKeyedObjectPoolConfig(org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig) Script(groovy.lang.Script) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) BaseKeyedPooledObjectFactory(org.apache.commons.pool2.BaseKeyedPooledObjectFactory)

Example 12 with DefaultPooledObject

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project datanucleus-rdbms by datanucleus.

the class KeyedCPDSConnectionFactory method makeObject.

/**
 * Creates a new {@link PooledConnectionAndInfo} from the given {@link UserPassKey}.
 *
 * @param upkey {@link UserPassKey} containing user credentials
 * @throws SQLException if the connection could not be created.
 * @see org.datanucleus.store.rdbms.datasource.dbcp2.pool2.KeyedPooledObjectFactory#makeObject(java.lang.Object)
 */
@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject(UserPassKey upkey) throws Exception {
    PooledConnectionAndInfo pci = null;
    PooledConnection pc = null;
    String username = upkey.getUsername();
    String password = upkey.getPassword();
    if (username == null) {
        pc = _cpds.getPooledConnection();
    } else {
        pc = _cpds.getPooledConnection(username, password);
    }
    if (pc == null) {
        throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
    }
    // should we add this object as a listener or the pool.
    // consider the validateObject method in decision
    pc.addConnectionEventListener(this);
    pci = new PooledConnectionAndInfo(pc, username, password);
    pcMap.put(pc, pci);
    return new DefaultPooledObject<>(pci);
}
Also used : DefaultPooledObject(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject) PooledConnection(javax.sql.PooledConnection)

Example 13 with DefaultPooledObject

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project datanucleus-rdbms by datanucleus.

the class CPDSConnectionFactory method makeObject.

@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject() {
    PooledConnectionAndInfo pci;
    try {
        PooledConnection pc = null;
        if (_username == null) {
            pc = _cpds.getPooledConnection();
        } else {
            pc = _cpds.getPooledConnection(_username, _password);
        }
        if (pc == null) {
            throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
        }
        // should we add this object as a listener or the pool.
        // consider the validateObject method in decision
        pc.addConnectionEventListener(this);
        pci = new PooledConnectionAndInfo(pc, _username, _password);
        pcMap.put(pc, pci);
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage());
    }
    return new DefaultPooledObject<>(pci);
}
Also used : DefaultPooledObject(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject) PooledConnection(javax.sql.PooledConnection) SQLException(java.sql.SQLException)

Example 14 with DefaultPooledObject

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project x-pipe by ctripcorp.

the class NettyClientFactory method makeObject.

@Override
public PooledObject<NettyClient> makeObject() throws Exception {
    ChannelFuture f = b.connect(address);
    f.get(connectTimeoutMilli, TimeUnit.MILLISECONDS);
    Channel channel = f.channel();
    logger.info("[makeObject]{}", channel);
    NettyClient nettyClient = new DefaultNettyClient(channel);
    channel.attr(NettyClientHandler.KEY_CLIENT).set(nettyClient);
    return new DefaultPooledObject<NettyClient>(nettyClient);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) SocketChannel(io.netty.channel.socket.SocketChannel)

Example 15 with DefaultPooledObject

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject in project tomcat by apache.

the class PoolingConnection method makeObject.

/**
 * {@link KeyedPooledObjectFactory} method for creating {@link PoolablePreparedStatement}s or
 * {@link PoolableCallableStatement}s. The <code>stmtType</code> field in the key determines whether a
 * PoolablePreparedStatement or PoolableCallableStatement is created.
 *
 * @param key
 *            the key for the {@link PreparedStatement} to be created
 * @see #createKey(String, int, int, StatementType)
 */
@Override
public PooledObject<DelegatingPreparedStatement> makeObject(final PStmtKey key) throws Exception {
    if (null == key) {
        throw new IllegalArgumentException("Prepared statement key is null or invalid.");
    }
    if (key.getStmtType() == StatementType.PREPARED_STATEMENT) {
        final PreparedStatement statement = (PreparedStatement) key.createStatement(getDelegate());
        // Unable to find way to avoid this
        @SuppressWarnings({ "rawtypes", "unchecked" }) final PoolablePreparedStatement pps = new PoolablePreparedStatement(statement, key, pstmtPool, this);
        return new DefaultPooledObject<>(pps);
    }
    final CallableStatement statement = (CallableStatement) key.createStatement(getDelegate());
    final PoolableCallableStatement pcs = new PoolableCallableStatement(statement, key, pstmtPool, this);
    return new DefaultPooledObject<>(pcs);
}
Also used : DefaultPooledObject(org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject) CallableStatement(java.sql.CallableStatement) PreparedStatement(java.sql.PreparedStatement)

Aggregations

DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)8 DefaultPooledObject (org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject)6 PooledConnection (javax.sql.PooledConnection)5 PooledObject (org.apache.commons.pool2.PooledObject)5 URISyntaxException (java.net.URISyntaxException)4 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 PooledObjectFactory (org.apache.commons.pool2.PooledObjectFactory)4 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)4 Test (org.junit.Test)4 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 ObjectName (javax.management.ObjectName)3 DefaultPooledObject (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject)3 Jedis (redis.clients.jedis.Jedis)3 JedisPool (redis.clients.jedis.JedisPool)3 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)3 Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2