/** {@inheritDoc} */ @Override public Iterator<FijiCell<T>> iterator() { if (!mDebugRegistered) { ResourceTracker.get().registerResource(this); mDebugRegistered = true; } return Iterables.concat(mColumnResults.values()).iterator(); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
new Class[]{iface}, new TrackedProxy<T>(resource)); get().registerResource(resource); return proxy;
/** * Private constructor. * * @param refreshPeriod Configures the refresh rate for the scheduler. * @param timeUnit Specifies the unit of time for the refreshPeriod. * @param refreshingLoader Used to initialize and refresh the cached value. * @param builder Thread factory builder. Expects that the name format is already set. * @param loopController Used to deterministically control refresh cycles during testing. */ private RefreshingReference( final Long refreshPeriod, final TimeUnit timeUnit, final RefreshingLoader<T> refreshingLoader, final ThreadFactoryBuilder builder, final Optional<LoopController> loopController ) { mRef = new AtomicReference<>(WithTimestamp.create(refreshingLoader.initial())); mScheduler = Executors.newSingleThreadScheduledExecutor( builder .setDaemon(true) .build() ); mRefreshingLoader = refreshingLoader; final RefreshingRunnable runnable = new RefreshingRunnable(); mScheduler.scheduleAtFixedRate(runnable, refreshPeriod, refreshPeriod, timeUnit); mLoopController = loopController; ResourceTracker.get().registerResource(this); }
/** * Open a table reader whose behavior is customized by overriding CellSpecs. * * @param table Fiji table from which this reader will read. * @param cellSpecOverrides specifications of overriding read behaviors. * @throws java.io.IOException in case of an error opening the reader. */ private CassandraFijiTableReader( final CassandraFijiTable table, final Map<FijiColumnName, CellSpec> cellSpecOverrides ) throws IOException { mTable = table; mCellSpecOverrides = cellSpecOverrides; mOnDecoderCacheMiss = FijiTableReaderBuilder.DEFAULT_CACHE_MISS; mOverrides = null; mAlternatives = null; mLayoutConsumerRegistration = mTable.registerLayoutConsumer(mInnerLayoutUpdater); Preconditions.checkState(mReaderLayoutCapsule != null, "FijiTableReader for table: %s failed to initialize.", mTable.getURI()); // Retain the table only when everything succeeds. mTable.retain(); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiTableReader instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** * Open a table reader whose behavior is customized by overriding CellSpecs. * * @param table Fiji table from which this reader will read. * @param cellSpecOverrides specifications of overriding read behaviors. * @throws IOException in case of an error opening the reader. */ private HBaseFijiTableReader( final HBaseFijiTable table, final Map<FijiColumnName, CellSpec> cellSpecOverrides ) throws IOException { mTable = table; mCellSpecOverrides = cellSpecOverrides; mOnDecoderCacheMiss = FijiTableReaderBuilder.DEFAULT_CACHE_MISS; mOverrides = null; mAlternatives = null; mLayoutConsumerRegistration = mTable.registerLayoutConsumer(new InnerLayoutUpdater()); Preconditions.checkState(mReaderLayoutCapsule != null, "FijiTableReader for table: %s failed to initialize.", mTable.getURI()); // Retain the table only when everything succeeds. mTable.retain(); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiTableReader instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** * Creates a buffered fiji table writer that stores modifications to be sent on command * or when the buffer is full. * * @param table A fiji table. * @throws com.moz.fiji.schema.FijiTableNotFoundException in case of an invalid table parameter * @throws java.io.IOException in case of IO errors. */ public CassandraFijiBufferedWriter(final CassandraFijiTable table) throws IOException { mTable = table; mLayoutConsumerRegistration = mTable.registerLayoutConsumer(new InnerLayoutUpdater()); Preconditions.checkState( mCapsule != null, "CassandraFijiBufferedWriter for table: %s failed to initialize.", mTable.getURI()); mBufferedStatements = ArrayListMultimap.create( mTable.getLayout().getLocalityGroups().size(), (int) mMaxWriteBufferSize); // Retain the table only after everything else succeeded: mTable.retain(); synchronized (mMonitor) { Preconditions.checkState(mState == State.UNINITIALIZED, "Cannot open CassandraFijiBufferedWriter instance in state %s.", mState); mState = State.OPEN; } ResourceTracker.get().registerResource(this); }
newEntry.incrementAndGetCount(); if (mTracking) { ResourceTracker.get().registerResource(value);
/** * Open a connection to the HBase schema table for a Fiji instance. * * @param fijiURI the FijiURI * @param conf The Hadoop configuration. * @param tableFactory HTableInterface factory. * @throws IOException on I/O error. */ public HBaseSchemaTable( FijiURI fijiURI, Configuration conf, HTableInterfaceFactory tableFactory ) throws IOException { mURI = fijiURI; mSchemaHashTable = newSchemaHashTable(mURI, conf, tableFactory); mSchemaIdTable = newSchemaIdTable(mURI, conf, tableFactory); mZKClient = ZooKeeperUtils.getZooKeeperClient(mURI); mZKLock = new ZooKeeperLock(mZKClient, ZooKeeperUtils.getSchemaTableLock(mURI)); final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open SchemaTable instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
/** * Creates a buffered fiji table writer that stores modifications to be sent on command * or when the buffer overflows. * * @param table A fiji table. * @throws FijiTableNotFoundException in case of an invalid table parameter * @throws IOException in case of IO errors. */ public HBaseFijiBufferedWriter(HBaseFijiTable table) throws IOException { mTable = table; try { mHTable = mTable.openHTableConnection(); } catch (TableNotFoundException e) { throw new FijiTableNotFoundException(table.getURI()); } mLayoutConsumerRegistration = mTable.registerLayoutConsumer(new InnerLayoutUpdater()); Preconditions.checkState(mWriterLayoutCapsule != null, "HBaseFijiBufferedWriter for table: %s failed to initialize.", mTable.getURI()); SchemaPlatformBridge.get().setAutoFlush(mHTable, false); // Retain the table only after everything else succeeded: mTable.retain(); synchronized (mInternalLock) { Preconditions.checkState(mState == State.UNINITIALIZED, "Cannot open HBaseFijiBufferedWriter instance in state %s.", mState); mState = State.OPEN; } ResourceTracker.get().registerResource(this); }
Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiTable instance in state %s.", oldState); ResourceTracker.get().registerResource(this);
/** * Creates a new <code>FijiRowScanner</code> instance. * * @param options The options for this scanner. * @throws IOException on I/O error. */ public HBaseFijiRowScanner(Options options) throws IOException { mDataRequest = options.getDataRequest(); mTable = options.getTable(); mScan = options.getScan(); mCellDecoderProvider = options.getCellDecoderProvider(); mReopenScannerOnTimeout = options.getReopenScannerOnTimeout(); mEntityIdFactory = EntityIdFactory.getFactory(mTable.getLayout()); mHTable = mTable.openHTableConnection(); try { mResultScanner = openResultScanner(); mNextResult = getNextResult(); } catch (FijiIOException ioe) { if (mHTable != null) { mHTable.close(); } throw ioe; } final State oldState = mState.getAndSet(State.OPEN); Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open FijiRowScanner instance in state %s.", oldState); ResourceTracker.get().registerResource(this); }
Preconditions.checkState(oldState == State.UNINITIALIZED, "Cannot open SchemaTable instance in state %s.", oldState); ResourceTracker.get().registerResource(this);