List of usage examples for org.apache.commons.pool2 PooledObject getObject
T getObject();
From source file:org.apache.omid.tso.TestBatch.java
@Test(timeOut = 10_000) public void testBatchFactoryFunctionality() throws Exception { // Component to test Batch.BatchFactory factory = new Batch.BatchFactory(BATCH_SIZE); // Check the factory creates a new batch properly... Batch batch = factory.create();/*from ww w. j a v a 2s . com*/ assertTrue(batch.isEmpty(), "Batch should be empty"); assertFalse(batch.isFull(), "Batch shouldn't be full"); assertEquals(batch.getNumEvents(), 0, "Num events should be 0"); // ...and is wrapped in to a pooled object PooledObject<Batch> pooledBatch = factory.wrap(batch); assertEquals(pooledBatch.getObject(), batch); // Put some elements in the batch... batch.addTimestamp(ANY_ST, channel, monCtx); batch.addCommit(ANY_ST, ANY_CT, channel, monCtx); batch.addCommitRetry(ANY_ST, channel, monCtx); batch.addAbort(ANY_ST, channel, monCtx); assertFalse(batch.isEmpty(), "Batch should contain elements"); assertFalse(batch.isFull(), "Batch should NOT be full"); assertEquals(batch.getNumEvents(), 4, "Num events should be 4"); // ... and passivate the object through the factory. It should reset the state of the batch factory.passivateObject(pooledBatch); assertTrue(batch.isEmpty(), "Batch should NOT contain elements"); assertFalse(batch.isFull(), "Batch should NOT be full"); assertEquals(batch.getNumEvents(), 0, "Num events should be 0"); }
From source file:org.apache.sentry.service.thrift.SentryServiceClientPoolFactory.java
@Override public void destroyObject(PooledObject<SentryPolicyServiceClient> pooledObject) { SentryPolicyServiceClient client = pooledObject.getObject(); LOGGER.debug("Destroying Sentry Service Client: " + client); if (client != null) { // The close() of TSocket or TSaslClientTransport is called actually, and there has no // exception even there has some problems, eg, the client is closed already. // The close here is just try to close the socket and the client will be destroyed soon. client.close();//from ww w. j a v a 2s. co m } }
From source file:org.bimserver.renderengine.RenderEnginePool.java
public RenderEnginePool(int poolSize, RenderEngineFactory renderEngineFactory) throws RenderEngineException { super(new PooledObjectFactory<RenderEngine>() { @Override//from w w w . ja v a2 s . c om public void activateObject(PooledObject<RenderEngine> arg0) throws Exception { arg0.getObject().init(); } @Override public void destroyObject(PooledObject<RenderEngine> arg0) throws Exception { } @Override public PooledObject<RenderEngine> makeObject() throws Exception { return new DefaultPooledObject<RenderEngine>(renderEngineFactory.createRenderEngine()); } @Override public void passivateObject(PooledObject<RenderEngine> arg0) throws Exception { } @Override public boolean validateObject(PooledObject<RenderEngine> arg0) { return false; } }); setMaxTotal(8); // available = new ArrayBlockingQueue<>(poolSize); // busy = new HashSet<>(); // for (int i=0; i<poolSize; i++) { // available.add(renderEngineFactory.createRenderEngine()); // } }
From source file:org.cloudgraph.hbase.connect.PooledConnectionFactory.java
@Override public void destroyObject(PooledObject<Connection> p) throws Exception { if (log.isDebugEnabled()) log.debug("destroying connection" + p.getObject()); p.getObject().destroy();//from www . ja v a2s . co m super.destroyObject(p); }
From source file:org.cloudgraph.hbase.connect.PooledConnectionFactory.java
@Override public boolean validateObject(PooledObject<Connection> p) { if (log.isDebugEnabled()) log.debug("validating connection" + p.getObject()); return super.validateObject(p); }
From source file:org.cloudgraph.hbase.connect.PooledConnectionFactory.java
@Override public void activateObject(PooledObject<Connection> p) throws Exception { if (log.isDebugEnabled()) log.debug("activate connection" + p.getObject()); super.activateObject(p); }
From source file:org.cloudgraph.hbase.connect.PooledConnectionFactory.java
@Override public void passivateObject(PooledObject<Connection> p) throws Exception { if (log.isDebugEnabled()) log.debug("passivate connection" + p.getObject()); super.passivateObject(p); }
From source file:org.darkphoenixs.pool.hbase.HbaseConnectionFactory.java
@Override public void destroyObject(PooledObject<Connection> p) throws Exception { Connection connection = p.getObject(); if (connection != null) connection.close();/*from ww w. ja va2s . co m*/ }
From source file:org.darkphoenixs.pool.hbase.HbaseConnectionFactory.java
@Override public boolean validateObject(PooledObject<Connection> p) { Connection connection = p.getObject(); if (connection != null) return ((!connection.isAborted()) && (!connection.isClosed())); return false; }
From source file:org.darkphoenixs.pool.jdbc.JdbcConnectionFactory.java
@Override public boolean validateObject(PooledObject<Connection> p) { Connection connection = p.getObject(); if (connection != null) try {/*from w w w . j a v a 2 s. com*/ return ((!connection.isClosed()) && (connection.isValid(1))); } catch (SQLException e) { e.printStackTrace(); } return false; }