Search in sources :

Example 1 with GridSpinBusyLock

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();
    }
}
Also used : GridSpinBusyLock(org.apache.ignite.internal.util.GridSpinBusyLock) NullLogger(org.apache.ignite.logger.NullLogger) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) UUID(java.util.UUID)

Example 2 with GridSpinBusyLock

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();
}
Also used : IgniteThreadFactory(org.apache.ignite.thread.IgniteThreadFactory) GridSpinBusyLock(org.apache.ignite.internal.util.GridSpinBusyLock)

Example 3 with GridSpinBusyLock

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.");
}
Also used : GridSpinBusyLock(org.apache.ignite.internal.util.GridSpinBusyLock) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.ignite.services.Service) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SecurityException(org.apache.ignite.plugin.security.SecurityException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

GridSpinBusyLock (org.apache.ignite.internal.util.GridSpinBusyLock)3 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 ExecutorService (java.util.concurrent.ExecutorService)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 NullLogger (org.apache.ignite.logger.NullLogger)1 SecurityException (org.apache.ignite.plugin.security.SecurityException)1 Service (org.apache.ignite.services.Service)1 ServiceDeploymentException (org.apache.ignite.services.ServiceDeploymentException)1 IgniteThreadFactory (org.apache.ignite.thread.IgniteThreadFactory)1