use of org.apache.ignite.internal.util.lang.GridPlainCallable in project ignite by apache.
the class GridClosureProcessor method callLocal.
/**
* @param c Closure to execute.
* @param plc Whether to run on system or public pool.
* @param <R> Type of closure return value.
* @return Future.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
public <R> IgniteInternalFuture<R> callLocal(@Nullable final Callable<R> c, byte plc) throws IgniteCheckedException {
if (c == null)
return new GridFinishedFuture<>();
busyLock.readLock();
try {
// Inject only if needed.
if (!(c instanceof GridPlainCallable))
ctx.resource().inject(ctx.deploy().getDeployment(c.getClass().getName()), c.getClass(), c);
final ClassLoader ldr = Thread.currentThread().getContextClassLoader();
final GridWorkerFuture<R> fut = new GridWorkerFuture<>();
GridWorker w = new GridWorker(ctx.igniteInstanceName(), "closure-proc-worker", log) {
@Override
protected void body() {
try {
if (ldr != null)
fut.onDone(U.wrapThreadLoader(ldr, c));
else
fut.onDone(c.call());
} catch (Throwable e) {
if (e instanceof Error)
U.error(log, "Closure execution failed with error.", e);
fut.onDone(U.cast(e));
if (e instanceof Error)
throw (Error) e;
}
}
};
fut.setWorker(w);
try {
pools.poolForPolicy(plc).execute(w);
} catch (RejectedExecutionException e) {
U.error(log, "Failed to execute worker due to execution rejection " + "(increase upper bound on executor service) [policy=" + plc + ']', e);
w.run();
}
return fut;
} finally {
busyLock.readUnlock();
}
}
Aggregations