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