本文整理了Java中org.apache.ignite.Ignite.cache()
方法的一些代码示例,展示了Ignite.cache()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.cache()
方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:cache
[英]Gets an instance of IgniteCache API. IgniteCache is a fully-compatible implementation of JCache (JSR 107) specification.
[中]获取IgniteCacheAPI的实例。IgniteCache是JCache(JSR107)规范的完全兼容实现。
代码示例来源:origin: apache/ignite
@Override public Object call() throws Exception {
ignite.cache(CU.UTILITY_CACHE_NAME);
return null;
}
}, IllegalStateException.class, null);
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
super.afterTest();
for(String cacheName : ignite().cacheNames())
ignite().cache(cacheName).destroy();
}
代码示例来源:origin: apache/ignite
/**
* Get cache for node.
*
* @param node Node.
* @return Cache.
*/
private static IgniteCache<Long, Person> cache(Ignite node) {
return node.cache(CACHE_NAME);
}
代码示例来源:origin: apache/ignite
@Override public void onLifecycleEvent(LifecycleEventType evt) {
if (evt == LifecycleEventType.AFTER_NODE_START) {
IgniteCache<Integer, byte[]> c = ignite.cache(DEFAULT_CACHE_NAME);
if (c.putIfAbsent(-1, new byte[1])) {
populate(c, cnt, KBSIZE);
info(">>> POPULATED GRID <<<");
}
}
}
};
代码示例来源:origin: apache/ignite
/**
* @return Cache.
*/
protected IgniteCache cache() {
if (!isBinaryMarshaller())
return ignite(0).cache("S2P");
else
return ignite(0).cache("S2P-bin").withKeepBinary();
}
代码示例来源:origin: apache/ignite
/**
*
*/
@NotNull private IgniteCache insertSomeData(Ignite ignite) {
if (!ignite.active())
ignite.active(true);
IgniteCache<String, Person> cache = ignite.cache("cache");
for (int i=0; i<10; i++)
cache.put(String.valueOf(System.currentTimeMillis()), new Person("Name " + i, i));
return cache;
}
代码示例来源:origin: apache/ignite
@Override public Void call() throws Exception {
Lock lock = ignite1.cache(DEFAULT_CACHE_NAME).lock(key);
log.info("Start lock.");
lock.lock();
log.info("Locked.");
return null;
}
}, "lock-thread2");
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testStoreMap() throws Exception {
IgniteCache<Object, Object> cache1 = ignite(0).cache(CACHE1);
IgniteCache<Object, Object> cache2 = ignite(0).cache(CACHE2);
IgniteCache<Object, Object> cache3 = ignite(0).cache(CACHE3);
checkStoreMap(cache1);
checkStoreMap(cache2);
checkStoreMap(cache3);
}
代码示例来源:origin: apache/ignite
@Override public Void call() throws Exception {
IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = node1.transactions().txStart()) {
Integer key = keys.get(idx.getAndIncrement());
cache.getAndPut(key, "new-" + key);
tx.commit();
}
return null;
}
}, txCnt, "tx");
代码示例来源:origin: apache/ignite
/**
* @param caches Cache names to put data into.
* @param node Ignite node.
*/
private void putPersons(String[] caches, Ignite node) {
for (String cacheName : caches) {
IgniteCache<Object, Object> cache = node.cache(cacheName);
for (int i = 0; i < entriesCount(); i++)
cache.put(i, new Person("" + i, cacheName));
}
}
代码示例来源:origin: apache/ignite
@Override public Void call() throws Exception {
Transaction tx = ignite0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
ignite0.cache(DEFAULT_CACHE_NAME).get(key);
return null;
}
}, "lock-thread1");
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
super.afterTest();
for (Ignite g : G.allGrids())
g.cache(DEFAULT_CACHE_NAME).removeAll();
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void run(int idx) throws Exception {
assertEquals(0, ((IgniteKernal)ignite).<String, Integer>internalCache(DEFAULT_CACHE_NAME).context().tm().idMapSize());
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
ClusterNode node = ((IgniteKernal)ignite).localNode();
for (int k = 0; k < size; k++) {
if (affinity(cache).isPrimaryOrBackup(node, k))
assertEquals("Check failed for node: " + node.id(), k,
cache.localPeek(k, CachePeekMode.ONHEAP, CachePeekMode.OFFHEAP));
}
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public List<Cache.Entry<Integer, GridCacheQueryTestValue>> call() throws Exception {
IgniteCache<Integer, GridCacheQueryTestValue> c = ignite.cache(CACHE_NAME);
String sqlStr = "FROM GridCacheQueryTestValue WHERE fieldname = ?";
SqlQuery<Integer, GridCacheQueryTestValue> sql = new SqlQuery<>(GridCacheQueryTestValue.class, sqlStr);
sql.setArgs("C");
return c.query(sql.setSql(sqlStr)).getAll();
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
MvccFeatureChecker.failIfNotSupported(MvccFeatureChecker.Feature.METRICS);
super.beforeTest();
for (int i = 0; i < gridCount(); i++) {
Ignite g = grid(i);
IgniteCache cache = g.cache(DEFAULT_CACHE_NAME);
cache.enableStatistics(true);
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void run(int idx) throws Exception {
GridCacheContext<String, Integer> ctx = ((IgniteKernal)ignite).<String, Integer>internalCache(cacheName).context();
int size = 0;
for (String key : keys)
if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx()))
size++;
assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(cacheName).localSize(ALL));
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void initCacheAndDbData() throws Exception {
Integer k1 = primaryKey(ignite(0).cache(pCache.getName()));
Integer k2 = primaryKey(ignite(1).cache(pCache.getName()));
Organization org1 = new Organization(k1, "org", "org1");
Organization org2 = new Organization(k2, "org", "org2");
pCache.put(k1, org1);
pCache.put(k2, org2);
insertInDb(org1);
insertInDb(org2);
}
代码示例来源:origin: apache/ignite
@Override public Void call() throws Exception {
try (Transaction tx = ignite1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
log.info("Start tx lock.");
ignite1.cache(DEFAULT_CACHE_NAME).get(key);
log.info("Tx locked key.");
tx.commit();
}
return null;
}
}, "lock-thread2");
代码示例来源:origin: apache/ignite
/**
*
*/
@Test
public void testPrimitives() {
IgniteCache<Integer, Integer> p = ignite(0).cache("I2I").withKeepBinary();
p.query(new SqlFieldsQuery("merge into Integer(_key, _val) values (1, ?), " +
"(?, 4)").setArgs(2, 3));
assertEquals(2, (int)p.get(1));
assertEquals(4, (int)p.get(3));
}
}
代码示例来源:origin: apache/ignite
/**
*
*/
@Test
public void testFieldsCaseSensitivity() {
IgniteCache<Key2, Person> p = ignite(0).cache("K22P").withKeepBinary();
p.query(new SqlFieldsQuery("insert into \"Person2\" (\"Id\", \"id\", \"firstName\", \"IntVal\") " +
"values (1, ?, ?, 5), (2, 3, 'Alex', 6)").setArgs(4, "Sergi"));
assertEquals(createPerson2(4, "Sergi", 5), p.get(new Key2(1)));
assertEquals(createPerson2(3, "Alex", 6), p.get(new Key2(2)));
}
内容来源于网络,如有侵权,请联系作者删除!