/** * Create a new cached CachedCuratorFrameworkImpl with the provided cache and key. * * @param cache holding delegate CuratorFramework instances. * @param key key in cache. * @param delegate to proxy through ZooKeeper operations. */ private CachedCuratorFrameworkImpl( final ReferenceCountedCache<K, CuratorFramework> cache, final K key, final CuratorFrameworkImpl delegate ) { super(delegate); mCache = cache; mCacheKey = key; ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public void close() throws IOException { try { mCloser.close(); } finally { if (mDebugRegistered) { ResourceTracker.get().unregisterResource(this); mDebugRegistered = false; } } }
/** * Constructs a ZooKeeper lock object. * * @param zkClient ZooKeeper client. Will be not be closed by this lock. * @param lockDir Path of the directory node to use for the lock. */ public ZooKeeperLock(CuratorFramework zkClient, File lockDir) { mZKClient = zkClient; mLockDir = lockDir; mLockPathPrefix = new File(lockDir, LOCK_NAME_PREFIX); ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public Object invoke( final Object proxy, final Method method, final Object[] args ) throws Throwable { if (method.getName().equals("close") && args == null) { get().unregisterResource(mResource); } return method.invoke(mResource, args); } }
/** * Create a new cached CachedCuratorFrameworkImpl with the provided cache and key. * * @param cache holding delegate CuratorFramework instances. * @param key key in cache. * @param delegate to proxy through ZooKeeper operations. */ private CachedNamespacedCuratorFramework( final ReferenceCountedCache<K, CuratorFramework> cache, final K key, final CuratorFrameworkImpl delegate, final String namespace ) { super(delegate, namespace); mCache = cache; mCacheKey = key; ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public void unlock() throws IOException { synchronized (this) { ResourceTracker.get().unregisterResource(mCreatedPath); unlockInternal(); } }
/** {@inheritDoc} */ @Override public Iterator<FijiCell<T>> iterator() { if (!mDebugRegistered) { ResourceTracker.get().registerResource(this); mDebugRegistered = true; } return Iterables.concat(mColumnResults.values()).iterator(); }
/** {@inheritDoc} */ @Override public void close() throws IOException { ResourceTracker.get().unregisterResource(this); mTable.release(); } }
/** * Wrap an existing HTable connection that is assumed to be the table that stores the * Fiji instance properties. * * @param uri URI of the Fiji instance this table belongs to. * @param htable An HTable to wrap. */ public HBaseSystemTable(FijiURI uri, HTableInterface htable) { mURI = uri; mTable = htable; final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open SystemTable instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public synchronized void close() throws IOException { final State oldState = mState.getAndSet(State.CLOSED); Preconditions.checkState(oldState == State.OPEN, "Cannot close MetaTable instance in state %s.", oldState); ResourceTracker.get().unregisterResource(this); mTable.close(); }
/** * Constructs a new pool of Fiji tables with the specified parameters. This class should not * be instantiated outside of the builder {@link FijiTablePoolBuilder}. * * @param builder FijiTablePoolBuilder which contains the configuration parameters to build * this FijiTablePool with. */ private FijiTablePool(FijiTablePoolBuilder builder) { mTableFactory = builder.mFijiTableFactory; mClock = builder.mClock; mMinSize = builder.mMinSize; mMaxSize = builder.mMaxSize; mIdleTimeout = builder.mIdleTimeout; mIdlePollPeriod = builder.mIdlePollPeriod; mPoolCache = new HashMap<String, Pool>(); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiTablePool instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public void close() throws IOException { synchronized (this) { if (mCreatedPath != null) { // This will trigger a leaked acquired lock resource error in the cleanup log by not // unregistering mCreatedPath with the ResourceTracker. unlockInternal(); } ResourceTracker.get().unregisterResource(this); } } }
/** * Create a connection to a Fiji meta table backed by an HTable within HBase. * * <p>This class takes ownership of the HTable. It will be closed when this instance is * closed.</p> * * @param fijiURI URI of the Fiji instance this meta-table belongs to. * @param htable The HTable to use for storing Fiji meta data. * @param tableLayoutDatabase A database of table layouts to delegate layout storage to. * @param tableKeyValueDatabase A database of key-value pairs to delegate metadata storage to. */ private HBaseMetaTable( FijiURI fijiURI, HTableInterface htable, FijiTableLayoutDatabase tableLayoutDatabase, FijiTableKeyValueDatabase<?> tableKeyValueDatabase) { mFijiURI = fijiURI; mTable = htable; mTableLayoutDatabase = tableLayoutDatabase; mTableKeyValueDatabase = tableKeyValueDatabase; final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open MetaTable instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public synchronized void close() throws IOException { final State oldState = mState.getAndSet(State.CLOSED); Preconditions.checkState(oldState == State.OPEN, "Cannot close FijiSystemTable instance in state %s.", oldState); ResourceTracker.get().unregisterResource(this); mTable.close(); }
/** * Constructs a ZooKeeper lock object. * * @param zookeeper ZooKeeper client. * @param lockDir Path of the directory node to use for the lock. */ public ZooKeeperLock(ZooKeeperClient zookeeper, File lockDir) { this.mConstructorStack = CLEANUP_LOG.isDebugEnabled() ? Debug.getStackTrace() : null; this.mZKClient = zookeeper; this.mLockDir = lockDir; this.mLockPathPrefix = new File(lockDir, LOCK_NAME_PREFIX); // ZooKeeperClient.retain() should be the last line of the constructor. this.mZKClient.retain(); ResourceTracker.get().registerResource(this); }
/** {@inheritDoc} */ @Override public void close() throws IOException { final State oldState = mState.getAndSet(State.CLOSED); Preconditions.checkState(oldState == State.OPEN, "Cannot close FijiRowScanner instance in state %s.", oldState); ResourceTracker.get().unregisterResource(this); mResultScanner.close(); mHTable.close(); }
/** * Returns the value associated with {@code key} in this cache, first creating that value if * necessary. No observable state associated with this cache is modified until loading completes. * * @param key for which to retrieve cached value. * @return cached value associated with the key. */ @SuppressWarnings("unchecked") public V get(final K key) { final V value = mCache.get(key); final ReferenceCountedProxy<K, V> proxy = new ReferenceCountedProxy<>(value, key, mCache, mTrackProxies); if (mTrackProxies) { ResourceTracker.get().registerResource(proxy); } return (V) Proxy.newProxyInstance(value.getClass().getClassLoader(), mIface, proxy); }
/** {@inheritDoc} */ @Override public void close() throws IOException { final State oldState = mState.getAndSet(State.CLOSED); Preconditions.checkState(oldState == State.OPEN, "Cannot close FijiTableReader instance %s in state %s.", this, oldState); ResourceTracker.get().unregisterResource(this); mLayoutConsumerRegistration.close(); mTable.release(); }
new Class[]{iface}, new TrackedProxy<T>(resource)); get().registerResource(resource); return proxy;
/** {@inheritDoc} */ @Override public void close() { try { mCache.release(mCacheKey); } catch (IOException e) { // Impossible since {@link CuratorFramework#close()} does not throw IOException. throw new InternalFijiError(e); } finally { ResourceTracker.get().unregisterResource(this); } } }