public void requestReturnFromBorrowersIfNotInUse() throws InterruptedException { globalPool.requestReturnFromBorrowersIfNotInUse(); }
@Override public boolean scan(final ScanHandler<ObjectHolder<T>> handler) throws Exception { return globalPool.scan(handler); }
@Override public boolean tryDispose(final long timeoutMillis) throws ObjectDisposeException, InterruptedException { return globalPool.tryDispose(timeoutMillis); }
/** * Test of get method, of class SimpleSmartObjectPool. */ @Test public void testPool() throws InterruptedException, TimeoutException, ObjectCreationException, ObjectDisposeException { borowedObject = instance.get(this); Assert.assertNotNull(borowedObject); instance.recycle(borowedObject, this); instance.dispose(); } }
public SimpleSmartObjectPoolTest() throws ObjectCreationException { instance = new SimpleSmartObjectPool(2, 10, new RecyclingSupplier.Factory<TestObject>() { @Override public TestObject create() { TestObject obj = new TestObject("Object"); LOG.debug("Created {}", obj); return obj; } @Override public void dispose(final TestObject object) throws ObjectDisposeException { try { LOG.debug("Disposing Object {}", object); object.dispose(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } @Override public boolean validate(final TestObject object, final Exception e) { throw new UnsupportedOperationException("Not supported yet."); } }, true); }
@Override @SuppressFBWarnings("MDM_THREAD_YIELD") public Either<Action, SimpleSmartObjectPoolTest.TestObject> tryRequestReturnObject() { if (borowedObject != null) { try { Thread.sleep(1000); } catch (InterruptedException ex) { throw new RuntimeException(ex); } instance.recycle(borowedObject, this); } return Either.left(Action.NONE); }
ObjectDisposeException exception = disposeReturnedObjects(null); while (!borrowedObjects.isEmpty()) { long waitTimeNanos = deadlineNanos - TimeSource.nanoTime(); return false; exception = disposeReturnedObjects(exception);
ScalableObjectPool(final int initialSize, final int maxSize, @Nonnull final RecyclingSupplier.Factory<T> factory, final boolean fair) throws ObjectCreationException { globalPool = new SimpleSmartObjectPool<>(initialSize, maxSize, new ObjectHolderFactory<>(initialSize, factory), fair); localPool = new ThreadLocal<LocalObjectPool<T>>() { @Override protected LocalObjectPool<T> initialValue() { return new LocalObjectPool<>(globalPool); } }; }