Search in sources :

Example 1 with GridPlainCallable

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();
    }
}
Also used : TC_NO_FAILOVER(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_NO_FAILOVER) FAILOVER(org.apache.ignite.compute.ComputeJobResultPolicy.FAILOVER) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) GridWorkerFuture(org.apache.ignite.internal.util.worker.GridWorkerFuture) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 FAILOVER (org.apache.ignite.compute.ComputeJobResultPolicy.FAILOVER)1 TC_NO_FAILOVER (org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_NO_FAILOVER)1 GridPlainCallable (org.apache.ignite.internal.util.lang.GridPlainCallable)1 GridWorker (org.apache.ignite.internal.util.worker.GridWorker)1 GridWorkerFuture (org.apache.ignite.internal.util.worker.GridWorkerFuture)1