sysCaches.add(CU.UTILITY_CACHE_NAME);
GridCacheConfiguration[] cfgs = ctx.config().getCacheConfiguration();
for (int i = 0; i < cfgs.length; i++) {
GridCacheConfiguration cfg = new GridCacheConfiguration(cfgs[i]);
// Initialize defaults.
initialize(cfg);
// Skip suggestions for system caches.
if (!sysCaches.contains(cfg.getName()))
suggestOptimizations(cfg);
validate(ctx.config(), cfg);
GridCacheJtaManagerAdapter jta = JTA.create(cfg.getTransactionManagerLookupClassName() == null);
jta.createTmLookup(cfg);
prepare(cfg, jta.tmLookup());
U.startLifecycleAware(lifecycleAwares(cfg, jta.tmLookup()));
cfgs[i] = cfg; // Replace original configuration value.
GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
GridCacheTxManager tm = new GridCacheTxManager();
GridCacheAffinityManager affMgr = new GridCacheAffinityManager();
GridCacheVersionManager verMgr = new GridCacheVersionManager();
GridCacheEventManager evtMgr = new GridCacheEventManager();
GridCacheSwapManager swapMgr = new GridCacheSwapManager(cfg.getCacheMode() == LOCAL || !isNearEnabled(cfg));
GridCacheDgcManager dgcMgr = new GridCacheDgcManager();
GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
GridCacheEvictionManager evictMgr = new GridCacheEvictionManager();
GridCacheQueryManager qryMgr = queryManager(cfg);
GridCacheContinuousQueryManager contQryMgr = new GridCacheContinuousQueryManager();
GridCacheIoManager ioMgr = new GridCacheIoManager();
GridCacheDataStructuresManager dataStructuresMgr = new GridCacheDataStructuresManager();
GridCacheTtlManager ttlMgr = new GridCacheTtlManager();
GridCacheDrManager drMgr = createComponent(GridCacheDrManager.class);
GridCacheStore nearStore = cacheStore(ctx.gridName(), cfg, isNearEnabled(cfg));
GridCacheStoreManager storeMgr = new GridCacheStoreManager(nearStore);
GridCacheContext<?, ?> cacheCtx = new GridCacheContext(
ctx,
cfg,
/*
* Managers in starting order!
* ===========================
*/
mvccMgr,
verMgr,
evtMgr,
swapMgr,
storeMgr,
depMgr,
evictMgr,
ioMgr,
qryMgr,
contQryMgr,
dgcMgr,
affMgr,
tm,
dataStructuresMgr,
ttlMgr,
drMgr,
jta);
GridCacheAdapter cache = null;
switch (cfg.getCacheMode()) {
case LOCAL: {
switch (cfg.getAtomicityMode()) {
case TRANSACTIONAL: {
cache = new GridLocalCache(cacheCtx);
break;
}
case ATOMIC: {
cache = new GridLocalAtomicCache(cacheCtx);
break;
}
default: {
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
break;
}
case PARTITIONED:
case REPLICATED: {
if (isNearEnabled(cfg)) {
switch (cfg.getAtomicityMode()) {
case TRANSACTIONAL: {
cache = new GridNearTransactionalCache(cacheCtx);
break;
}
case ATOMIC: {
cache = new GridNearAtomicCache(cacheCtx);
break;
}
default: {
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
}
else {
switch (cfg.getAtomicityMode()) {
case TRANSACTIONAL: {
cache = isAffinityNode(cfg) ? new GridDhtColocatedCache(cacheCtx) :
new GridDhtColocatedCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
break;
}
case ATOMIC: {
cache = isAffinityNode(cfg) ? new GridDhtAtomicCache(cacheCtx) :
new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
break;
}
default: {
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
}
break;
}
default: {
assert false : "Invalid cache mode: " + cfg.getCacheMode();
}
}
cacheCtx.cache(cache);
if (caches.containsKey(cfg.getName())) {
String cacheName = cfg.getName();
if (cacheName != null)
throw new GridException("Duplicate cache name found (check configuration and " +
"assign unique name to each cache): " + cacheName);
else
throw new GridException("Default cache has already been configured (check configuration and " +
"assign unique name to each cache).");
}
caches.put(cfg.getName(), cache);
if (sysCaches.contains(cfg.getName()))
stopSeq.addLast(cache);
else
stopSeq.addFirst(cache);
// Start managers.
for (GridCacheManager mgr : F.view(cacheCtx.managers(), F.notContains(dhtExcludes(cacheCtx))))
mgr.start(cacheCtx);
/*
* Start DHT cache.
* ================
*/
if (cfg.getCacheMode() != LOCAL && isNearEnabled(cfg)) {
/*
* Specifically don't create the following managers
* here and reuse the one from Near cache:
* 1. GridCacheVersionManager
* 2. GridCacheIoManager
* 3. GridCacheDeploymentManager
* 4. GridCacheQueryManager (note, that we start it for DHT cache though).
* 5. GridCacheContinuousQueryManager (note, that we start it for DHT cache though).
* 6. GridCacheDgcManager
* 7. GridCacheTtlManager.
* ===============================================
*/
mvccMgr = new GridCacheMvccManager();
tm = new GridCacheTxManager();
swapMgr = new GridCacheSwapManager(true);
evictMgr = new GridCacheEvictionManager();
evtMgr = new GridCacheEventManager();
drMgr = createComponent(GridCacheDrManager.class);
GridCacheStore dhtStore = cacheStore(ctx.gridName(), cfg, false);
storeMgr = new GridCacheStoreManager(dhtStore);
cacheCtx = new GridCacheContext(
ctx,
cfg,
/*
* Managers in starting order!
* ===========================
*/
mvccMgr,
verMgr,
evtMgr,
swapMgr,
storeMgr,
depMgr,
evictMgr,
ioMgr,
qryMgr,
contQryMgr,
dgcMgr,
affMgr,
tm,
dataStructuresMgr,
ttlMgr,
drMgr,
jta);
GridDhtCacheAdapter dht = null;
switch (cfg.getAtomicityMode()) {
case TRANSACTIONAL: {
assert cache instanceof GridNearTransactionalCache;
GridNearTransactionalCache near = (GridNearTransactionalCache)cache;
GridDhtCache dhtCache = !isAffinityNode(cfg) ?
new GridDhtCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx)) :
new GridDhtCache(cacheCtx);
dhtCache.near(near);
near.dht(dhtCache);
dht = dhtCache;
break;
}
case ATOMIC: {
assert cache instanceof GridNearAtomicCache;
GridNearAtomicCache near = (GridNearAtomicCache)cache;
GridDhtAtomicCache dhtCache = isAffinityNode(cfg) ? new GridDhtAtomicCache(cacheCtx) :
new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
dhtCache.near(near);
near.dht(dhtCache);
dht = dhtCache;
break;
}
default: {
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
cacheCtx.cache(dht);
// Start managers.
for (GridCacheManager mgr : dhtManagers(cacheCtx))
mgr.start(cacheCtx);
dht.start();
if (log.isDebugEnabled())
log.debug("Started DHT cache: " + dht.name());
}
cache.start();
if (log.isInfoEnabled())
log.info("Started cache [name=" + cfg.getName() + ", mode=" + cfg.getCacheMode() + ']');
}
for (Map.Entry<String, GridCacheAdapter<?, ?>> e : caches.entrySet()) {
GridCacheAdapter cache = e.getValue();