/** * Shuts down the scheduler and calls the close method in the RefreshingLoader. Attempts * to wait for concurrent execution, but does not wait indefinitely. * * @throws IOException If the RefreshingLoader encounters an error on closing. */ public void close() throws IOException { close(false); } }
/** * Creates a LoopController with barriers awaiting 2 threads. * * @return A new LoopController. */ public static LoopController create() { return new LoopController(2); }
/** * Allows the user to advance the refresh cycle a given number of loops. * * @param numLoops The number of loops to advance. */ public void advance( final int numLoops ) { for (int i=0; i < numLoops; i++) { advance(); } }
/** {@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); } } }
/** * 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); }
/** * Get a referenced table layout monitor for a table from the cache. * @param tableName table whose layout monitor should be returned. * @param cache of table layout monitors. */ public ReferencedTableLayoutMonitor( String tableName, ReferenceCountedCache<String, TableLayoutMonitor> cache) { mTableName = tableName; mCache = cache; mTableLayoutMonitor = mCache.get(mTableName); }
/** {@inheritDoc} */ @Override public void close() throws IOException { mCache.release(mTableName); }
/** * Make a best effort at closing all the cached values. This method is *not* guaranteed to close * every cached value if there are concurrent users of the cache. As a result, this method * should only be relied upon if only a single thread is using this cache while {@code #close} is * called. * * @throws IOException if any entry throws an IOException while closing. An entry throwing an * IOException will prevent any further entries from being closed. */ @Override public void close() throws IOException { mCache.close(); }
/** * Log a reference in the cleanup log with it's message. * * @param reference to log. */ private static void logReference(ResourceReference reference) { CLEANUP_LOG.error("Leaked resource detected: {}\n{}", reference.getMessage(), reference.getStackTrace()); }
/** {@inheritDoc} */ @Override public final void after( final RESOURCE releasable ) throws IOException { releasable.release(); } }
/** * Returns whether this cache contains <i>or</i> contained a cached entry for the provided key. * * @param key to check for a cached entry. * @return whether this cache contains <i>or</i> contained a cached entry for the key. */ public boolean containsKey(final K key) { return mCache.containsKey(key); }
/** * Wraps an existing iterator and removes consecutive duplicate elements. * * @param iterator The iterator to deduplicate. * @param <T> The value type of the iterator. * @return An iterator which lazily deduplicates elements. */ public static <T> Iterator<T> deduplicatingIterator(final Iterator<T> iterator) { return new DeduplicatingIterator<>(iterator); }
/** * Create a new StreamRedirect from the given InputStream to the given OutputStream. * * @param in InputStream to redirect to the given OutputStream. * @param out OutputStream into which to redirect values from the given InputStream. * @return a new StreamRedirect from the given InputStream to the given OutputStream. */ public static StreamRedirect create( final InputStream in, final OutputStream out ) { return new StreamRedirect(in, out); }
/** * Write a printable representation of a byte array. * * Copied from HBase's {@code org.apache.hadoop.hbase.util.Bytes} class. * * @param b byte array * @return string */ public static String toStringBinary(final byte [] b) { if (b == null) { return "null"; } return toStringBinary(b, 0, b.length); }
/** * This static factory constructor allows the user to specify a time of * creation. * * @param object The object that will be wrapped. * @param timestamp Specifies the time this object was created in milliseconds * since the epoch. * @return A new WithTimestamp instance. * @param <U> The type that will be stored. */ public static <U> WithTimestamp<U> create( final U object, final long timestamp ) { return new WithTimestamp<U>(object, timestamp); }
/** * Returns the current value of this reference. * May be an old value if the scheduler has not refreshed the value recently. * * @return The current value of this reference. */ public T get() { return mRef.get().getValue(); }
/** * Get the publicly resolvable hostname of the current host machine. * * @return The publicly resolvable hostname of the current host machine. */ public static InetAddress getPublicLocalHost() { return localToPublic(new InetSocketAddress(0)).getAddress(); }
/** {@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); } } }
/** * Close all cached ZooKeeper connections. * * <p> * This method closes all ZooKeeper connections that have been returned from * {@link #getZooKeeperClient}. Clients who continue to use these connections will receive * {@code IOExceptions}. This method should only be called when Fiji objects will no longer be * used in the JVM. * </p> * * @throws java.io.IOException on I/O Exception */ public static void closeAllZooKeeperConnections() throws IOException { ZK_CLIENT_CACHE.close(); }
/** * Creates a LoopController and allows the user to define the number of threads the barriers will * await execution on. * * @param numThreads The number of different threads the barriers will await execution on. * @return A new LoopController. */ public static LoopController create( final int numThreads ) { return new LoopController(numThreads); }