use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class GridCacheProcessor method onKernalStart.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException {
ClusterNode locNode = ctx.discovery().localNode();
try {
boolean checkConsistency = !ctx.config().isDaemon() && !getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK);
if (checkConsistency)
checkConsistency();
cachesInfo.onKernalStart(checkConsistency);
boolean currStatus = ctx.state().active();
// which were received on join.
if (!ctx.isDaemon() && currStatus && !activeOnStart) {
List<CacheConfiguration> tmpCacheCfg = new ArrayList<>();
for (CacheConfiguration conf : ctx.config().getCacheConfiguration()) {
assert conf.getName() != null;
for (DynamicCacheDescriptor desc : cacheDescriptors()) {
CacheConfiguration c = desc.cacheConfiguration();
IgnitePredicate filter = c.getNodeFilter();
if (c.getName().equals(conf.getName()) && ((desc.receivedOnDiscovery() && CU.affinityNode(locNode, filter)) || CU.isSystemCache(c.getName()))) {
tmpCacheCfg.add(c);
break;
}
}
}
if (!tmpCacheCfg.isEmpty()) {
CacheConfiguration[] newCacheCfg = new CacheConfiguration[tmpCacheCfg.size()];
tmpCacheCfg.toArray(newCacheCfg);
ctx.config().setCacheConfiguration(newCacheCfg);
}
activeOnStart = currStatus;
}
if (activeOnStart && !ctx.clientNode() && !ctx.isDaemon())
sharedCtx.database().lock();
// Must start database before start first cache.
sharedCtx.database().onKernalStart(false);
ctx.query().onCacheKernalStart();
for (GridCacheSharedManager<?, ?> mgr : sharedCtx.managers()) {
if (sharedCtx.database() != mgr)
mgr.onKernalStart(false);
}
} finally {
cacheStartedLatch.countDown();
}
// Escape if start active on start false
if (!activeOnStart)
return;
if (!ctx.config().isDaemon())
ctx.cacheObjects().onUtilityCacheStarted();
ctx.service().onUtilityCacheStarted();
final AffinityTopologyVersion startTopVer = new AffinityTopologyVersion(ctx.discovery().localJoinEvent().topologyVersion(), 0);
final List<IgniteInternalFuture> syncFuts = new ArrayList<>(caches.size());
sharedCtx.forAllCaches(new CIX1<GridCacheContext>() {
@Override
public void applyx(GridCacheContext cctx) throws IgniteCheckedException {
CacheConfiguration cfg = cctx.config();
if (cctx.affinityNode() && cfg.getRebalanceMode() == SYNC && startTopVer.equals(cctx.startTopologyVersion())) {
CacheMode cacheMode = cfg.getCacheMode();
if (cacheMode == REPLICATED || (cacheMode == PARTITIONED && cfg.getRebalanceDelay() >= 0))
// Need to wait outside to avoid a deadlock
syncFuts.add(cctx.preloader().syncFuture());
}
}
});
for (int i = 0, size = syncFuts.size(); i < size; i++) syncFuts.get(i).get();
assert ctx.config().isDaemon() || caches.containsKey(CU.UTILITY_CACHE_NAME) : "Utility cache should be started";
if (!ctx.clientNode() && !ctx.isDaemon())
addRemovedItemsCleanupTask(Long.getLong(IGNITE_CACHE_REMOVED_ENTRIES_TTL, 10_000));
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class EventsExample method localListen.
/**
* Listen to events that happen only on local node.
*
* @throws IgniteException If failed.
*/
private static void localListen() throws IgniteException {
System.out.println();
System.out.println(">>> Local event listener example.");
Ignite ignite = Ignition.ignite();
IgnitePredicate<TaskEvent> lsnr = new IgnitePredicate<TaskEvent>() {
@Override
public boolean apply(TaskEvent evt) {
System.out.println("Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName() + ']');
// Return true to continue listening.
return true;
}
};
// Register event listener for all local task execution events.
ignite.events().localListen(lsnr, EVTS_TASK_EXECUTION);
// Generate task events.
ignite.compute().withName("example-event-task").run(new IgniteRunnable() {
@Override
public void run() {
System.out.println("Executing sample job.");
}
});
// Unsubscribe local task event listener.
ignite.events().stopLocalListen(lsnr);
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class GridCacheAdapter method sizeLongAsync.
/** {@inheritDoc} */
@Override
public IgniteInternalFuture<Long> sizeLongAsync(final int part, final CachePeekMode[] peekModes) {
assert peekModes != null;
final PeekModes modes = parsePeekModes(peekModes, true);
IgniteClusterEx cluster = ctx.grid().cluster();
final GridCacheAffinityManager aff = ctx.affinity();
final AffinityTopologyVersion topVer = aff.affinityTopologyVersion();
ClusterGroup grp = cluster.forDataNodes(name());
Collection<ClusterNode> nodes = grp.forPredicate(new IgnitePredicate<ClusterNode>() {
/** {@inheritDoc} */
@Override
public boolean apply(ClusterNode clusterNode) {
return ((modes.primary && aff.primaryByPartition(clusterNode, part, topVer)) || (modes.backup && aff.backupByPartition(clusterNode, part, topVer)));
}
}).nodes();
if (nodes.isEmpty())
return new GridFinishedFuture<>(0L);
ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
return ctx.kernalContext().task().execute(new PartitionSizeLongTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes, part), null);
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgniteUtilsSelfTest method testResolveLocalAddresses.
/**
* @throws Exception If failed.
*/
public void testResolveLocalAddresses() throws Exception {
InetAddress inetAddress = InetAddress.getByName("0.0.0.0");
IgniteBiTuple<Collection<String>, Collection<String>> addrs = U.resolveLocalAddresses(inetAddress);
Collection<String> hostNames = addrs.get2();
assertFalse(hostNames.contains(null));
assertFalse(hostNames.contains(""));
assertFalse(hostNames.contains("127.0.0.1"));
assertFalse(F.exist(hostNames, new IgnitePredicate<String>() {
@Override
public boolean apply(String hostName) {
return hostName.contains("localhost") || hostName.contains("0:0:0:0:0:0:0:1");
}
}));
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgniteSqlRoutingTest method runQueryEnsureBroadcast.
private List<List<?>> runQueryEnsureBroadcast(IgniteCache<?, ?> cache, SqlFieldsQuery qry) throws Exception {
final CountDownLatch execLatch = new CountDownLatch(NODE_COUNT);
final IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertNotNull(qe.clause());
execLatch.countDown();
return true;
}
};
for (int i = 0; i < NODE_COUNT; i++) grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED);
List<List<?>> result = cache.query(qry).getAll();
assertTrue(execLatch.await(5000, MILLISECONDS));
for (int i = 0; i < NODE_COUNT; i++) grid(i).events().stopLocalListen(pred);
return result;
}
Aggregations