public synchronized static ExecutionHandler getExecutionHandler() { if(null == EXECUTION_HANDLER){ EXECUTION_HANDLER = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)); } return EXECUTION_HANDLER; }
/** * Shuts down the {@link Executor} which was specified with the constructor * and wait for its termination. */ public void releaseExternalResources() { Executor executor = getExecutor(); if (executor instanceof ExecutorService) { ((ExecutorService) executor).shutdown(); } if (executor instanceof ExternalResourceReleasable) { ((ExternalResourceReleasable) executor).releaseExternalResources(); } }
@Override protected void startUp() throws Exception { executionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(4, 0, 0)); bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { final ChannelPipeline pipeline = Channels.pipeline(); //pipeline.addLast("logger", new LoggingHandler(InternalLogLevel.INFO)); pipeline.addLast("xmlFramer", new XMLFrameDecoder()); pipeline.addLast("xmlDecoder", new XMLElementDecoder()); pipeline.addLast("xmppDecoder", new XEP0114Decoder(xmppHost, xmppSecret)); pipeline.addLast("executor", executionHandler); pipeline.addLast("xmppHandler", new XMPPStreamHandler(component)); return pipeline; } }); final ChannelFuture future = bootstrap.connect(serverAddress).await(); if (!future.isSuccess()) { bootstrap.releaseExternalResources(); executionHandler.releaseExternalResources(); future.rethrowIfFailed(); } channel = future.getChannel(); component.init(channel, JID.jid("localhost"), JID.jid(xmppHost)); // FIXME }
@Override protected void shutDown() throws Exception { bootstrap.releaseExternalResources(); executionHandler.releaseExternalResources(); }
/** * Set true if an ExecutionHandler should be used to hand over the tasks. This should be done if you have some {@link ProtocolHandler}'s which need to full fill some blocking operation. * * @param useHandler <code>true</code> if an ExecutionHandler should be used * @param size the thread count to use */ public void setUseExecutionHandler(boolean useHandler, int size) { if (isBound()) { throw new IllegalStateException("Server running already"); } if (useHandler) { eHandler = createExecutionHandler(size); } else { if (eHandler != null) { eHandler.releaseExternalResources(); } eHandler = null; } }
new NioServerSocketChannelFactory (Executors.newCachedThreadPool(), Executors.newCachedThreadPool()), new ExecutionHandler(Executors.newCachedThreadPool())); server.start();
/** * Set true if an ExecutionHandler should be used to hand over the tasks. This should be done if you have some {@link ProtocolHandler}'s which need to full fill some blocking operation. * * @param useHandler <code>true</code> if an ExecutionHandler should be used * @param size the thread count to use */ public void setUseExecutionHandler(boolean useHandler, int size) { if (isBound()) { throw new IllegalStateException("Server running already"); } if (useHandler) { eHandler = createExecutionHandler(size); } else { if (eHandler != null) { eHandler.releaseExternalResources(); } eHandler = null; } }
public HttpServerPipelineFactory(final RequestDispatcher dispatcher, final String root, final int executorThreadCount, final int maxRequestSize, final boolean isKeepAlive, final List<ChannelHandler> additionalChannelHandlers) { this.resteasyDecoder = new RestEasyHttpRequestDecoder(dispatcher.getDispatcher(), root, getProtocol(), isKeepAlive); this.resteasyEncoder = new RestEasyHttpResponseEncoder(dispatcher); this.resteasyRequestHandler = new RequestHandler(dispatcher); if (executorThreadCount > 0) { this.executionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(executorThreadCount, 0L, 0L)); } else { this.executionHandler = null; } this.maxRequestSize = maxRequestSize; this.additionalChannelHandlers = additionalChannelHandlers; }
@PreDestroy public final void destroy() { LOGGER.info("Dispose {}", getServiceType()); if (isEnabled()) { unbind(); postDestroy(); if (executionHandler != null) { executionHandler.releaseExternalResources(); } unregisterMBean(); } LOGGER.info("Dispose {} done", getServiceType()); }
public NettyServer(InetSocketAddress addr, ChannelFactory channelFactory, Configuration conf) { this(addr, channelFactory, new ExecutionHandler( new MemoryAwareThreadPoolExecutor(128, 1024 * 1024 * 32, 1024 * 1024 * 32)), conf); }
/** * Shuts the AirReceiver down gracefully */ public static void onShutdown() { /* Close channels */ final ChannelGroupFuture allChannelsClosed = s_allChannels.close(); /* Stop all mDNS responders */ synchronized(s_jmDNSInstances) { for(final JmDNS jmDNS: s_jmDNSInstances) { try { jmDNS.unregisterAllServices(); s_logger.info("Unregistered all services on " + jmDNS.getInterface()); } catch (final IOException e) { s_logger.info("Failed to unregister some services"); } } } /* Wait for all channels to finish closing */ allChannelsClosed.awaitUninterruptibly(); /* Stop the ExecutorService */ ExecutorService.shutdown(); /* Release the OrderedMemoryAwareThreadPoolExecutor */ ChannelExecutionHandler.releaseExternalResources(); }
protected ExecutionHandler createExecutionHandler(int size) { return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0)); }
protected ExecutionHandler createExecutionHandler(int size) { return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0)); }
public SimplePipelineFactory(SimpleServerHandler handler) { this.handler = handler; this.executor = new ThreadPoolExecutor(60, 600, 30000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable e) { logger.error("thread:" + thread.getName() + " uncaughtException:" + e.getMessage(), e); } }); thread.setName("worker-pool-thread-" + threaCounter.incrementAndGet()); thread.setDaemon(false); return thread; } }, new ThreadPoolExecutor.DiscardPolicy()); this.executionHandler = new ExecutionHandler(executor); }
@PostConstruct public void start() throws IOException, RepositoryException, InterruptedException { AvroLilyImpl avroLily = new AvroLilyImpl(repositoryManager, repositoryManager.getDefaultRepository().getTypeManager()); Responder responder = new LilySpecificResponder(AvroLily.class, avroLily); ThreadFactory threadFactory = new CustomThreadFactory("avro-exechandler", new ThreadGroup("AvroExecHandler")); if (maxServerThreads == -1) { executorService = Executors.newCachedThreadPool(threadFactory); executionHandler = new ExecutionHandler(executorService); } else { executorService = new ThreadPoolExecutor(maxServerThreads / 3, maxServerThreads, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory, new WaitPolicy()); executionHandler = new ExecutionHandler(executorService); } //server = new HttpServer(responder, port); server = new NettyServer(responder, new InetSocketAddress(port), new NioServerSocketChannelFactory (Executors.newCachedThreadPool(), Executors.newCachedThreadPool()), executionHandler); server.start(); }
public SwitchChannelPipeline( final OpenVirteXController openVirteXController, final ThreadPoolExecutor pipelineExecutor) { super(); this.ctrl = openVirteXController; this.pipelineExecutor = pipelineExecutor; this.timer = PhysicalNetwork.getTimer(); this.idleHandler = new IdleStateHandler(this.timer, 20, 25, 0); this.readTimeoutHandler = new ReadTimeoutHandler(this.timer, 30); this.eh = new ExecutionHandler(this.pipelineExecutor); }
@Override protected void doStart() { executionHandler = new ExecutionHandler(executor); bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setPipelineFactory(new PipelineFactory()); bootstrap.bind(new InetSocketAddress(this.port)); }
protected CoapChannelPipelineFactory(ScheduledExecutorService executor) { this.channelHandlers = new LinkedHashSet<>(); addChannelHandler(new ExecutionHandler(executor)); addChannelHandler(new CoapMessageEncoder()); addChannelHandler(new CoapMessageDecoder()); }
/** * Create a new {@link ExecutionHandler} which is used to execute IO-Bound handlers * * @return ehandler */ protected ExecutionHandler createExecutionHander() { return new ExecutionHandler(new JMXEnabledOrderedMemoryAwareThreadPoolExecutor(maxExecutorThreads, 0, 0, getThreadPoolJMXPath(), getDefaultJMXName() + "-executor")); }
@Override public ChannelPipeline getPipeline() throws Exception { final ChannelPipeline pipeline = Channels.pipeline(); if(executor != null) pipeline.addLast("executor", new ExecutionHandler(executor)); pipeline.addLast("logging", new LoggingHandler(logger)); // a node resolver must be added before the mesage codec pipeline.addLast("messageCodec", new MessagePacketCodec()); pipeline.addLast("nodeResolver", nodeResolver); return pipeline; } }