use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class IgfsDataManager method start0.
/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
dataCacheStartLatch = new CountDownLatch(1);
String igfsName = igfsCtx.configuration().getName();
topic = F.isEmpty(igfsName) ? TOPIC_IGFS : TOPIC_IGFS.topic(igfsName);
igfsCtx.kernalContext().io().addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg) {
if (msg instanceof IgfsBlocksMessage)
processBlocksMessage(nodeId, (IgfsBlocksMessage) msg);
else if (msg instanceof IgfsAckMessage)
processAckMessage(nodeId, (IgfsAckMessage) msg);
}
});
igfsCtx.kernalContext().event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT;
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
if (igfsCtx.igfsNode(discoEvt.eventNode())) {
for (WriteCompletionFuture future : pendingWrites.values()) {
future.onError(discoEvt.eventNode().id(), new ClusterTopologyCheckedException("Node left grid before write completed: " + evt.node().id()));
}
}
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
delWorker = new AsyncDeleteWorker(igfsCtx.kernalContext().igniteInstanceName(), "igfs-" + igfsName + "-delete-worker", log);
dataCacheName = igfsCtx.configuration().getDataCacheConfiguration().getName();
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class PlatformDataStreamer method processInLongOutLong.
/** {@inheritDoc} */
@Override
public long processInLongOutLong(int type, final long val) throws IgniteCheckedException {
switch(type) {
case OP_SET_ALLOW_OVERWRITE:
ldr.allowOverwrite(val == TRUE);
return TRUE;
case OP_SET_PER_NODE_BUFFER_SIZE:
ldr.perNodeBufferSize((int) val);
return TRUE;
case OP_SET_SKIP_STORE:
ldr.skipStore(val == TRUE);
return TRUE;
case OP_SET_PER_NODE_PARALLEL_OPS:
ldr.perNodeParallelOperations((int) val);
return TRUE;
case OP_LISTEN_TOPOLOGY:
{
lsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
long topVer = discoEvt.topologyVersion();
int topSize = platformCtx.kernalContext().discovery().cacheNodes(cacheName, new AffinityTopologyVersion(topVer)).size();
platformCtx.gateway().dataStreamerTopologyUpdate(val, topVer, topSize);
}
};
platformCtx.kernalContext().event().addLocalEventListener(lsnr, EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT);
GridDiscoveryManager discoMgr = platformCtx.kernalContext().discovery();
AffinityTopologyVersion topVer = discoMgr.topologyVersionEx();
int topSize = discoMgr.cacheNodes(cacheName, topVer).size();
platformCtx.gateway().dataStreamerTopologyUpdate(val, topVer.topologyVersion(), topSize);
return TRUE;
}
case OP_ALLOW_OVERWRITE:
return ldr.allowOverwrite() ? TRUE : FALSE;
case OP_PER_NODE_BUFFER_SIZE:
return ldr.perNodeBufferSize();
case OP_SKIP_STORE:
return ldr.skipStore() ? TRUE : FALSE;
case OP_PER_NODE_PARALLEL_OPS:
return ldr.perNodeParallelOperations();
}
return super.processInLongOutLong(type, val);
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class GridTaskCommandHandler method requestTaskResult.
/**
* @param resHolderId Result holder.
* @param taskId Task ID.
* @return Response from task holder.
*/
private IgniteBiTuple<String, GridTaskResultResponse> requestTaskResult(final UUID resHolderId, IgniteUuid taskId) {
ClusterNode taskNode = ctx.discovery().node(resHolderId);
if (taskNode == null)
return F.t("Task result holder has left grid: " + resHolderId, null);
// Tuple: error message-response.
final IgniteBiTuple<String, GridTaskResultResponse> t = new IgniteBiTuple<>();
final Lock lock = new ReentrantLock();
final Condition cond = lock.newCondition();
GridMessageListener msgLsnr = new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg) {
String err = null;
GridTaskResultResponse res = null;
if (!(msg instanceof GridTaskResultResponse))
err = "Received unexpected message: " + msg;
else if (!nodeId.equals(resHolderId))
err = "Received task result response from unexpected node [resHolderId=" + resHolderId + ", nodeId=" + nodeId + ']';
else
// Sender and message type are fine.
res = (GridTaskResultResponse) msg;
try {
res.result(U.unmarshal(ctx, res.resultBytes(), U.resolveClassLoader(ctx.config())));
} catch (IgniteCheckedException e) {
U.error(log, "Failed to unmarshal task result: " + res, e);
}
lock.lock();
try {
if (t.isEmpty()) {
t.set(err, res);
cond.signalAll();
}
} finally {
lock.unlock();
}
}
};
GridLocalEventListener discoLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent && (evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT) : "Unexpected event: " + evt;
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
if (resHolderId.equals(discoEvt.eventNode().id())) {
lock.lock();
try {
if (t.isEmpty()) {
t.set("Node that originated task execution has left grid: " + resHolderId, null);
cond.signalAll();
}
} finally {
lock.unlock();
}
}
}
};
// 1. Create unique topic name and register listener.
Object topic = TOPIC_REST.topic("task-result", topicIdGen.getAndIncrement());
try {
ctx.io().addMessageListener(topic, msgLsnr);
// 2. Send message.
try {
byte[] topicBytes = U.marshal(ctx, topic);
ctx.io().sendToGridTopic(taskNode, TOPIC_REST, new GridTaskResultRequest(taskId, topic, topicBytes), SYSTEM_POOL);
} catch (IgniteCheckedException e) {
String errMsg = "Failed to send task result request [resHolderId=" + resHolderId + ", err=" + e.getMessage() + ']';
if (log.isDebugEnabled())
log.debug(errMsg);
return F.t(errMsg, null);
}
// 3. Listen to discovery events.
ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT);
// 4. Check whether node has left before disco listener has been installed.
taskNode = ctx.discovery().node(resHolderId);
if (taskNode == null)
return F.t("Task result holder has left grid: " + resHolderId, null);
// 5. Wait for result.
lock.lock();
try {
long netTimeout = ctx.config().getNetworkTimeout();
if (t.isEmpty())
cond.await(netTimeout, MILLISECONDS);
if (t.isEmpty())
t.set1("Timed out waiting for task result (consider increasing 'networkTimeout' " + "configuration property) [resHolderId=" + resHolderId + ", netTimeout=" + netTimeout + ']');
// Return result
return t;
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
return F.t("Interrupted while waiting for task result.", null);
} finally {
lock.unlock();
}
} finally {
ctx.io().removeMessageListener(topic, msgLsnr);
ctx.event().removeLocalEventListener(discoLsnr);
}
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class IgniteSpiAdapter method onContextInitialized.
/** {@inheritDoc} */
@Override
public final void onContextInitialized(final IgniteSpiContext spiCtx) throws IgniteSpiException {
assert spiCtx != null;
this.spiCtx = spiCtx;
if (!Boolean.getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
spiCtx.addLocalEventListener(paramsLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent : "Invalid event [expected=" + EVT_NODE_JOINED + ", actual=" + evt.type() + ", evt=" + evt + ']';
ClusterNode node = spiCtx.node(((DiscoveryEvent) evt).eventNode().id());
if (node != null)
try {
checkConfigurationConsistency(spiCtx, node, false);
checkConfigurationConsistency0(spiCtx, node, false);
} catch (IgniteSpiException e) {
U.error(log, "Spi consistency check failed [node=" + node.id() + ", spi=" + getName() + ']', e);
}
}
}, EVT_NODE_JOINED);
final Collection<ClusterNode> remotes = F.concat(false, spiCtx.remoteNodes(), spiCtx.remoteDaemonNodes());
for (ClusterNode node : remotes) {
checkConfigurationConsistency(spiCtx, node, true);
checkConfigurationConsistency0(spiCtx, node, true);
}
}
onContextInitialized0(spiCtx);
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class WeightedRandomLoadBalancingSpi method onContextInitialized0.
/** {@inheritDoc} */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof TaskEvent || evt instanceof JobEvent;
if (evt.type() == EVT_TASK_FINISHED || evt.type() == EVT_TASK_FAILED) {
IgniteUuid sesId = ((TaskEvent) evt).taskSessionId();
taskTops.remove(sesId);
if (log.isDebugEnabled())
log.debug("Removed task topology from topology cache for session: " + sesId);
} else // Here we set mapped property and later cache will be ignored
if (evt.type() == EVT_JOB_MAPPED) {
IgniteUuid sesId = ((JobEvent) evt).taskSessionId();
IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(sesId);
if (weightedTop != null)
weightedTop.set1(true);
if (log.isDebugEnabled())
log.debug("Job has been mapped. Ignore cache for session: " + sesId);
}
}
}, EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
}
Aggregations