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

The following examples show how to use org.jboss.netty.handler.execution.ExecutionHandler. These examples are extracted from open source projects. 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
@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 2
Source Project: recipes-rss   Source File: NettyServer.java    License: 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 3
Source Project: Android-Airplay-Server   Source File: AirPlayServer.java    License: 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
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 5
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 6
Source Project: usergrid   Source File: WebSocketServerPipelineFactory.java    License: 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 7
Source Project: usergrid   Source File: WebSocketServer.java    License: 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 8
Source Project: usergrid   Source File: MongoServer.java    License: 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 9
Source Project: usergrid   Source File: MongoServerPipelineFactory.java    License: 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 10
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 11
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 12
Source Project: james-project   Source File: OioPOP3Server.java    License: 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 13
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 14
Source Project: james-project   Source File: ManageSieveServer.java    License: 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 15
Source Project: james-project   Source File: IMAPServer.java    License: 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 16
Source Project: james-project   Source File: OioIMAPServer.java    License: 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 Project: james-project   Source File: OioLMTPServer.java    License: 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 18
Source Project: james-project   Source File: OioSMTPServer.java    License: 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 19
/**
 * 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
/**
 * 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;
}