Search in sources :

Example 11 with Service

use of org.apache.ignite.services.Service in project ignite by apache.

the class IgniteServiceDeployment2ClassLoadersDefaultMarshallerTest method serviceConfig.

/**
 * @param firstGrp First group flag.
 * @return Service configuration.
 * @throws Exception If failed.
 */
private ServiceConfiguration serviceConfig(final boolean firstGrp) throws Exception {
    ServiceConfiguration srvCfg = new ServiceConfiguration();
    srvCfg.setNodeFilter(new TestNodeFilter(firstGrp ? grp1 : grp2));
    Class<Service> srvcCls;
    if (firstGrp)
        srvcCls = (Class<Service>) extClsLdr1.loadClass(NOOP_SERVICE_CLS_NAME);
    else
        srvcCls = (Class<Service>) extClsLdr2.loadClass(NOOP_SERVICE_2_CLS_NAME);
    Service srvc = srvcCls.newInstance();
    srvCfg.setService(srvc);
    srvCfg.setName("TestDeploymentService" + (firstGrp ? 1 : 2));
    srvCfg.setMaxPerNodeCount(1);
    return srvCfg;
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Service(org.apache.ignite.services.Service)

Example 12 with Service

use of org.apache.ignite.services.Service in project ignite by apache.

the class IgniteServiceDeploymentClassLoadingDefaultMarshallerTest method serviceConfig.

/**
 * @return Service configuration.
 * @throws Exception If failed.
 */
private ServiceConfiguration serviceConfig() throws Exception {
    ServiceConfiguration srvCfg = new ServiceConfiguration();
    srvCfg.setNodeFilter(new TestNodeFilter(extClsLdrGrids));
    Class<Service> srvcCls = (Class<Service>) extClsLdr.loadClass(NOOP_SERVICE_CLS_NAME);
    Service srvc = srvcCls.newInstance();
    srvCfg.setService(srvc);
    srvCfg.setName("TestDeploymentService");
    srvCfg.setMaxPerNodeCount(1);
    return srvCfg;
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Service(org.apache.ignite.services.Service)

Example 13 with Service

use of org.apache.ignite.services.Service in project ignite by apache.

the class GridServiceProcessor method cancel.

/**
 * @param ctxs Contexts to cancel.
 * @param cancelCnt Number of contexts to cancel.
 */
private void cancel(Iterable<ServiceContextImpl> ctxs, int cancelCnt) {
    for (Iterator<ServiceContextImpl> it = ctxs.iterator(); it.hasNext(); ) {
        ServiceContextImpl svcCtx = it.next();
        // Flip cancelled flag.
        svcCtx.setCancelled(true);
        // Notify service about cancellation.
        Service svc = svcCtx.service();
        if (svc != null) {
            try {
                svc.cancel(svcCtx);
            } catch (Throwable e) {
                log.error("Failed to cancel service (ignoring) [name=" + svcCtx.name() + ", execId=" + svcCtx.executionId() + ']', e);
                if (e instanceof Error)
                    throw e;
            } finally {
                try {
                    ctx.resource().cleanup(svc);
                } catch (IgniteCheckedException e) {
                    U.error(log, "Failed to clean up service (will ignore): " + svcCtx.name(), e);
                }
            }
        }
        // Close out executor thread for the service.
        // This will cause the thread to be interrupted.
        svcCtx.executor().shutdownNow();
        it.remove();
        if (log.isInfoEnabled())
            log.info("Cancelled service instance [name=" + svcCtx.name() + ", execId=" + svcCtx.executionId() + ']');
        if (--cancelCnt == 0)
            break;
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.ignite.services.Service)

Example 14 with Service

use of org.apache.ignite.services.Service in project ignite by apache.

the class GridServiceProcessor method services.

/**
 * @param name Service name.
 * @param <T> Service type.
 * @return Services by specified service name.
 */
@SuppressWarnings("unchecked")
public <T> Collection<T> services(String name) {
    ctx.security().authorize(name, SecurityPermission.SERVICE_INVOKE, null);
    Collection<ServiceContextImpl> ctxs;
    synchronized (locSvcs) {
        ctxs = locSvcs.get(name);
    }
    if (ctxs == null)
        return null;
    synchronized (ctxs) {
        Collection<T> res = new ArrayList<>(ctxs.size());
        for (ServiceContextImpl ctx : ctxs) {
            Service svc = ctx.service();
            if (svc != null)
                res.add((T) svc);
        }
        return res;
    }
}
Also used : LT(org.apache.ignite.internal.util.typedef.internal.LT) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.ignite.services.Service)

Example 15 with Service

use of org.apache.ignite.services.Service 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

Service (org.apache.ignite.services.Service)16 Ignite (org.apache.ignite.Ignite)7 ExecutorService (java.util.concurrent.ExecutorService)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteServices (org.apache.ignite.IgniteServices)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 ServiceConfiguration (org.apache.ignite.services.ServiceConfiguration)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 GridSpinBusyLock (org.apache.ignite.internal.util.GridSpinBusyLock)1 PA (org.apache.ignite.internal.util.typedef.PA)1