org.jboss.netty.handler.execution.ExecutionHandler Java Examples

The following examples show how to use org.jboss.netty.handler.execution.ExecutionHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyServer.java    From recipes-rss with Apache License 2.0 6 votes vote down vote up
public PipelineFactory(Map<String, ChannelHandler> handlers,
		ChannelHandler encoder, ChannelHandler decoder, int numThreads) {

	this.handlers = handlers;
	this.encoder = encoder;
	this.decoder = decoder;

	if (numThreads != 0) {
		ThreadPoolExecutor executorThreadPool = new ThreadPoolExecutor(
				NettyServer.cpus, NettyServer.cpus * 4, 60,
				TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
				new DescriptiveThreadFactory("Executor-Thread"));

		this.executionHandler = new ExecutionHandler(executorThreadPool);
	} else {
		this.executionHandler = null;
	}
}
 
Example #2
Source File: OpenflowPipelineFactory.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    OFChannelHandler handler = new OFChannelHandler(controller);
    
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
    pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
    pipeline.addLast("idle", idleHandler);
    pipeline.addLast("timeout", readTimeoutHandler);
    pipeline.addLast("handshaketimeout",
                     new HandshakeTimeoutHandler(handler, timer, 15));
    if (pipelineExecutor != null)
        pipeline.addLast("pipelineExecutor",
                         new ExecutionHandler(pipelineExecutor));
    pipeline.addLast("handler", handler);
    return pipeline;
}
 
Example #3
Source File: AirPlayServer.java    From Android-Airplay-Server with MIT License 5 votes vote down vote up
private AirPlayServer(){
	//create executor service
	executorService = Executors.newCachedThreadPool();
	
	//create channel execution handler
	channelExecutionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(4, 0, 0));

	//channel group
	channelGroup = new DefaultChannelGroup();
	
	//list of mDNS services
	jmDNSInstances = new java.util.LinkedList<JmDNS>();
}
 
Example #4
Source File: MongoServerPipelineFactory.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public MongoServerPipelineFactory( EntityManagerFactory emf, ServiceManagerFactory smf,
                                   ManagementService management, SessionsSecurityManager securityManager,
                                   ExecutionHandler executionHandler ) {
    this.emf = emf;
    this.smf = smf;
    this.management = management;
    this.securityManager = securityManager;
    this.executionHandler = executionHandler;
}
 
Example #5
Source File: MongoServer.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public void startServer() {

        if ( ( properties != null ) && ( Boolean
                .parseBoolean( properties.getProperty( "usergrid.mongo.disable", "false" ) ) ) ) {
            logger.info( "Usergrid Mongo Emulation Server Disabled" );
            return;
        }

        logger.info( "Starting Usergrid Mongo Emulation Server" );

        if ( realm != null ) {
            securityManager = new DefaultSecurityManager( realm );
        }

        // Configure the server.
        ServerBootstrap bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool() ) );

        bootstrap.setOption( "child.bufferFactory", HeapChannelBufferFactory.getInstance( ByteOrder.LITTLE_ENDIAN ) );

        // Set up the pipeline factory.
        ExecutionHandler executionHandler =
                new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor( 16, 1048576, 1048576 ) );
        // TODO if config'ed for SSL, start the SslMSPF instead, change port as well?
        bootstrap.setPipelineFactory(
                new MongoServerPipelineFactory( emf, smf, management, securityManager, executionHandler ) );

        // Bind and start to accept incoming connections.
        channel = bootstrap.bind( new InetSocketAddress( 27017 ) );

        logger.info( "Usergrid Mongo API Emulation Server accepting connections..." );
    }
 
