use of org.apache.ignite.internal.util.GridSpinBusyLock in project ignite by apache.
the class GridH2IndexBase method initDistributedJoinMessaging.
/**
* @param tbl Table.
*/
protected final void initDistributedJoinMessaging(GridH2Table tbl) {
final GridH2RowDescriptor desc = tbl.rowDescriptor();
if (desc != null && desc.context() != null) {
ctx = desc.context();
GridKernalContext ctx = desc.context().kernalContext();
log = ctx.log(getClass());
msgTopic = new IgniteBiTuple<>(GridTopic.TOPIC_QUERY, tbl.identifierString() + '.' + getName());
msgLsnr = new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
GridSpinBusyLock l = desc.indexing().busyLock();
if (!l.enterBusy())
return;
try {
onMessage0(nodeId, msg);
} finally {
l.leaveBusy();
}
}
};
ctx.io().addMessageListener(msgTopic, msgLsnr);
} else {
msgTopic = null;
msgLsnr = null;
log = new NullLogger();
}
}
use of org.apache.ignite.internal.util.GridSpinBusyLock in project ignite by apache.
the class GridServiceProcessor method onActivate.
/**
* {@inheritDoc}
*/
@Override
public void onActivate(GridKernalContext kctx) throws IgniteCheckedException {
if (log.isDebugEnabled())
log.debug("Activate service processor [nodeId=" + ctx.localNodeId() + " topVer=" + ctx.discovery().topologyVersionEx() + " ]");
busyLock = new GridSpinBusyLock();
depExe = Executors.newSingleThreadExecutor(new IgniteThreadFactory(ctx.igniteInstanceName(), "srvc-deploy"));
start();
onKernalStart0();
}
use of org.apache.ignite.internal.util.GridSpinBusyLock in project ignite by apache.
the class GridServiceProcessor method onKernalStop.
/**
* {@inheritDoc}
*/
@Override
public void onKernalStop(boolean cancel) {
if (ctx.isDaemon())
return;
GridSpinBusyLock busyLock = this.busyLock;
// Will not release it.
if (busyLock != null) {
busyLock.block();
this.busyLock = null;
}
startLatch.countDown();
U.shutdownNow(GridServiceProcessor.class, depExe, log);
if (!ctx.clientNode())
ctx.event().removeDiscoveryEventListener(topLsnr);
Collection<ServiceContextImpl> ctxs = new ArrayList<>();
synchronized (locSvcs) {
for (Collection<ServiceContextImpl> ctxs0 : locSvcs.values()) ctxs.addAll(ctxs0);
}
for (ServiceContextImpl ctx : ctxs) {
ctx.setCancelled(true);
Service svc = ctx.service();
if (svc != null)
try {
svc.cancel(ctx);
} catch (Throwable e) {
log.error("Failed to cancel service (ignoring) [name=" + ctx.name() + ", execId=" + ctx.executionId() + ']', e);
if (e instanceof Error)
throw e;
}
ctx.executor().shutdownNow();
}
for (ServiceContextImpl ctx : ctxs) {
try {
if (log.isInfoEnabled() && !ctxs.isEmpty())
log.info("Shutting down distributed service [name=" + ctx.name() + ", execId8=" + U.id8(ctx.executionId()) + ']');
ctx.executor().awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
U.error(log, "Got interrupted while waiting for service to shutdown (will continue stopping node): " + ctx.name());
}
}
Exception err = new IgniteCheckedException("Operation has been cancelled (node is stopping).");
cancelFutures(depFuts, err);
cancelFutures(undepFuts, err);
if (log.isDebugEnabled())
log.debug("Stopped service processor.");
}
Aggregations