use of org.apache.ignite.events.JobEvent in project ignite by apache.
the class AdaptiveLoadBalancingSpi method onContextInitialized0.
/** {@inheritDoc} */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
switch(evt.type()) {
case EVT_TASK_FINISHED:
case EVT_TASK_FAILED:
{
TaskEvent taskEvt = (TaskEvent) evt;
taskTops.remove(taskEvt.taskSessionId());
if (log.isDebugEnabled())
log.debug("Removed task topology from topology cache for session: " + taskEvt.taskSessionId());
break;
}
case EVT_JOB_MAPPED:
{
// We should keep topology and use cache in ComputeTask#map() method to
// avoid O(n*n/2) complexity, after that we can drop caches.
// Here we set mapped property and later cache will be ignored
JobEvent jobEvt = (JobEvent) evt;
IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(jobEvt.taskSessionId());
if (weightedTop != null)
weightedTop.set1(true);
if (log.isDebugEnabled())
log.debug("Job has been mapped. Ignore cache for session: " + jobEvt.taskSessionId());
break;
}
case EVT_NODE_METRICS_UPDATED:
case EVT_NODE_FAILED:
case EVT_NODE_JOINED:
case EVT_NODE_LEFT:
{
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
rwLock.writeLock().lock();
try {
switch(evt.type()) {
case EVT_NODE_JOINED:
{
nodeJobs.put(discoEvt.eventNode().id(), new AtomicInteger(0));
break;
}
case EVT_NODE_LEFT:
case EVT_NODE_FAILED:
{
nodeJobs.remove(discoEvt.eventNode().id());
break;
}
case EVT_NODE_METRICS_UPDATED:
{
// Reset counter.
nodeJobs.put(discoEvt.eventNode().id(), new AtomicInteger(0));
break;
}
}
} finally {
rwLock.writeLock().unlock();
}
}
}
}
}, EVT_NODE_METRICS_UPDATED, EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_TASK_FINISHED, EVT_TASK_FAILED, EVT_JOB_MAPPED);
// Put all known nodes.
rwLock.writeLock().lock();
try {
for (ClusterNode node : getSpiContext().nodes()) nodeJobs.put(node.id(), new AtomicInteger(0));
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.ignite.events.JobEvent in project ignite by apache.
the class GridEventConsumeSelfTest method testEventsByTypeAndFilter.
/**
* @throws Exception If failed.
*/
public void testEventsByTypeAndFilter() throws Exception {
final Collection<UUID> nodeIds = new HashSet<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(GRID_CNT);
UUID consumeId = grid(0).events().remoteListen(new P2<UUID, JobEvent>() {
@Override
public boolean apply(UUID nodeId, JobEvent evt) {
info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
assertEquals(EVT_JOB_STARTED, evt.type());
nodeIds.add(nodeId);
cnt.incrementAndGet();
latch.countDown();
return true;
}
}, new P1<JobEvent>() {
@Override
public boolean apply(JobEvent evt) {
return !"exclude".equals(evt.taskName());
}
}, EVT_JOB_STARTED);
try {
assertNotNull(consumeId);
grid(0).compute().broadcast(F.noop());
grid(0).compute().withName("exclude").run(F.noop());
assert latch.await(2, SECONDS);
assertEquals(GRID_CNT, nodeIds.size());
assertEquals(GRID_CNT, cnt.get());
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
}
Aggregations