public synchronized static ExecutionHandler getExecutionHandler() { if(null == EXECUTION_HANDLER){ EXECUTION_HANDLER = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)); } return EXECUTION_HANDLER; }
public void run() { try { runnable.run(); } finally { // if "next" is not null, then trigger "next" to execute; // else if "next" is null, set "next" to END, means end this linked list if (!compareAndSetNext(this, null, end)) { doUnorderedExecute(next); } } } }
@Override protected boolean shouldCount(Runnable task) { if (task instanceof ChildExecutor) { return false; } return super.shouldCount(task); }
@Override public void execute(Runnable command) { if (command instanceof ChannelDownstreamEventRunnable) { throw new RejectedExecutionException("command must be enclosed with an upstream event."); } if (!(command instanceof ChannelEventRunnable)) { command = new MemoryAwareRunnable(command); } increaseCounter(command); doExecute(command); }
/** * Executes the specified task concurrently while maintaining the event * order. */ @Override protected void doExecute(Runnable task) { if (!(task instanceof ChannelEventRunnable)) { doUnorderedExecute(task); } else { ChannelEventRunnable r = (ChannelEventRunnable) task; getChildExecutor(r.getEvent()).execute(task); } }
void onAfterExecute(Runnable r, Throwable t) { afterExecute(r, t); }
public void handleDownstream( ChannelHandlerContext ctx, ChannelEvent e) throws Exception { // check if the read was suspend if (!handleReadSuspend(ctx, e)) { if (handleDownstream) { executor.execute(new ChannelDownstreamEventRunnable(ctx, e, executor)); } else { ctx.sendDownstream(e); } } }
private void removeIfClosed(ChannelEventRunnable eventRunnable, Object key) { ChannelEvent event = eventRunnable.getEvent(); if (event instanceof ChannelStateEvent) { ChannelStateEvent se = (ChannelStateEvent) event; if (se.getState() == ChannelState.OPEN && !event.getChannel().isOpen()) { removeKey(key); } } }
@Override protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); decreaseCounter(r); }
/** * This will call {@link #shutdownNow(boolean)} with the value of {@link #getNotifyChannelFuturesOnShutdown()}. */ @Override public List<Runnable> shutdownNow() { return shutdownNow(notifyOnShutdown); }
/** * Put the actual execution logic here. The default implementation simply * calls {@link #doUnorderedExecute(Runnable)}. */ protected void doExecute(Runnable task) { doUnorderedExecute(task); }
public void operationComplete(ChannelFuture future) throws Exception { removeKey(key); } });
public void operationComplete(ChannelFuture future) throws Exception { removeChildExecutor(key); } });
public final void run() { doRun(); }
/** * Sets the {@link ObjectSizeEstimator} of this pool. */ public void setObjectSizeEstimator(ObjectSizeEstimator objectSizeEstimator) { if (objectSizeEstimator == null) { throw new NullPointerException("objectSizeEstimator"); } settings = new Settings( objectSizeEstimator, settings.maxChannelMemorySize); }
@Override public void execute(Runnable command) { // check if the Runnable was of an unsupported type if (command instanceof ChannelUpstreamEventRunnable) { throw new RejectedExecutionException("command must be enclosed with an downstream event."); } doExecute(command); }
@Override public void execute(Runnable command) { // check if the Runnable was of an unsupported type if (command instanceof ChannelUpstreamEventRunnable) { throw new RejectedExecutionException("command must be enclosed with an downstream event."); } doExecute(command); }
public void releaseExternalResources() { if (cur instanceof ExecutorService) { ((ExecutorService) cur).shutdown(); } if (next instanceof ExecutorService) { ((ExecutorService) next).shutdown(); } releaseExternal(cur); releaseExternal(next); }
@Override protected boolean shouldCount(Runnable task) { return !(task instanceof EventTask) && super.shouldCount(task); }
@Override public boolean remove(Runnable task) { boolean removed = super.remove(task); if (removed) { decreaseCounter(task); } return removed; }