use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class GridMarshallerMappingProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
GridDiscoveryManager discoMgr = ctx.discovery();
GridIoManager ioMgr = ctx.io();
MarshallerMappingTransport transport = new MarshallerMappingTransport(ctx, mappingExchangeSyncMap, clientReqSyncMap);
marshallerCtx.onMarshallerProcessorStarted(ctx, transport);
discoMgr.setCustomEventListener(MappingProposedMessage.class, new MarshallerMappingExchangeListener());
discoMgr.setCustomEventListener(MappingAcceptedMessage.class, new MappingAcceptedListener());
if (ctx.clientNode())
ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingResponseListener());
else
ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingRequestListener(ioMgr));
if (ctx.clientNode())
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
DiscoveryEvent evt0 = (DiscoveryEvent) evt;
if (!ctx.isStopping()) {
for (ClientRequestFuture fut : clientReqSyncMap.values()) fut.onNodeLeft(evt0.eventNode().id());
}
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener 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.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class RoundRobinGlobalLoadBalancer method onContextInitialized.
/**
* @param ctx Load balancing context.
*/
void onContextInitialized(final IgniteSpiContext ctx) {
this.ctx = ctx;
ctx.addLocalEventListener(lsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent;
UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
synchronized (mux) {
if (evt.type() == EVT_NODE_JOINED) {
List<UUID> oldNodes = nodeList.getNodes();
if (!oldNodes.contains(nodeId)) {
List<UUID> newNodes = new ArrayList<>(oldNodes.size() + 1);
newNodes.add(nodeId);
for (UUID node : oldNodes) newNodes.add(node);
nodeList = new GridNodeList(0, newNodes);
}
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
Collection<ClusterNode> nodes = ((DiscoveryEvent) evt).topologyNodes();
List<UUID> newNodes = new ArrayList<>(nodes.size());
for (ClusterNode node : nodes) newNodes.add(node.id());
nodeList = new GridNodeList(0, newNodes);
} else {
assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
List<UUID> oldNodes = nodeList.getNodes();
if (oldNodes.contains(nodeId)) {
List<UUID> newNodes = new ArrayList<>(oldNodes.size() - 1);
for (UUID node : oldNodes) if (!nodeId.equals(node))
newNodes.add(node);
nodeList = new GridNodeList(0, newNodes);
}
}
}
}
}, EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_CLIENT_NODE_RECONNECTED);
synchronized (mux) {
List<UUID> oldNodes = nodeList.getNodes();
Collection<UUID> set = oldNodes == null ? new HashSet<UUID>() : new HashSet<>(oldNodes);
for (ClusterNode node : ctx.nodes()) set.add(node.id());
nodeList = new GridNodeList(0, new ArrayList<>(set));
}
initLatch.countDown();
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class IgniteTxManager method start0.
/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
txFinishSync = new GridCacheTxFinishSync<>(cctx);
txHnd = new IgniteTxHandler(cctx);
deferredAckMsgSnd = new GridDeferredAckMessageSender<GridCacheVersion>(cctx.time(), cctx.kernalContext().closure()) {
@Override
public int getTimeout() {
return DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_TIMEOUT;
}
@Override
public int getBufferSize() {
return DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_BUFFER_SIZE;
}
@Override
public void finish(UUID nodeId, ConcurrentLinkedDeque8<GridCacheVersion> vers) {
GridDhtTxOnePhaseCommitAckRequest ackReq = new GridDhtTxOnePhaseCommitAckRequest(vers);
cctx.kernalContext().gateway().readLock();
try {
cctx.io().send(nodeId, ackReq, GridIoPolicy.SYSTEM_POOL);
} catch (ClusterTopologyCheckedException ignored) {
if (log.isDebugEnabled())
log.debug("Failed to send one phase commit ack to backup node because it left grid: " + nodeId);
} catch (IgniteCheckedException e) {
log.error("Failed to send one phase commit ack to backup node [backup=" + nodeId + ']', e);
} finally {
cctx.kernalContext().gateway().readUnlock();
}
}
};
cctx.gridEvents().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent;
assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT;
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
UUID nodeId = discoEvt.eventNode().id();
// Wait some time in case there are some unprocessed messages from failed node.
cctx.time().addTimeoutObject(new NodeFailureTimeoutObject(nodeId));
if (txFinishSync != null)
txFinishSync.onNodeLeft(nodeId);
for (TxDeadlockFuture fut : deadlockDetectFuts.values()) fut.onNodeLeft(nodeId);
for (Map.Entry<GridCacheVersion, Object> entry : completedVersHashMap.entrySet()) {
Object obj = entry.getValue();
if (obj instanceof GridCacheReturnCompletableWrapper && nodeId.equals(((GridCacheReturnCompletableWrapper) obj).nodeId()))
removeTxReturn(entry.getKey());
}
}
}, EVT_NODE_FAILED, EVT_NODE_LEFT);
this.txDeadlockDetection = new TxDeadlockDetection(cctx);
cctx.gridIO().addMessageListener(TOPIC_TX, new DeadlockDetectionListener());
}
use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.
the class IgfsFragmentizerManager method start0.
/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
if (!igfsCtx.configuration().isFragmentizerEnabled())
return;
// We care only about node leave and fail events.
igfsCtx.kernalContext().event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
checkLaunchCoordinator(discoEvt);
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
fragmentizerWorker = new FragmentizerWorker();
String igfsName = igfsCtx.configuration().getName();
topic = F.isEmpty(igfsName) ? TOPIC_IGFS : TOPIC_IGFS.topic(igfsName);
igfsCtx.kernalContext().io().addMessageListener(topic, fragmentizerWorker);
new IgniteThread(fragmentizerWorker).start();
}
Aggregations