Search in sources :

Example 96 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException 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)

Example 97 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project ignite by apache.

the class GridClosureProcessor method runLocal.

/**
     * @param c Closure to execute.
     * @param plc Whether to run on system or public pool.
     * @return Future.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
public IgniteInternalFuture<?> runLocal(@Nullable final Runnable c, byte plc) throws IgniteCheckedException {
    if (c == null)
        return new GridFinishedFuture();
    busyLock.readLock();
    try {
        // Inject only if needed.
        if (!(c instanceof GridPlainRunnable))
            ctx.resource().inject(ctx.deploy().getDeployment(c.getClass().getName()), c.getClass(), c);
        final ClassLoader ldr = Thread.currentThread().getContextClassLoader();
        final GridWorkerFuture fut = new GridWorkerFuture();
        GridWorker w = new GridWorker(ctx.igniteInstanceName(), "closure-proc-worker", log) {

            @Override
            protected void body() {
                try {
                    if (ldr != null)
                        U.wrapThreadLoader(ldr, c);
                    else
                        c.run();
                    fut.onDone();
                } 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 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 : GridWorkerFuture(org.apache.ignite.internal.util.worker.GridWorkerFuture) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 98 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project ignite by apache.

the class IgfsIpcHandler method handleAsync.

/** {@inheritDoc} */
@Override
public IgniteInternalFuture<IgfsMessage> handleAsync(final IgfsClientSession ses, final IgfsMessage msg, final DataInput in) {
    try {
        // Even if will be closed right after this call, response write error will be ignored.
        if (stopping)
            return null;
        final IgfsIpcCommand cmd = msg.command();
        IgniteInternalFuture<IgfsMessage> fut;
        switch(cmd) {
            // Execute not-blocking command synchronously in worker thread.
            case WRITE_BLOCK:
            case MAKE_DIRECTORIES:
            case LIST_FILES:
            case LIST_PATHS:
                {
                    fut = executeSynchronously(ses, cmd, msg, in);
                    break;
                }
            // Execute command asynchronously in pool.
            default:
                {
                    try {
                        final GridFutureAdapter<IgfsMessage> fut0 = new GridFutureAdapter<>();
                        pool.execute(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    fut0.onDone(execute(ses, cmd, msg, in));
                                } catch (Exception e) {
                                    fut0.onDone(e);
                                }
                            }
                        });
                        fut = fut0;
                    } catch (RejectedExecutionException ignored) {
                        fut = executeSynchronously(ses, cmd, msg, in);
                    }
                }
        }
        // Pack result object into response format.
        return fut;
    } catch (Exception e) {
        return new GridFinishedFuture<>(e);
    }
}
Also used : IgfsIpcCommand(org.apache.ignite.internal.igfs.common.IgfsIpcCommand) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgfsMessage(org.apache.ignite.internal.igfs.common.IgfsMessage) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgfsOutOfSpaceException(org.apache.ignite.igfs.IgfsOutOfSpaceException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 99 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project ignite by apache.

the class GridJobProcessor method executeAsync.

/**
     * @param jobWorker Job worker.
     * @return {@code True} if job has been submitted to pool.
     */
private boolean executeAsync(GridJobWorker jobWorker) {
    try {
        if (jobWorker.executorName() != null) {
            Executor customExec = ctx.pools().customExecutor(jobWorker.executorName());
            if (customExec != null)
                customExec.execute(jobWorker);
            else {
                LT.warn(log, "Custom executor doesn't exist (local job will be processed in default " + "thread pool): " + jobWorker.executorName());
                ctx.getExecutorService().execute(jobWorker);
            }
        } else
            ctx.getExecutorService().execute(jobWorker);
        if (metricsUpdateFreq > -1L)
            startedJobsCnt.increment();
        return true;
    } catch (RejectedExecutionException e) {
        // Remove from active jobs.
        activeJobs.remove(jobWorker.getJobId(), jobWorker);
        // Even if job was removed from another thread, we need to reject it
        // here since job has never been executed.
        IgniteException e2 = new ComputeExecutionRejectedException("Job has been rejected " + "[jobSes=" + jobWorker.getSession() + ", job=" + jobWorker.getJob() + ']', e);
        if (metricsUpdateFreq > -1L)
            rejectedJobsCnt.increment();
        jobWorker.finishJob(null, e2, true);
    }
    return false;
}
Also used : Executor(java.util.concurrent.Executor) IgniteException(org.apache.ignite.IgniteException) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 100 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project ignite by apache.

the class GridRestProcessor method handleAsync0.

/**
     * @param req Request.
     * @return Future.
     */
private IgniteInternalFuture<GridRestResponse> handleAsync0(final GridRestRequest req) {
    if (!busyLock.tryReadLock())
        return new GridFinishedFuture<>(new IgniteCheckedException("Failed to handle request (received request while stopping grid)."));
    try {
        final GridWorkerFuture<GridRestResponse> fut = new GridWorkerFuture<>();
        workersCnt.increment();
        GridWorker w = new GridWorker(ctx.igniteInstanceName(), "rest-proc-worker", log) {

            @Override
            protected void body() {
                try {
                    IgniteInternalFuture<GridRestResponse> res = handleRequest(req);
                    res.listen(new IgniteInClosure<IgniteInternalFuture<GridRestResponse>>() {

                        @Override
                        public void apply(IgniteInternalFuture<GridRestResponse> f) {
                            try {
                                fut.onDone(f.get());
                            } catch (IgniteCheckedException e) {
                                fut.onDone(e);
                            }
                        }
                    });
                } catch (Throwable e) {
                    if (e instanceof Error)
                        U.error(log, "Client request execution failed with error.", e);
                    fut.onDone(U.cast(e));
                    if (e instanceof Error)
                        throw e;
                } finally {
                    workersCnt.decrement();
                }
            }
        };
        fut.setWorker(w);
        try {
            ctx.getRestExecutorService().execute(w);
        } catch (RejectedExecutionException e) {
            U.error(log, "Failed to execute worker due to execution rejection " + "(increase upper bound on REST executor service). " + "Will attempt to process request in the current thread instead.", e);
            w.run();
        }
        return fut;
    } finally {
        busyLock.readUnlock();
    }
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridWorkerFuture(org.apache.ignite.internal.util.worker.GridWorkerFuture)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)231 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)31 Test (org.junit.Test)29 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 ExecutionException (java.util.concurrent.ExecutionException)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 Executor (java.util.concurrent.Executor)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9