use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class DataRegionsExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("examples/config/example-data-regions.xml")) {
System.out.println();
System.out.println(">>> Data regions example started.");
/*
* Preparing configurations for 2 caches that will be bound to the memory region defined by
* '10MB_Region_Eviction' data region from 'example-data-regions.xml' configuration.
*/
CacheConfiguration<Integer, Integer> firstCacheCfg = new CacheConfiguration<>("firstCache");
firstCacheCfg.setDataRegionName(REGION_40MB_EVICTION);
firstCacheCfg.setCacheMode(CacheMode.PARTITIONED);
firstCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
CacheConfiguration<Integer, Integer> secondCacheCfg = new CacheConfiguration<>("secondCache");
secondCacheCfg.setDataRegionName(REGION_40MB_EVICTION);
secondCacheCfg.setCacheMode(CacheMode.REPLICATED);
secondCacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
IgniteCache<Integer, Integer> firstCache = ignite.createCache(firstCacheCfg);
IgniteCache<Integer, Integer> secondCache = ignite.createCache(secondCacheCfg);
System.out.println(">>> Started two caches bound to '" + REGION_40MB_EVICTION + "' memory region.");
/*
* Preparing a configuration for a cache that will be bound to the memory region defined by
* '5MB_Region_Swapping' data region from 'example-data-regions.xml' configuration.
*/
CacheConfiguration<Integer, Integer> thirdCacheCfg = new CacheConfiguration<>("thirdCache");
thirdCacheCfg.setDataRegionName(REGION_30MB_MEMORY_MAPPED_FILE);
IgniteCache<Integer, Integer> thirdCache = ignite.createCache(thirdCacheCfg);
System.out.println(">>> Started a cache bound to '" + REGION_30MB_MEMORY_MAPPED_FILE + "' memory region.");
/*
* Preparing a configuration for a cache that will be bound to the default memory region defined by
* default 'Default_Region' data region from 'example-data-regions.xml' configuration.
*/
CacheConfiguration<Integer, Integer> fourthCacheCfg = new CacheConfiguration<>("fourthCache");
IgniteCache<Integer, Integer> fourthCache = ignite.createCache(fourthCacheCfg);
System.out.println(">>> Started a cache bound to '" + REGION_DEFAULT + "' memory region.");
System.out.println(">>> Destroying caches...");
firstCache.destroy();
secondCache.destroy();
thirdCache.destroy();
fourthCache.destroy();
}
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class CacheStarSchemaExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Cache star schema example started.");
CacheConfiguration<Integer, FactPurchase> factCacheCfg = new CacheConfiguration<>(FACT_CACHE_NAME);
factCacheCfg.setCacheMode(CacheMode.PARTITIONED);
factCacheCfg.setIndexedTypes(Integer.class, FactPurchase.class);
CacheConfiguration<Integer, DimStore> dimStoreCacheCfg = new CacheConfiguration<>(DIM_STORE_CACHE_NAME);
dimStoreCacheCfg.setCacheMode(CacheMode.REPLICATED);
dimStoreCacheCfg.setIndexedTypes(Integer.class, DimStore.class);
CacheConfiguration<Integer, DimProduct> dimProdCacheCfg = new CacheConfiguration<>(DIM_PROD_CACHE_NAME);
dimProdCacheCfg.setCacheMode(CacheMode.REPLICATED);
dimProdCacheCfg.setIndexedTypes(Integer.class, DimProduct.class);
// Auto-close cache at the end of the example.
try (IgniteCache<Integer, FactPurchase> factCache = ignite.getOrCreateCache(factCacheCfg);
IgniteCache<Integer, DimStore> dimStoreCache = ignite.getOrCreateCache(dimStoreCacheCfg);
IgniteCache<Integer, DimProduct> dimProdCache = ignite.getOrCreateCache(dimProdCacheCfg)) {
populateDimensions(dimStoreCache, dimProdCache);
populateFacts(factCache);
queryStorePurchases();
queryProductPurchases();
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(FACT_CACHE_NAME);
ignite.destroyCache(DIM_STORE_CACHE_NAME);
ignite.destroyCache(DIM_PROD_CACHE_NAME);
}
}
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class GridCacheProcessor method initiateCacheChanges.
/**
* @param reqs Requests.
* @return Collection of futures.
*/
@SuppressWarnings("TypeMayBeWeakened")
private Collection<DynamicCacheStartFuture> initiateCacheChanges(Collection<DynamicCacheChangeRequest> reqs) {
Collection<DynamicCacheStartFuture> res = new ArrayList<>(reqs.size());
Collection<DynamicCacheChangeRequest> sndReqs = new ArrayList<>(reqs.size());
for (DynamicCacheChangeRequest req : reqs) {
DynamicCacheStartFuture fut = new DynamicCacheStartFuture(req.requestId());
try {
if (req.stop()) {
DynamicCacheDescriptor desc = cacheDescriptor(req.cacheName());
if (desc == null)
// No-op.
fut.onDone(false);
}
if (req.start() && req.startCacheConfiguration() != null) {
CacheConfiguration ccfg = req.startCacheConfiguration();
try {
cachesInfo.validateStartCacheConfiguration(ccfg);
} catch (IgniteCheckedException e) {
fut.onDone(e);
}
}
if (fut.isDone())
continue;
DynamicCacheStartFuture old = (DynamicCacheStartFuture) pendingFuts.putIfAbsent(req.requestId(), fut);
assert old == null;
if (fut.isDone())
continue;
sndReqs.add(req);
} catch (Exception e) {
fut.onDone(e);
} finally {
res.add(fut);
}
}
Exception err = null;
if (!sndReqs.isEmpty()) {
try {
ctx.discovery().sendCustomEvent(new DynamicCacheChangeBatch(sndReqs));
err = checkNodeState();
} catch (IgniteCheckedException e) {
err = e;
}
}
if (err != null) {
for (DynamicCacheStartFuture fut : res) fut.onDone(err);
}
return res;
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class GridCacheUtils method hadoopSystemCache.
/**
* Create system cache used by Hadoop component.
*
* @return Hadoop cache configuration.
*/
public static CacheConfiguration hadoopSystemCache() {
CacheConfiguration cache = new CacheConfiguration();
cache.setName(CU.SYS_CACHE_HADOOP_MR);
cache.setCacheMode(REPLICATED);
cache.setAtomicityMode(TRANSACTIONAL);
cache.setWriteSynchronizationMode(FULL_SYNC);
cache.setEvictionPolicyFactory(null);
cache.setEvictionPolicy(null);
cache.setCacheStoreFactory(null);
cache.setNodeFilter(CacheConfiguration.ALL_NODES);
cache.setEagerTtl(true);
cache.setRebalanceMode(SYNC);
return cache;
}
use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.
the class GridCacheAffinityImpl method affinityKey.
/**
* {@inheritDoc}
*/
@Override
public Object affinityKey(K key) {
A.notNull(key, "key");
if (key instanceof CacheObject && !(key instanceof BinaryObject)) {
CacheObjectContext ctx = cctx.cacheObjectContext();
if (ctx == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
key = ((CacheObject) key).value(ctx, false);
}
CacheConfiguration ccfg = cctx.config();
if (ccfg == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
return ccfg.getAffinityMapper().affinityKey(key);
}
Aggregations