/** * 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); }
/** * Get an open session to the Cassandra cluster with the given cluster key. * * @param key The Cassandra cluster information. * @return An open session. */ private static Session getSession(final ClusterKey key) { LOG.debug("Retrieving cached session with key: {}.", key); return new CachedSession(key, CACHE.get(key).getSession()); }
/** * 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); }
/** * Create a new cached Curator Framework with the provided cache, key and namespace. * * @param cache holding delegate CuratorFramework instances. * @param key key in cache. * @param namespace to constrain client to, or null for root. * @return a new CuratorFramework with a shared ZooKeeper connection and resource tracking. * @param <K> type of key in cache. */ public static <K> CuratorFramework create( final ReferenceCountedCache<K, CuratorFramework> cache, final K key, final String namespace ) { // Cast is safe; all implementations of CuratorFramework subclass CuratorFrameworkImpl final CuratorFrameworkImpl delegate = (CuratorFrameworkImpl) cache.get(key); if (namespace == null) { return new CachedCuratorFrameworkImpl<K>(cache, key, delegate); } else { return new CachedNamespacedCuratorFramework<K>(cache, key, delegate, namespace); } }