@Override public void apply(GridCacheConfiguration c) { cacheCfgs.put(c.getName(), c); } });
@Override public void apply(GridCacheConfiguration c) { cacheCfgs.put(c.getName(), c); } });
/** * Startup info. * * @return Startup info. */ protected final String startInfo() { return "Cache started: " + ctx.config().getName(); }
/** * Stop info. * * @return Stop info. */ protected final String stopInfo() { return "Cache stopped: " + ctx.config().getName(); }
/** {@inheritDoc} */ @Override public String name() { return ctx.config().getName(); }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. * @throws GridException If failed. */ private void prepare(GridCacheConfiguration cfg, @Nullable Object rsrc, boolean near) throws GridException { if (rsrc != null) { ctx.resource().injectGeneric(rsrc); ctx.resource().injectCacheName(rsrc, cfg.getName()); registerMbean(rsrc, cfg.getName(), near); } }
/** {@inheritDoc} */ @Override public void addAttributes(Map<String, Object> attrs) throws GridException { if (ctx.isDaemon() || F.isEmpty(ctx.config().getCacheConfiguration())) return; GridCacheAttributes[] attrVals = new GridCacheAttributes[ctx.config().getCacheConfiguration().length]; Map<String, Boolean> attrPortable = new HashMap<>(); Collection<String> replicationCaches = new ArrayList<>(); Map<String, String> interceptors = new HashMap<>(); int i = 0; for (GridCacheConfiguration cfg : ctx.config().getCacheConfiguration()) { attrVals[i++] = new GridCacheAttributes(cfg); attrPortable.put(CU.mask(cfg.getName()), cfg.isPortableEnabled()); if (cfg.getDrSenderConfiguration() != null) replicationCaches.add(cfg.getName()); if (cfg.getInterceptor() != null) interceptors.put(cfg.getName(), cfg.getInterceptor().getClass().getName()); } attrs.put(ATTR_CACHE, attrVals); attrs.put(ATTR_CACHE_PORTABLE, attrPortable); attrs.put(ATTR_REPLICATION_CACHES, replicationCaches); if (!interceptors.isEmpty()) attrs.put(ATTR_CACHE_INTERCEPTORS, interceptors); }
/** {@inheritDoc} */ @Override public void validateCacheConfiguration(GridCacheConfiguration cfg) throws GridException { GridCacheEvictionPolicy evictPlc = cfg.getEvictionPolicy(); if (evictPlc != null && evictPlc instanceof GridCacheGgfsPerBlockLruEvictionPolicy) { GridCacheEvictionFilter evictFilter = cfg.getEvictionFilter(); if (evictFilter != null && !(evictFilter instanceof GridCacheGgfsEvictionFilter)) throw new GridException("Eviction filter cannot be set explicitly when using " + "GridCacheGgfsPerBlockLruEvictionPolicy:" + cfg.getName()); } }
/** {@inheritDoc} */ @Override public void validateCacheConfiguration(GridCacheConfiguration cfg) throws GridException { GridCacheEvictionPolicy evictPlc = cfg.getEvictionPolicy(); if (evictPlc != null && evictPlc instanceof GridCacheGgfsPerBlockLruEvictionPolicy) { GridCacheEvictionFilter evictFilter = cfg.getEvictionFilter(); if (evictFilter != null && !(evictFilter instanceof GridCacheGgfsEvictionFilter)) throw new GridException("Eviction filter cannot be set explicitly when using " + "GridCacheGgfsPerBlockLruEvictionPolicy:" + cfg.getName()); } }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. */ private void cleanup(GridCacheConfiguration cfg, @Nullable Object rsrc, boolean near) { if (rsrc != null) { unregisterMbean(rsrc, cfg.getName(), near); try { ctx.resource().cleanupGeneric(rsrc); } catch (GridException e) { U.error(log, "Failed to cleanup resource: " + rsrc, e); } } }
/** * Checks that preload-order-dependant caches has SYNC or ASYNC preloading mode. * * @param cfgs Caches. * @return Maximum detected preload order. * @throws GridException If validation failed. */ private int validatePreloadOrder(GridCacheConfiguration[] cfgs) throws GridException { int maxOrder = 0; for (GridCacheConfiguration cfg : cfgs) { int preloadOrder = cfg.getPreloadOrder(); if (preloadOrder > 0) { if (cfg.getCacheMode() == LOCAL) throw new GridException("Preload order set for local cache (fix configuration and restart the " + "node): " + cfg.getName()); if (cfg.getPreloadMode() == GridCachePreloadMode.NONE) throw new GridException("Only caches with SYNC or ASYNC preload mode can be set as preload " + "dependency for other caches [cacheName=" + cfg.getName() + ", preloadMode=" + cfg.getPreloadMode() + ", preloadOrder=" + cfg.getPreloadOrder() + ']'); maxOrder = Math.max(maxOrder, preloadOrder); } else if (preloadOrder < 0) throw new GridException("Preload order cannot be negative for cache (fix configuration and restart " + "the node) [cacheName=" + cfg.getName() + ", preloadOrder=" + preloadOrder + ']'); } return maxOrder; }
/** * @param space Space name. * @param typeId Type ID. * @return Type meta data if it was declared in configuration. */ @Nullable private GridCacheQueryTypeMetadata declaredType(String space, int typeId) { Map<TypeId, GridCacheQueryTypeMetadata> declaredTypesById = this.declaredTypesById; if (declaredTypesById == null) { declaredTypesById = new HashMap<>(); for (GridCacheConfiguration ccfg : ctx.config().getCacheConfiguration()){ GridCacheQueryConfiguration qryCfg = ccfg.getQueryConfiguration(); if (qryCfg != null) { for (GridCacheQueryTypeMetadata meta : qryCfg.getTypeMetadata()) declaredTypesById.put(new TypeId(ccfg.getName(), ctx.portable().typeId(meta.getType())), meta); } } this.declaredTypesById = declaredTypesById; } return declaredTypesById.get(new TypeId(space, typeId)); }
/** * */ private void ackCacheConfiguration() { GridCacheConfiguration[] cacheCfgs = cfg.getCacheConfiguration(); if (cacheCfgs == null || cacheCfgs.length == 0) U.warn(log, "Cache is not configured - in-memory data grid is off."); else { SB sb = new SB(); for (GridCacheConfiguration c : cacheCfgs) { String name = c.getName(); if (name == null) name = "<default>"; sb.a("'").a(name).a("', "); } String names = sb.toString(); U.log(log, "Configured caches [" + names.substring(0, names.length() - 2) + ']'); } }
if (F.eq(dataCacheName, cacheCfg.getName())) { GridCacheEvictionPolicy evictPlc = cacheCfg.getEvictionPolicy();
/** * @throws GridException Thrown in case of any errors. */ @Override public void start() throws GridException { if (ctx.config().isDaemon()) return; if (!enabled()) U.warn(log, "Indexing is disabled (to enable please configure GridH2IndexingSpi)."); GridIndexingMarshaller m = new IdxMarshaller(); for (GridIndexingSpi spi : getSpis()) { spi.registerMarshaller(m); for (GridCacheConfiguration cacheCfg : ctx.config().getCacheConfiguration()) spi.registerSpace(cacheCfg.getName()); } execSvc = ctx.config().getExecutorService(); startSpi(); for (GridCacheConfiguration ccfg : ctx.config().getCacheConfiguration()){ GridCacheQueryConfiguration qryCfg = ccfg.getQueryConfiguration(); if (qryCfg != null) { for (GridCacheQueryTypeMetadata meta : qryCfg.getTypeMetadata()) declaredTypesByName.put(new TypeName(ccfg.getName(), meta.getType()), meta); if (qryCfg.getTypeResolver() != null) typeResolvers.put(ccfg.getName(), qryCfg.getTypeResolver()); } } if (log.isDebugEnabled()) log.debug(startInfo()); }
if (cctx.discovery().hasNearCache(cctx.config().getName(), topologyVersion())) { Collection<UUID> backupIds = dhtMap.keySet();
if (CU.isSystemCache(ccfg.getName())) continue;
/** * Checks that local and remove configurations have the same value of given attribute. * * @param log Logger used to log warning message (used only if fail flag is not set). * @param locCfg Local configuration. * @param rmtCfg Remote configuration. * @param rmt Remote node. * @param attr Attribute name. * @param fail If true throws GridException in case of attribute values mismatch, otherwise logs warning. * @throws GridException If attribute values are different and fail flag is true. */ public static void checkAttributeMismatch(GridLogger log, GridCacheConfiguration locCfg, GridCacheConfiguration rmtCfg, GridNode rmt, T2<String, String> attr, boolean fail) throws GridException { assert rmt != null; assert attr != null; assert attr.get1() != null; assert attr.get2() != null; Object locVal = U.property(locCfg, attr.get1()); Object rmtVal = U.property(rmtCfg, attr.get1()); checkAttributeMismatch(log, rmtCfg.getName(), rmt, attr.get1(), attr.get2(), locVal, rmtVal, fail); }
/** * Creates a wrapped cache store if write-behind cache is configured. * * @param gridName Grid name. * @param cfg Cache configuration. * @param near Whether or not store retrieved for near cache. * @return Instance if {@link GridCacheWriteBehindStore} if write-behind store is configured, * or user-defined cache store. */ @SuppressWarnings({"unchecked"}) private GridCacheStore cacheStore(String gridName, GridCacheConfiguration cfg, boolean near) { if (cfg.getStore() == null || !cfg.isWriteBehindEnabled()) return cfg.getStore(); // Write-behind store is used in DHT cache only. if (!near) { GridCacheWriteBehindStore store = new GridCacheWriteBehindStore(gridName, cfg.getName(), log, cfg.getStore()); store.setFlushSize(cfg.getWriteBehindFlushSize()); store.setFlushThreadCount(cfg.getWriteBehindFlushThreadCount()); store.setFlushFrequency(cfg.getWriteBehindFlushFrequency()); store.setBatchSize(cfg.getWriteBehindBatchSize()); return store; } else return cfg.getStore(); }
VisorCacheConfig cfg = new VisorCacheConfig(); cfg.name(ccfg.getName()); cfg.mode(ccfg.getCacheMode()); cfg.distributionMode(ccfg.getDistributionMode());