Example #6
Source File: WebSocketServer.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public void startServer() {
    if ( ( properties != null ) && ( Boolean
            .parseBoolean( properties.getProperty( "usergrid.websocket.disable", "false" ) ) ) ) {
        logger.info( "Usergrid WebSocket Server Disabled" );
        return;
    }

    logger.info( "Starting Usergrid WebSocket Server" );

    if ( realm != null ) {
        securityManager = new DefaultSecurityManager( realm );
    }

    ServerBootstrap bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool() ) );

    // Set up the pipeline factory.
    ExecutionHandler executionHandler =
            new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor( 16, 1048576, 1048576 ) );

    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(
            new WebSocketServerPipelineFactory( emf, smf, management, securityManager, executionHandler, ssl ) );

    // Bind and start to accept incoming connections.
    channel = bootstrap.bind( new InetSocketAddress( 8088 ) );

    logger.info( "Usergrid WebSocket Server started..." );
}
 
Example #7
Source File: WebSocketServerPipelineFactory.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public WebSocketServerPipelineFactory( EntityManagerFactory emf, ServiceManagerFactory smf,
                                       ManagementService management, SessionsSecurityManager securityManager,
                                       ExecutionHandler executionHandler, boolean ssl ) {
    this.emf = emf;
    this.smf = smf;
    this.management = management;
    this.securityManager = securityManager;
    this.executionHandler = executionHandler;
    this.ssl = ssl;
}
 
Example #8
Source File: AbstractChannelPipelineFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp, ChannelGroup channels,
                                      ExecutionHandler eHandler, ChannelHandlerFactory frameHandlerFactory,
                                      HashedWheelTimer hashedWheelTimer) {
    this.connectionLimitHandler = new ConnectionLimitUpstreamHandler(maxConnections);
    this.connectionPerIpLimitHandler = new ConnectionPerIpLimitUpstreamHandler(maxConnectsPerIp);
    this.groupHandler = new ChannelGroupHandler(channels);
    this.timeout = timeout;
    this.eHandler = eHandler;
    this.frameHandlerFactory = frameHandlerFactory;
    this.timer = hashedWheelTimer;
}
 
Example #9
Source File: AbstractSSLAwareChannelPipelineFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
public AbstractSSLAwareChannelPipelineFactory(int timeout,
        int maxConnections, int maxConnectsPerIp, ChannelGroup group, String[] enabledCipherSuites, ExecutionHandler eHandler,
        ChannelHandlerFactory frameHandlerFactory, HashedWheelTimer hashedWheelTimer) {
    this(timeout, maxConnections, maxConnectsPerIp, group, eHandler, frameHandlerFactory, hashedWheelTimer);
    
    // We need to copy the String array because of possible security issues.
    // See https://issues.apache.org/jira/browse/PROTOCOLS-18
    this.enabledCipherSuites = ArrayUtils.clone(enabledCipherSuites);
}
 
Example #10
Source File: AbstractExecutorAwareChannelPipelineFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
public AbstractExecutorAwareChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp,
                                                   ChannelGroup group, String[] enabledCipherSuites,
                                                   ExecutionHandler eHandler, ChannelHandlerFactory frameHandlerFactory,
                                                   HashedWheelTimer hashedWheelTimer) {
    super(timeout, maxConnections, maxConnectsPerIp, group, enabledCipherSuites, eHandler, frameHandlerFactory, hashedWheelTimer);
}
 
Example #11
Source File: ManageSieveServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(final ChannelGroup group) {

    return new ChannelPipelineFactory() {

        private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group);

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            Encryption secure = getEncryption();
            if (secure != null && !secure.isStartTLS()) {
                // We need to set clientMode to false.
                // See https://issues.apache.org/jira/browse/JAMES-1025
                SSLEngine engine = secure.getContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));

            }
            pipeline.addLast(GROUP_HANDLER, groupHandler);
            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(ManageSieveServer.this.connectionLimit));
            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(ManageSieveServer.this.connPerIP));
            // Add the text line decoder which limit the max line length,
            // don't strip the delimiter and use CRLF as delimiter
            // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
            pipeline.addLast(FRAMER, getFrameHandlerFactory().create(pipeline));
            pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());
            pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());

            ExecutionHandler ehandler = getExecutionHandler();
            if (ehandler  != null) {
                pipeline.addLast(EXECUTION_HANDLER, ehandler);

            }
            pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
            pipeline.addLast(CORE_HANDLER, createCoreHandler());
            pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
            return pipeline;
        }

    };
}
 
