Refine search
@Override public int pendingTasks() { return super.pendingTasks() + tailTasks.size(); }
@Override protected void doRegister() throws Exception { ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook); }
@Override public void execute(Runnable task) { if (task == null) { throw new NullPointerException("task"); } boolean inEventLoop = inEventLoop(); addTask(task); if (!inEventLoop) { startThread(); if (isShutdown()) { boolean reject = false; try { if (removeTask(task)) { reject = true; } } catch (UnsupportedOperationException e) { // The task queue does not support removal so the best thing we can do is to just move on and // hope we will be able to pick-up the task before its completely terminated. // In worst case we will log on termination. } if (reject) { reject(); } } } if (!addTaskWakesUp && wakesUpForTask(task)) { wakeup(inEventLoop); } }
/** * Remove a previous added {@link Runnable} as a shutdown hook */ public void removeShutdownHook(final Runnable task) { if (inEventLoop()) { shutdownHooks.remove(task); } else { execute(new Runnable() { @Override public void run() { shutdownHooks.remove(task); } }); } }
/** * Poll all tasks from the task queue and run them via {@link Runnable#run()} method. * * @return {@code true} if and only if at least one task was run */ protected boolean runAllTasks() { assert inEventLoop(); boolean fetchedAll; boolean ranAtLeastOne = false; do { fetchedAll = fetchFromScheduledTaskQueue(); if (runAllTasksFrom(taskQueue)) { ranAtLeastOne = true; } } while (!fetchedAll); // keep on processing until we fetched all scheduled tasks. if (ranAtLeastOne) { lastExecutionTime = ScheduledFutureTask.nanoTime(); } afterRunningAllTasks(); return ranAtLeastOne; }
updateLastExecutionTime(); try { SingleThreadEventExecutor.this.run(); success = true; } catch (Throwable t) { if (confirmShutdown()) { break; cleanup(); } finally { if (!taskQueue.isEmpty()) { if (logger.isWarnEnabled()) { logger.warn("An event executor terminated with " + "non-empty task queue (" + taskQueue.size() + ')');
if (!isShuttingDown()) { return false; if (!inEventLoop()) { throw new IllegalStateException("must be invoked from an event loop"); cancelScheduledTasks(); if (runAllTasks() || runShutdownHooks()) { if (isShutdown()) { return true; wakeup(true); return false; if (isShutdown() || nanoTime - gracefulShutdownStartTime > gracefulShutdownTimeout) { return true; wakeup(true); try { Thread.sleep(100);
fetchFromScheduledTaskQueue(); Runnable task = pollTask(); if (task == null) { afterRunningAllTasks(); return false; long lastExecutionTime; for (;;) { safeExecute(task); task = pollTask(); if (task == null) { lastExecutionTime = ScheduledFutureTask.nanoTime(); afterRunningAllTasks(); this.lastExecutionTime = lastExecutionTime; return true;
@Override @Deprecated public void shutdown() { if (isShutdown()) { return; boolean inEventLoop = inEventLoop(); boolean wakeup; int oldState; for (;;) { if (isShuttingDown()) { return; doStartThread(); } catch (Throwable cause) { STATE_UPDATER.set(this, ST_TERMINATED); wakeup(inEventLoop);
if (isShuttingDown()) { return terminationFuture(); boolean inEventLoop = inEventLoop(); boolean wakeup; int oldState; for (;;) { if (isShuttingDown()) { return terminationFuture(); doStartThread(); } catch (Throwable cause) { STATE_UPDATER.set(this, ST_TERMINATED); wakeup(inEventLoop); return terminationFuture();
assert inEventLoop(); if (!(taskQueue instanceof BlockingQueue)) { throw new UnsupportedOperationException(); ScheduledFutureTask<?> scheduledTask = peekScheduledTask(); if (scheduledTask == null) { Runnable task = null; fetchFromScheduledTaskQueue(); task = taskQueue.poll();
state = State.CONNECTED; peer.remoteAddress = parent() == null ? null : parent().localAddress(); peer.state = State.CONNECTED; ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook);
private void startThread() { if (state == ST_NOT_STARTED) { if (STATE_UPDATER.compareAndSet(this, ST_NOT_STARTED, ST_STARTED)) { try { doStartThread(); } catch (Throwable cause) { STATE_UPDATER.set(this, ST_NOT_STARTED); PlatformDependent.throwException(cause); } } } }
@Override public Integer getValue() { return singleExecutor.pendingTasks(); } });
updateLastExecutionTime(); try { SingleThreadEventExecutor.this.run(); success = true; } catch (Throwable t) { if (confirmShutdown()) { break; cleanup(); } finally { if (!taskQueue.isEmpty()) { if (logger.isWarnEnabled()) { logger.warn("An event executor terminated with " + "non-empty task queue (" + taskQueue.size() + ')');
if (!isShuttingDown()) { return false; if (!inEventLoop()) { throw new IllegalStateException("must be invoked from an event loop"); cancelScheduledTasks(); if (runAllTasks() || runShutdownHooks()) { if (isShutdown()) { return true; wakeup(true); return false; if (isShutdown() || nanoTime - gracefulShutdownStartTime > gracefulShutdownTimeout) { return true; wakeup(true); try { Thread.sleep(100);
/** * Poll all tasks from the task queue and run them via {@link Runnable#run()} method. * * @return {@code true} if and only if at least one task was run */ protected boolean runAllTasks() { assert inEventLoop(); boolean fetchedAll; boolean ranAtLeastOne = false; do { fetchedAll = fetchFromScheduledTaskQueue(); if (runAllTasksFrom(taskQueue)) { ranAtLeastOne = true; } } while (!fetchedAll); // keep on processing until we fetched all scheduled tasks. if (ranAtLeastOne) { lastExecutionTime = ScheduledFutureTask.nanoTime(); } afterRunningAllTasks(); return ranAtLeastOne; }
fetchFromScheduledTaskQueue(); Runnable task = pollTask(); if (task == null) { afterRunningAllTasks(); return false; long lastExecutionTime; for (;;) { safeExecute(task); task = pollTask(); if (task == null) { lastExecutionTime = ScheduledFutureTask.nanoTime(); afterRunningAllTasks(); this.lastExecutionTime = lastExecutionTime; return true;
@Override @Deprecated public void shutdown() { if (isShutdown()) { return; boolean inEventLoop = inEventLoop(); boolean wakeup; int oldState; for (;;) { if (isShuttingDown()) { return; doStartThread(); } catch (Throwable cause) { STATE_UPDATER.set(this, ST_TERMINATED); wakeup(inEventLoop);
if (isShuttingDown()) { return terminationFuture(); boolean inEventLoop = inEventLoop(); boolean wakeup; int oldState; for (;;) { if (isShuttingDown()) { return terminationFuture(); doStartThread(); } catch (Throwable cause) { STATE_UPDATER.set(this, ST_TERMINATED); wakeup(inEventLoop); return terminationFuture();