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;
}
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;
}
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;
}
}
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;
}
}
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.");
}
Aggregations