use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class GridCacheDhtPreloadSelfTest method startGrids.
/**
* @param cnt Number of grids.
* @param startIdx Start node index.
* @param list List of started grids.
* @throws Exception If failed.
*/
private void startGrids(int cnt, int startIdx, Collection<Ignite> list) throws Exception {
for (int i = 0; i < cnt; i++) {
final Ignite g = startGrid(startIdx++);
if (DEBUG)
g.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
info("\n>>> Preload event [igniteInstanceName=" + g.name() + ", evt=" + evt + ']');
return true;
}
}, EVTS_CACHE_REBALANCE);
list.add(g);
}
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class ConfigVariationsTestSuiteBuilderTest method testIgniteConfigFilter.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("serial")
public void testIgniteConfigFilter() throws Exception {
TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class).build();
final AtomicInteger cnt = new AtomicInteger();
TestSuite filteredSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class).withIgniteConfigFilters(new IgnitePredicate<IgniteConfiguration>() {
@Override
public boolean apply(IgniteConfiguration configuration) {
return cnt.getAndIncrement() % 2 == 0;
}
}).build();
assertEquals(dfltSuite.countTestCases() / 2, filteredSuite.countTestCases());
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class ConfigVariationsTestSuiteBuilderTest method testCacheConfigFilter.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("serial")
public void testCacheConfigFilter() throws Exception {
TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class).withBasicCacheParams().build();
final AtomicInteger cnt = new AtomicInteger();
TestSuite filteredSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class).withBasicCacheParams().withCacheConfigFilters(new IgnitePredicate<CacheConfiguration>() {
@Override
public boolean apply(CacheConfiguration configuration) {
return cnt.getAndIncrement() % 2 == 0;
}
}).build();
assertEquals(dfltSuite.countTestCases() / 2, filteredSuite.countTestCases());
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class CacheEventsExample 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, InterruptedException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Cache events example started.");
// Auto-close cache at the end of the example.
try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) {
// This optional local callback is called for each event notification
// that passed remote predicate listener.
IgniteBiPredicate<UUID, CacheEvent> locLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {
@Override
public boolean apply(UUID uuid, CacheEvent evt) {
System.out.println("Received event [evt=" + evt.name() + ", key=" + evt.key() + ", oldVal=" + evt.oldValue() + ", newVal=" + evt.newValue());
// Continue listening.
return true;
}
};
// Remote listener which only accepts events for keys that are
// greater or equal than 10 and if event node is primary for this key.
IgnitePredicate<CacheEvent> rmtLsnr = new IgnitePredicate<CacheEvent>() {
@Override
public boolean apply(CacheEvent evt) {
System.out.println("Cache event [name=" + evt.name() + ", key=" + evt.key() + ']');
int key = evt.key();
return key >= 10 && ignite.affinity(CACHE_NAME).isPrimary(ignite.cluster().localNode(), key);
}
};
// Subscribe to specified cache events on all nodes that have cache running.
// Cache events are explicitly enabled in examples/config/example-ignite.xml file.
ignite.events(ignite.cluster().forCacheNodes(CACHE_NAME)).remoteListen(locLsnr, rmtLsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);
// Generate cache events.
for (int i = 0; i < 20; i++) cache.put(i, Integer.toString(i));
// Wait for a while while callback is notified about remaining puts.
Thread.sleep(2000);
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class ClusterGroupExample 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-ignite.xml")) {
if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
return;
System.out.println();
System.out.println("Compute example started.");
IgniteCluster cluster = ignite.cluster();
// Say hello to all nodes in the cluster, including local node.
sayHello(ignite, cluster);
// Say hello to all remote nodes.
sayHello(ignite, cluster.forRemotes());
// Pick random node out of remote nodes.
ClusterGroup randomNode = cluster.forRemotes().forRandom();
// Say hello to a random node.
sayHello(ignite, randomNode);
// Say hello to all nodes residing on the same host with random node.
sayHello(ignite, cluster.forHost(randomNode.node()));
// Say hello to all nodes that have current CPU load less than 50%.
sayHello(ignite, cluster.forPredicate(new IgnitePredicate<ClusterNode>() {
@Override
public boolean apply(ClusterNode n) {
return n.metrics().getCurrentCpuLoad() < 0.5;
}
}));
}
}
Aggregations