Example usage for org.apache.commons.pool2.impl DefaultPooledObject DefaultPooledObject

List of usage examples for org.apache.commons.pool2.impl DefaultPooledObject DefaultPooledObject

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl DefaultPooledObject DefaultPooledObject.

Prototype

public DefaultPooledObject(T object) 

Source Link

Document

Create a new instance that wraps the provided object so that the pool can track the state of the pooled object.

Usage

From source file:com.baidu.jprotobuf.pbrpc.transport.ChannelPoolObjectFactory.java

@Override
public PooledObject<Connection> wrap(Connection connection) {
    InetSocketAddress address;//from  ww w  . j ava 2  s .  c om
    if (host == null) {
        address = new InetSocketAddress(port);
    } else {
        address = new InetSocketAddress(host, port);
    }
    ChannelFuture future = this.rpcClient.connect(address);

    // Wait until the connection is made successfully.
    future.awaitUninterruptibly();
    if (!future.isSuccess()) {
        LOGGER.log(Level.SEVERE, "failed to get result from stp", future.cause());
    } else {
        connection.setIsConnected(true);
    }

    future.addListener(new RpcChannelFutureListener(connection));
    connection.setFuture(future);

    return new DefaultPooledObject<Connection>(connection);
}

From source file:com.xoriant.jmx.pool.JmxPoolFactory.java

/**
 *  This method will wrap the pool object.
 *///from  www.  ja  va2s. c om
@Override
public PooledObject<Q> wrap(Q jmxConnector) {
    return new DefaultPooledObject<Q>(jmxConnector);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.apns.StubAPNSConnectionKeyedPooledObjectFactory.java

@Override
public PooledObject<APNSConnection> wrap(APNSConnection value) {
    return new DefaultPooledObject<APNSConnection>(value);
}

From source file:com.sky.projects.pool.hbase.HbaseConnectionFactory.java

@Override
public PooledObject<HConnection> makeObject() throws Exception {
    return new DefaultPooledObject<HConnection>(this.createConnection());
}

From source file:com.google.devtools.build.lib.worker.WorkerFactory.java

/**
 * Use the DefaultPooledObject implementation.
 *///from   w  ww . j av  a  2 s  .com
@Override
public PooledObject<Worker> wrap(Worker worker) {
    return new DefaultPooledObject<>(worker);
}

From source file:com.sky.projects.pool.jdbc.JdbcConnectionFactory.java

@Override
public PooledObject<Connection> makeObject() throws Exception {
    return new DefaultPooledObject<Connection>(this.createConnection());
}

From source file:com.lambdaworks.redis.RedisConnectionPool.java

private PooledObjectFactory<T> createFactory(final RedisConnectionProvider<T> redisConnectionProvider) {
    return new BasePooledObjectFactory<T>() {

        @SuppressWarnings("unchecked")
        @Override/* w w  w.  j ava  2s  . c o  m*/
        public T create() throws Exception {

            T connection = redisConnectionProvider.createConnection();
            PooledConnectionInvocationHandler<T> h = new PooledConnectionInvocationHandler<>(connection,
                    RedisConnectionPool.this);

            Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(),
                    new Class<?>[] { redisConnectionProvider.getComponentType() }, h);

            return (T) proxy;
        }

        @Override
        public PooledObject<T> wrap(T obj) {
            return new DefaultPooledObject<>(obj);
        }

        @Override
        public boolean validateObject(PooledObject<T> p) {
            return Connections.isOpen(p.getObject());
        }

        @Override
        @SuppressWarnings("unchecked")
        public void destroyObject(PooledObject<T> p) throws Exception {

            T object = p.getObject();
            if (Proxy.isProxyClass(object.getClass())) {
                PooledConnectionInvocationHandler<T> invocationHandler = (PooledConnectionInvocationHandler<T>) Proxy
                        .getInvocationHandler(object);

                object = invocationHandler.getConnection();
            }

            Connections.close(object);
        }
    };
}

From source file:de.qucosa.dissemination.epicur.servlet.EpicurDisseminationServlet.java

@Override
public void init() {
    httpClient = HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager())
            .build();/*from   w  w w  . ja v  a  2s.com*/

    marshallerPool = new GenericObjectPool<>(new BasePooledObjectFactory<Marshaller>() {
        @Override
        public Marshaller create() throws Exception {
            Marshaller marshaller = JAXBContext.newInstance(Epicur.class).createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, XEPICUR_SCHEMA_LOCATION);
            return marshaller;
        }

        @Override
        public PooledObject<Marshaller> wrap(Marshaller marshaller) {
            return new DefaultPooledObject<>(marshaller);
        }
    });
}

From source file:gobblin.hive.HiveMetaStoreClientFactory.java

@Override
public PooledObject<IMetaStoreClient> wrap(IMetaStoreClient client) {
    return new DefaultPooledObject<>(client);
}

From source file:net.identio.server.service.authentication.ldap.LdapConnectionFactory.java

@Override
public PooledObject<InitialLdapContext> wrap(InitialLdapContext ctx) {
    return new DefaultPooledObject<>(ctx);
}