use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.
the class PlatformProcessorImpl method createCacheFromConfig.
/** {@inheritDoc} */
@Override
public PlatformTargetProxy createCacheFromConfig(long memPtr) throws IgniteCheckedException {
BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
IgniteCacheProxy cache = reader.readBoolean() ? (IgniteCacheProxy) ctx.grid().createCache(cfg, PlatformConfigurationUtils.readNearConfiguration(reader)) : (IgniteCacheProxy) ctx.grid().createCache(cfg);
return createPlatformCache(cache);
}
use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.
the class IgniteDrDataStreamerCacheUpdater method receive.
/** {@inheritDoc} */
@Override
public void receive(IgniteCache<KeyCacheObject, CacheObject> cache0, Collection<Map.Entry<KeyCacheObject, CacheObject>> col) {
try {
String cacheName = cache0.getConfiguration(CacheConfiguration.class).getName();
GridKernalContext ctx = ((IgniteKernal) cache0.unwrap(Ignite.class)).context();
IgniteLogger log = ctx.log(IgniteDrDataStreamerCacheUpdater.class);
GridCacheAdapter internalCache = ctx.cache().internalCache(cacheName);
CacheOperationContext opCtx = ((IgniteCacheProxy) cache0).operationContext();
IgniteInternalCache cache = opCtx != null ? new GridCacheProxyImpl(internalCache.context(), internalCache, opCtx) : internalCache;
assert !F.isEmpty(col);
if (log.isDebugEnabled())
log.debug("Running DR put job [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
CacheObjectContext cacheObjCtx = cache.context().cacheObjectContext();
for (Map.Entry<KeyCacheObject, CacheObject> entry0 : col) {
GridCacheRawVersionedEntry entry = (GridCacheRawVersionedEntry) entry0;
entry.unmarshal(cacheObjCtx, ctx.config().getMarshaller());
KeyCacheObject key = entry.getKey();
// Ensure that receiver to not receive special-purpose values for TTL and expire time.
assert entry.ttl() != CU.TTL_NOT_CHANGED && entry.ttl() != CU.TTL_ZERO && entry.ttl() >= 0;
assert entry.expireTime() != CU.EXPIRE_TIME_CALCULATE && entry.expireTime() >= 0;
CacheObject cacheVal = entry.getValue();
GridCacheDrInfo val = cacheVal != null ? entry.ttl() != CU.TTL_ETERNAL ? new GridCacheDrExpirationInfo(cacheVal, entry.version(), entry.ttl(), entry.expireTime()) : new GridCacheDrInfo(cacheVal, entry.version()) : null;
if (val == null)
cache.removeAllConflict(Collections.singletonMap(key, entry.version()));
else
cache.putAllConflict(Collections.singletonMap(key, val));
}
if (log.isDebugEnabled())
log.debug("DR put job finished [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
}
use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.
the class GridQueryProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
super.start(activeOnStart);
if (idx != null) {
ctx.resource().injectGeneric(idx);
idx.start(ctx, busyLock);
}
ctx.io().addMessageListener(TOPIC_SCHEMA, ioLsnr);
// Schedule queries detail metrics eviction.
qryDetailMetricsEvictTask = ctx.timeout().schedule(new Runnable() {
@Override
public void run() {
for (IgniteCacheProxy cache : ctx.cache().jcaches()) cache.context().queries().evictDetailMetrics();
}
}, QRY_DETAIL_METRICS_EVICTION_FREQ, QRY_DETAIL_METRICS_EVICTION_FREQ);
}
use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testIterator.
/**
* @throws Exception If failed.
*/
public void testIterator() throws Exception {
IgniteCache<Integer, TestObject> c = jcache(0);
Map<Integer, TestObject> entries = new HashMap<>();
for (int i = 0; i < ENTRY_CNT; i++) {
TestObject val = new TestObject(i);
c.put(i, val);
entries.put(i, val);
}
IgniteCache<Integer, BinaryObject> prj = ((IgniteCacheProxy) c).keepBinary();
Iterator<Cache.Entry<Integer, BinaryObject>> it = prj.iterator();
assertTrue(it.hasNext());
while (it.hasNext()) {
Cache.Entry<Integer, BinaryObject> entry = it.next();
assertTrue(entries.containsKey(entry.getKey()));
TestObject o = entries.get(entry.getKey());
BinaryObject po = entry.getValue();
assertEquals(o.val, (int) po.field("val"));
entries.remove(entry.getKey());
}
assertEquals(0, entries.size());
}
use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.
the class GridDataStreamerImplSelfTest method testAddBinaryDataFromMap.
/**
* Data streamer should correctly load binary entries from HashMap in case of grids with more than one node
* and with GridOptimizedMarshaller that requires serializable.
*
* @throws Exception If failed.
*/
public void testAddBinaryDataFromMap() throws Exception {
try {
binaries = true;
startGrids(2);
awaitPartitionMapExchange();
Ignite g0 = grid(0);
IgniteDataStreamer<Integer, TestObject> dataLdr = g0.dataStreamer(DEFAULT_CACHE_NAME);
Map<Integer, TestObject> map = U.newHashMap(KEYS_COUNT);
for (int i = 0; i < KEYS_COUNT; i++) map.put(i, new TestObject(i));
dataLdr.addData(map);
dataLdr.close(false);
checkDistribution(grid(0));
checkDistribution(grid(1));
// Read random keys. Take values as TestObject.
Random rnd = new Random();
IgniteCache<Integer, TestObject> c = g0.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) {
Integer k = rnd.nextInt(KEYS_COUNT);
TestObject v = c.get(k);
assertEquals(k, v.val());
}
// Read random keys. Take values as BinaryObject.
IgniteCache<Integer, BinaryObject> c2 = ((IgniteCacheProxy) c).keepBinary();
for (int i = 0; i < 100; i++) {
Integer k = rnd.nextInt(KEYS_COUNT);
BinaryObject v = c2.get(k);
assertEquals(k, v.field("val"));
}
} finally {
G.stopAll(true);
}
}
Aggregations