本文整理了Java中org.apache.ignite.Ignite.createNearCache()
方法的一些代码示例,展示了Ignite.createNearCache()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.createNearCache()
方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:createNearCache
[英]Starts a near cache on local node if cache was previously started with one of the #createCache(CacheConfiguration) or #createCache(CacheConfiguration,NearCacheConfiguration)methods.
[中]如果缓存以前是使用#createCache(CacheConfiguration)或#createCache(CacheConfiguration,NearCacheConfiguration)方法之一启动的,则在本地节点上启动近缓存。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public <K, V> IgniteCache<K, V> createNearCache(String cacheName, NearCacheConfiguration<K, V> nearCfg) {
checkIgnite();
return g.createNearCache(cacheName, nearCfg);
}
代码示例来源:origin: apache/ignite
@Override public Object call() throws Exception {
ignite1.createNearCache(cacheName, new NearCacheConfiguration<>());
return null;
}
}, CacheException.class, null);
代码示例来源:origin: apache/ignite
@Override public Void call() throws Exception {
int idx = getThreadIdx.getAndIncrement() % getNodes.size();
Ignite ignite = getNodes.get(idx);
IgniteCache<Integer, Integer> cache;
if (ignite.configuration().isClientMode())
cache = ignite.createNearCache(cacheName, new NearCacheConfiguration<Integer, Integer>());
else
cache = ignite.cache(cacheName);
Thread.currentThread().setName("get-thread-" + ignite.name());
barrier.await();
while (!updateFut.isDone())
cache.get(key);
return null;
}
}, GET_THREAD, "get-thread");
代码示例来源:origin: apache/ignite
/** @throws Exception If failed. */
private void checkStartupNearNode(int nearNodeIdx, int totalNodeCnt) throws Exception {
try {
cache = true;
for (int i = 0; i < totalNodeCnt; i++) {
cilent = nearNodeIdx == i;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
}
finally {
stopAllGrids();
}
}
}
代码示例来源:origin: apache/ignite
/**
* @param ignite Node.
* @param ccfg Cache configuration.
* @param nearCache If {@code true} creates near cache on one of client nodes.
* @return Created cache.
*/
private <K, V> IgniteCache<K, V> createCache(Ignite ignite, CacheConfiguration<K, V> ccfg,
boolean nearCache) {
IgniteCache<K, V> cache = ignite.createCache(ccfg);
if (nearCache)
ignite(NODES - 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
return cache;
}
代码示例来源:origin: apache/ignite
/**
* Startup routine.
*
* @throws Exception If failed.
*/
private void startUp() throws Exception {
cachesLoc = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
cachesPartitioned = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
cachesColocated = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
cachesReplicated = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
for (int i = 0; i < GRID_CNT; i++) {
Ignite ignite = startGrid(i);
if (i == 1) {
NearCacheConfiguration nearCfg = new NearCacheConfiguration();
ignite.createNearCache(CACHE_PARTITIONED, nearCfg);
}
if (i == 2)
ignite.cache(CACHE_PARTITIONED);
cachesLoc[i] = ignite.cache(CACHE_LOCAL);
cachesPartitioned[i] = ignite.cache(CACHE_PARTITIONED);
cachesColocated[i] = ignite.cache(CACHE_COLOCATED);
cachesReplicated[i] = ignite.cache(CACHE_REPLICATED);
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
startGridsMultiThreaded(GRID_CNT - 2);
client = true;
Ignite grid = startGrid(GRID_CNT - 2);
grid.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
grid = startGrid(GRID_CNT - 1);
grid.cache(DEFAULT_CACHE_NAME);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
startGridsMultiThreaded(GRID_CNT - 2);
client = true;
Ignite grid = startGrid(GRID_CNT - 2);
grid.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
grid = startGrid(GRID_CNT - 1);
grid.cache(DEFAULT_CACHE_NAME);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
System.setProperty(IgniteSystemProperties.IGNITE_ENABLE_FORCIBLE_NODE_KILL, "true");
super.beforeTestsStarted();
startGridsMultiThreaded(SRVS);
client.set(true);
Ignite client1 = startGrid(SRVS);
assertTrue(client1.configuration().isClientMode());
client.set(true);
Ignite client2 = startGrid(SRVS + 1);
assertTrue(client2.configuration().isClientMode());
client2.createNearCache(TX_CACHE1,
new NearCacheConfiguration<>().setNearEvictionPolicy(new GridCacheAlwaysEvictionPolicy<>()));
client2.createNearCache(TX_CACHE2,
new NearCacheConfiguration<>().setNearEvictionPolicy(new GridCacheAlwaysEvictionPolicy<>()));
client2.createNearCache(ATOMIC_CACHE,
new NearCacheConfiguration<>().setNearEvictionPolicy(new GridCacheAlwaysEvictionPolicy<>()));
}
代码示例来源:origin: apache/ignite
/**
* @param ignite Node.
* @param ccfg Cache configuration.
* @return Created cache.
*/
private <K, V> IgniteCache<K, V> createCache(Ignite ignite, CacheConfiguration<K, V> ccfg) {
IgniteCache<K, V> cache = ignite.createCache(ccfg);
if (!MvccFeatureChecker.forcedMvcc() || MvccFeatureChecker.isSupported(Feature.NEAR_CACHE))
ignite(NODES - 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
return cache;
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If f nodeailed.
* @return Started client.
*/
private Ignite startClient() throws Exception {
Ignite client = startGrid("client");
assertTrue(client.configuration().isClientMode());
if (nearCacheEnabled())
client.createNearCache(CACHE_NAME, new NearCacheConfiguration<>());
else
assertNotNull(client.cache(CACHE_NAME));
return client;
}
代码示例来源:origin: apache/ignite
/**
* @return Started client.
* @throws Exception If f nodeailed.
*/
private Ignite startClient() throws Exception {
Ignite client = startGrid("client");
assertTrue(client.configuration().isClientMode());
if (nearCacheEnabled())
client.createNearCache(CACHE_NAME, new NearCacheConfiguration<>());
else
assertNotNull(client.cache(CACHE_NAME));
return client;
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();
Ignite client = ignite(gridCount() - 1);
assertTrue(client.cluster().localNode().isClient());
for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
grid(0).createCache(ccfg);
client.createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
}
awaitPartitionMapExchange();
}
代码示例来源:origin: apache/ignite
/** @throws Exception If failed. */
@Test
public void testKeyMapping() throws Exception {
try {
cache = true;
for (int i = 0; i < 4; i++) {
cilent = i == 0;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
for (int i = 0; i < 100; i++)
assertFalse("For key: " + i, grid(0).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(0).localNode(), i));
}
finally {
stopAllGrids();
}
}
代码示例来源:origin: apache/ignite
/** @throws Exception If failed. */
@Test
public void testKeyMappingOnComputeNode() throws Exception {
try {
cache = true;
for (int i = 0; i < 4; i++) {
cilent = i == 0;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
cache = false;
cilent = true;
Ignite compute = startGrid(4);
for (int i = 0; i < 100; i++) {
ClusterNode node = compute.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i);
assertFalse("For key: " + i, node.id().equals(compute.cluster().localNode().id()));
assertFalse("For key: " + i, node.id().equals(grid(0).localNode().id()));
}
}
finally {
stopAllGrids();
}
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testNearOnlyPutMultithreaded() throws Exception {
final Ignite ignite1 = ignite(1);
assertTrue(ignite1.configuration().isClientMode());
ignite1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
final Integer key = 1;
final AtomicInteger idx = new AtomicInteger();
IgniteCache<Integer, Integer> cache0 = ignite(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Integer> cache1 = ignite1.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
int val = idx.getAndIncrement();
IgniteCache<Integer, Integer> cache = ignite1.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++)
cache.put(key, val);
return null;
}
}, 5, "put-thread").get();
assertEquals(cache0.localPeek(key), cache1.localPeek(key));
}
}
代码示例来源:origin: apache/ignite
/**
* @param ccfg Cache configuration.
*/
private void enumOperations(CacheConfiguration<Object, Object> ccfg) {
ignite(0).createCache(ccfg);
try {
int key = 0;
int nodes;
if (!singleNode()) {
nodes = 6;
ignite(nodes - 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
}
else
nodes = 1;
for (int i = 0; i < nodes; i++) {
IgniteCache<Object, Object> cache = ignite(i).cache(ccfg.getName());
for (int j = 0; j < 100; j++)
enumOperations(cache, key++);
}
}
finally {
ignite(0).destroyCache(ccfg.getName());
}
}
代码示例来源:origin: apache/ignite
client.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
代码示例来源:origin: apache/ignite
/**
* @param c Closure.
* @throws Exception If failed.
*/
private void executeTestForAllCaches(TestClosure c) throws Exception {
for (CacheConfiguration ccfg : cacheConfigurations()) {
ignite(0).createCache(ccfg);
log.info("Run test for cache [cache=" + ccfg.getCacheMode() +
", backups=" + ccfg.getBackups() +
", near=" + (ccfg.getNearConfiguration() != null) + "]");
ignite(serversNumber() + 1).createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
try {
for (int i = 0; i < serversNumber() + 2; i++) {
log.info("Run test for node [node=" + i + ", client=" + ignite(i).configuration().isClientMode() + ']');
c.apply(ignite(i), ccfg.getName());
}
}
finally {
ignite(0).destroyCache(ccfg.getName());
}
}
}
代码示例来源:origin: apache/ignite
/**
* @param cacheMode Cache mode.
* @param syncMode Write sync mode.
* @param near Near.
* @return Created cache.
*/
@SuppressWarnings("unchecked")
private IgniteCache createCache(CacheMode cacheMode, CacheWriteSynchronizationMode syncMode, boolean near)
throws IgniteInterruptedCheckedException, InterruptedException {
awaitPartitionMapExchange();
int minorTopVer = grid(0).context().discovery().topologyVersionEx().minorTopologyVersion();
CacheConfiguration ccfg = defaultCacheConfiguration();
ccfg.setName(CACHE_NAME);
ccfg.setCacheMode(cacheMode);
ccfg.setBackups(1);
ccfg.setNearConfiguration(near ? new NearCacheConfiguration() : null);
ccfg.setWriteSynchronizationMode(syncMode);
IgniteCache cache = ignite(0).createCache(ccfg);
if (near) {
for (int i = 0; i < NODES_CNT; i++) {
Ignite client = ignite(i + NODES_CNT);
assertTrue(client.configuration().isClientMode());
client.createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
}
}
waitForLateAffinityAssignment(minorTopVer);
return cache;
}
内容来源于网络,如有侵权,请联系作者删除!