Example #12
Source File: IMAPServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(final ChannelGroup group) {
    
    return new ChannelPipelineFactory() {
        
        private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group);
        private final HashedWheelTimer timer = new HashedWheelTimer();
        
        private final TimeUnit timeoutUnit = TimeUnit.SECONDS;

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast(GROUP_HANDLER, groupHandler);
            pipeline.addLast("idleHandler", new IdleStateHandler(timer, 0, 0, timeout, timeoutUnit));
            pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler());
            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(IMAPServer.this.connectionLimit));

            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(IMAPServer.this.connPerIP));

            // Add the text line decoder which limit the max line length,
            // don't strip the delimiter and use CRLF as delimiter
            // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
            pipeline.addLast(FRAMER, getFrameHandlerFactory().create(pipeline));
           
            Encryption secure = getEncryption();
            if (secure != null && !secure.isStartTLS()) {
                // We need to set clientMode to false.
                // See https://issues.apache.org/jira/browse/JAMES-1025
                SSLEngine engine = secure.getContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));

            }
            pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());

            pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());

            ExecutionHandler ehandler = getExecutionHandler();
            if (ehandler  != null) {
                pipeline.addLast(EXECUTION_HANDLER, ehandler);

            }
            pipeline.addLast(REQUEST_DECODER, new ImapRequestFrameDecoder(decoder, inMemorySizeLimit, literalSizeLimit));

            pipeline.addLast(CORE_HANDLER, createCoreHandler());
            return pipeline;
        }

    };
}
 
Example #13
Source File: OioIMAPServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
/**
 * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
 */
@Override
protected ExecutionHandler createExecutionHander() {
    return null;
}
 
Example #14
Source File: OioLMTPServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
/**
 * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
 * 
 */
@Override
protected ExecutionHandler createExecutionHander() {
    return null;
}
 
Example #15
Source File: OioSMTPServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
/**
 * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
 */
@Override
protected ExecutionHandler createExecutionHander() {
    return null;
}
 
Example #16
Source File: OioPOP3Server.java    From james-project with Apache License 2.0 4 votes vote down vote up
/**
 * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
 */
@Override
protected ExecutionHandler createExecutionHander() {
    return null;
}
 
Example #17
Source File: AbstractSSLAwareChannelPipelineFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
public AbstractSSLAwareChannelPipelineFactory(int timeout,
                                              int maxConnections, int maxConnectsPerIp, ChannelGroup group, ExecutionHandler eHandler,
                                              ChannelHandlerFactory frameHandlerFactory, HashedWheelTimer hashedWheelTimer) {
    super(timeout, maxConnections, maxConnectsPerIp, group, eHandler, frameHandlerFactory, hashedWheelTimer);
}
 
Example #18
Source File: LoginToClientPipeLineFactory.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
public LoginToClientPipeLineFactory(ClientPacketHandler clientPacketHandler) {
    this.clientPacketHandler = clientPacketHandler;
    this.executionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(THREADS_MAX, MEMORY_PER_CHANNEL, TOTAL_MEMORY, TIMEOUT, TimeUnit.MILLISECONDS, Executors.defaultThreadFactory()));
}
 
Example #19
Source File: AbstractConfigurableAsyncServer.java    From james-project with Apache License 2.0 2 votes vote down vote up
/**
 * 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"));
}
 
Example #20
Source File: AbstractConfigurableAsyncServer.java    From james-project with Apache License 2.0 2 votes vote down vote up
/**
 * Return the {@link ExecutionHandler} or null if non should be used. Be sure you call {@link #createExecutionHander()} before
 * 
 * @return ehandler
 */
protected ExecutionHandler getExecutionHandler() {
    return executionHandler;
}