/** * Returns the specified object to the underlying {@code ObjectPool}. */ @Override public void releaseTarget(Object target) throws Exception { if (this.pool != null) { this.pool.returnObject(target); } }
@Override public CompletableFuture<Void> returnObjectAsync(T o) throws Exception { pool.returnObject(o); return COMPLETED; } }
@Override public void returnObject(T o) throws Exception { pool.returnObject(o); }
public void sendMessage() throws Exception { final SMPPSession session = sessionPool.borrowObject(); try { final String messageId = session.submitShortMessage( serviceType, sourceTon, sourceNpi, sourceAddress, destinationTon, destinationNpi, destinationAddress, esm, protocolId, priorityFlag, scheduleDeliveryTime, validityPeriod, registeredDelivery, replaceIfPresentFlag, dataCoding, smDefaultMsgId, message ); Log.debug( "Message submitted, message_id is '{}'.", messageId ); } finally { sessionPool.returnObject( session ); } } }
/** * {@inheritDoc} */ @Override public void returnObject(final T obj) { final WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { pool.returnObject(obj); } catch (final Exception e) { // swallowed as of Pool 2 } finally { writeLock.unlock(); } }
@Override public void returnObject(final T proxy) throws Exception { final T pooledObject = proxySource.resolveProxy(proxy); pool.returnObject(pooledObject); }
pool.invalidateObject(obj); } else { pool.returnObject(obj);
_pool.returnObject(obj); } catch(final Exception e) { _error = e;
private static List<String> invokeEveryMethod(final ObjectPool<Object> op) throws Exception { op.addObject(); op.borrowObject(); op.clear(); op.close(); op.getNumActive(); op.getNumIdle(); op.invalidateObject(new Object()); op.returnObject(new Object()); op.toString(); final List<String> expectedMethods = Arrays.asList(new String[] { "addObject", "borrowObject", "clear", "close", "getNumActive", "getNumIdle", "invalidateObject", "returnObject", "toString" }); return expectedMethods; }
pool.returnObject(o); expectedMethods.add("returnObject"); assertEquals(expectedMethods, calledMethods); pool.returnObject(o); expectedMethods.add("returnObject"); pool.returnObject(o); expectedMethods.add("getNumIdle"); expectedMethods.add("invalidateObject");
@Test public void testBorrowObject() throws Exception { final TestObject obj = pool.borrowObject(); assertNotNull(obj); // Make sure proxied methods are working obj.setData(DATA1); assertEquals(DATA1, obj.getData()); pool.returnObject(obj); }
@Test public void testBaseClosePool() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } final String obj = _pool.borrowObject(); _pool.returnObject(obj); _pool.close(); try { _pool.borrowObject(); fail("Expected IllegalStateException"); } catch(final IllegalStateException e) { // expected } }
@Test(expected=IllegalStateException.class) public void testAccessAfterReturn() throws Exception { final TestObject obj = pool.borrowObject(); assertNotNull(obj); // Make sure proxied methods are working obj.setData(DATA1); assertEquals(DATA1, obj.getData()); pool.returnObject(obj); assertNotNull(obj); obj.getData(); }
String obj2 = _pool.borrowObject(); assertEquals(getNthObject(2),obj2); _pool.returnObject(obj2); obj2 = _pool.borrowObject(); assertEquals(getNthObject(2),obj2); _pool.returnObject(obj1); obj1 = _pool.borrowObject(); assertEquals(getNthObject(1),obj1); _pool.returnObject(obj0); _pool.returnObject(obj2); obj2 = _pool.borrowObject(); if (isLifo()) {
pool.returnObject(obj); clear(factory, expectedMethods); factory.setPassivateObjectFail(true); pool.returnObject(obj); factory.setPassivateObjectFail(true); factory.setDestroyObjectFail(true); pool.returnObject(obj); pool.close();
expectedMethods.add(new MethodCall("validateObject", ZERO).returned(Boolean.TRUE)); assertEquals(expectedMethods, factory.getMethodCalls()); pool.returnObject(obj);
@Test public void testBaseClear() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj0 = _pool.borrowObject(); final String obj1 = _pool.borrowObject(); assertEquals(2,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.returnObject(obj1); _pool.returnObject(obj0); assertEquals(0,_pool.getNumActive()); assertEquals(2,_pool.getNumIdle()); _pool.clear(); assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final Object obj2 = _pool.borrowObject(); assertEquals(getNthObject(2),obj2); _pool.close(); }
@Test public void testBaseNumActiveNumIdle() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj0 = _pool.borrowObject(); assertEquals(1,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj1 = _pool.borrowObject(); assertEquals(2,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.returnObject(obj1); assertEquals(1,_pool.getNumActive()); assertEquals(1,_pool.getNumIdle()); _pool.returnObject(obj0); assertEquals(0,_pool.getNumActive()); assertEquals(2,_pool.getNumIdle()); _pool.close(); }
@Test public void testBaseAddObject() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } try { assertEquals(0,_pool.getNumIdle()); assertEquals(0,_pool.getNumActive()); _pool.addObject(); assertEquals(1,_pool.getNumIdle()); assertEquals(0,_pool.getNumActive()); final String obj = _pool.borrowObject(); assertEquals(getNthObject(0),obj); assertEquals(0,_pool.getNumIdle()); assertEquals(1,_pool.getNumActive()); _pool.returnObject(obj); assertEquals(1,_pool.getNumIdle()); assertEquals(0,_pool.getNumActive()); } catch(final UnsupportedOperationException e) { return; // skip this test if one of those calls is unsupported } finally { _pool.close(); } }
assertEquals("A closed pool should still keep count of active objects.", 2, pool.getNumActive()); pool.returnObject(o1); if (pool.getNumIdle() >= 0) { assertEquals("returnObject should not add items back into the idle object pool for a closed pool.", 0, pool.getNumIdle());