/** * Acquires an object of type {@code T} from the pool. This operation is blocking if no resource * is available. Each call of {@link #acquire()} should be paired with another call of * {@link #release(Object)}} after the use of this resource completes to return this resource to * the pool. * * @return a resource taken from the pool */ @Override public T acquire() { return acquire(WAIT_INDEFINITELY, null); }
@Override public final State getState() { try (LockResource lr = new LockResource(mStateLock)) { return mState; } }
/** * @return the default option */ public static Options defaultOptions() { return new Options(); } }
/** * Creates a new block master client pool. * * @param subject the parent subject * @param address address of the worker * @param maxCapacity the maximum capacity of the pool * @param alluxioConf Alluxio configuration * is above the minimum capacity(1), it is closed and removed from the pool. */ public BlockWorkerClientPool(Subject subject, SocketAddress address, int maxCapacity, AlluxioConfiguration alluxioConf) { super(Options.defaultOptions().setMaxCapacity(maxCapacity).setGcExecutor(GC_EXECUTOR)); mSubject = subject; mAddress = address; mConf = alluxioConf; }
/** * Releases the lock and decrement the ref count if a ref counter was provided * at construction time. */ @Override public void close() { super.close(); mRefCount.decrementAndGet(); } }
/** * Tests the logic that invalid resource won't be acquired. */ @Test public void UnhealthyResource() throws Exception { TestPool pool = new TestPool(DynamicResourcePool.Options.defaultOptions()); Resource resource = pool.acquire(); Assert.assertEquals(0, resource.mInteger.intValue()); resource.setInteger(Resource.INVALID_RESOURCE); pool.release(resource); resource = pool.acquire(); // The 0-th resource is not acquired because it is unhealthy. Assert.assertEquals(1, resource.mInteger.intValue()); }
/** * Constructor of TestPool class. * * @param options the Options object to set ScheduledExecutorService object * @param clock the object of Clock class */ public TestPool(Options options, ManualClock clock) { super(options.setGcExecutor(GC_EXECUTOR)); mClock = clock; }
@Override protected boolean shouldGc(ResourceInternal<Resource> resourceInternal) { return mClock.millis() - resourceInternal.getLastAccessTimeMs() >= (long) mGcThresholdInSecs * (long) Constants.SECOND_MS; }
@Override protected void closeResource(Resource resource) { resource.setInteger(Resource.INVALID_RESOURCE); }
@Override protected Resource createNewResource() { return new Resource(mCounter++); }
/** * @return whether the stream is open */ public boolean isOpen() { try (LockResource lr = new LockResource(mLock)) { return !mClosed && !mCanceled && mError == null; } }
@Override public void close() { mLockedInodes.clear(); mEntries.forEach(entry -> entry.mLock.close()); mEntries.clear(); }
/** * Constructor of TestPool class. * * @param options the Options object to set ScheduledExecutorService object */ public TestPool(Options options) { super(options.setGcExecutor(GC_EXECUTOR)); }
/** * @return the set of threads present in the scheduler */ public static Set<String> getThreadNames() { try (LockResource r = new LockResource(sLock)) { return sTimers.keySet(); } }
@Override public void close() throws UnavailableException { try { mContext.close(); } finally { // The journal must be flushed before we can release the lock. mLockResource.close(); } } }
@Override public final void waitForState(State state) throws InterruptedException { try (LockResource lr = new LockResource(mStateLock)) { while (mState != state) { mStateCond.await(); } } } }
/** * Constructs a {@link MasterJournalContext}. * * @param asyncJournalWriter a {@link AsyncJournalWriter} * @param lock a lock to hold until the context is closed */ public RaftJournalContext(AsyncJournalWriter asyncJournalWriter, Lock lock) { mLockResource = new LockResource(lock); mContext = new MasterJournalContext(asyncJournalWriter); }
private void checkError() throws IOException { try (LockResource lr = new LockResource(mLock)) { if (mError != null) { // prevents rethrowing the same error mCanceled = true; throw toAlluxioStatusException(mError); } } }
@Override public BlockStoreMeta getBlockStoreMetaFull() { // Removed DEBUG logging because this is very noisy // LOG.debug("getBlockStoreMetaFull:"); BlockStoreMeta storeMeta; try (LockResource r = new LockResource(mMetadataReadLock)) { storeMeta = mMetaManager.getBlockStoreMetaFull(); } return storeMeta; }
@Override public BlockStoreMeta getBlockStoreMeta() { // Removed DEBUG logging because this is very noisy // LOG.debug("getBlockStoreMeta:"); BlockStoreMeta storeMeta; try (LockResource r = new LockResource(mMetadataReadLock)) { storeMeta = mMetaManager.getBlockStoreMeta(); } return storeMeta; }