/** * USED ONLY FOR TESTING. * * @param name Cache name. * @param <K> Key type. * @param <V> Value type. * @return Internal cache instance. */ /*@java.test.only*/ public <K, V> GridCacheAdapter<K, V> internalCache(@Nullable String name) { return ctx.cache().internalCache(name); }
@Nullable @Override public <K, V> V get(String cacheName, K key) throws GridException { return ctx.cache().<K, V>cache(cacheName).get(key); }
/** * @param ctx Kernal context. * @return Cache context. */ private GridCacheContext<K, V> cacheContext(GridKernalContext ctx) { assert ctx != null; return ctx.cache().<K, V>internalCache(cacheName).context(); }
@Override public <K> boolean containsKey(String cacheName, K key) { return ctx.cache().cache(cacheName).containsKey(key); }
/** {@inheritDoc} */ @Override public <K, V> GridCache<K, V> cachex(@Nullable String name) { guard(); try { return ctx.cache().cache(name); } finally { unguard(); } }
/** * @param cacheName Cache name. * @return If replicated cache with given name is locally available. */ private boolean replicatedCacheAvailable(String cacheName) { GridCacheAdapter<Object,Object> cache = ctx.cache().internalCache(cacheName); return cache != null && cache.configuration().getCacheMode() == GridCacheMode.REPLICATED; }
@Nullable @Override public <K, V> V putIfAbsent(String cacheName, K key, V val, long ttl) throws GridException { GridCacheEntry<K, V> e = ctx.cache().<K, V>cache(cacheName).entry(key); assert e != null; e.timeToLive(ttl); return e.setIfAbsent(val); }
/** {@inheritDoc} */ @Override public <K, V> GridCache<K, V> cache(@Nullable String name) { guard(); try { if (!dbUsageRegistered) { GridLicenseUseRegistry.onUsage(DATA_GRID, getClass()); dbUsageRegistered = true; } return ctx.cache().publicCache(name); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public <K extends GridCacheUtilityKey, V> GridCacheProjectionEx<K, V> utilityCache(Class<K> keyCls, Class<V> valCls) { guard(); try { return ctx.cache().utilityCache(keyCls, valCls); } finally { unguard(); } }
/** * @param cacheName Cache name. * @return If replicated cache with given name is locally available. */ private boolean replicatedCacheAvailable(String cacheName) { GridCacheAdapter<Object,Object> cache = ctx.cache().internalCache(cacheName); return cache != null && cache.configuration().getCacheMode() == GridCacheMode.REPLICATED; }
@Nullable @Override public <K, V> V put(String cacheName, K key, V val, long ttl) throws GridException { GridCacheEntry<K, V> e = ctx.cache().<K, V>cache(cacheName).entry(key); assert e != null; e.timeToLive(ttl); return e.set(val); }
/** {@inheritDoc} */ @Override public <K, V> GridCache<K, V> cachex() { guard(); try { return ctx.cache().cache(); } finally { unguard(); } }
@Override public int partition(String cacheName, Object key) { return ctx.cache().cache(cacheName).affinity().partition(key); }
@Nullable @Override public GridBiPredicate<K, V> forSpace(final String spaceName) { final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(spaceName); if (cache.context().isReplicated() || cache.configuration().getBackups() == 0) return null; return new GridBiPredicate<K, V>() { @Override public boolean apply(K k, V v) { return cache.context().affinity().primary(ctx.discovery().localNode(), k, -1); } }; } };
/** {@inheritDoc} */ @Override public Collection<GridCache<?, ?>> cachesx(GridPredicate<? super GridCache<?, ?>>[] p) { guard(); try { return F.retain(ctx.cache().caches(), true, p); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public Void call() throws GridException { GridCacheAdapter cache = ((GridKernal)grid).context().cache().internalCache(cacheName); assert cache != null; cache.context().dataStructures().removeSetData(setId, topVer); return null; }
/** {@inheritDoc} */ @Override public Void call() throws GridException { GridCacheAdapter cache = ((GridKernal)grid).context().cache().internalCache(cacheName); assert cache != null; cache.context().dataStructures().blockSet(setId); return null; }
@SuppressWarnings("unchecked") @Nullable @Override public <V> V readValueFromOffheapAndSwap(@Nullable String spaceName, Object key, @Nullable ClassLoader ldr) throws GridException { GridCache<Object, V> cache = ctx.cache().cache(spaceName); GridCacheContext cctx = ((GridCacheProxyImpl)cache).context(); if (cctx.isNear()) cctx = cctx.near().dht().context(); GridCacheSwapEntry e = cctx.swap().read(key); return e != null ? (V)e.value() : null; }
/** * @param ctx Kernal context. */ public GridTaskProcessor(GridKernalContext ctx) { super(ctx); marsh = ctx.config().getMarshaller(); discoLsnr = new TaskDiscoveryListener(); tasksMetaCache = ctx.security().enabled() ? ctx.cache().<GridTaskNameHashKey, String>utilityCache() : null; }
/** {@inheritDoc} */ @Override protected void start0() throws GridException { cfg = ggfsCtx.configuration(); metaCache = ggfsCtx.kernalContext().cache().cache(cfg.getMetaCacheName()); if (metaCache.configuration().getAtomicityMode() != TRANSACTIONAL) throw new GridException("Meta cache should be transactional: " + cfg.getMetaCacheName()); evts = ggfsCtx.kernalContext().event(); sampling = new GridGgfsSamplingKey(cfg.getName()); assert metaCache != null; id2InfoPrj = (GridCacheProjectionEx<GridUuid, GridGgfsFileInfo>)metaCache.<GridUuid, GridGgfsFileInfo>cache(); log = ggfsCtx.kernalContext().log(GridGgfsMetaManager.class); }