Search in sources :

Example 1 with ServerSocketChannelConfig

use of org.jboss.netty.channel.socket.ServerSocketChannelConfig in project graylog2-server by Graylog2.

the class NettyTransport method launch.

@Override
public void launch(final MessageInput input) throws MisfireException {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = getBaseChannelHandlers(input);
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalHandlers = getFinalChannelHandlers(input);
    handlerList.putAll(finalHandlers);
    try {
        bootstrap = getBootstrap();
        bootstrap.setPipelineFactory(getPipelineFactory(handlerList));
        // sigh, bindable bootstraps do not share a common interface
        int receiveBufferSize;
        if (bootstrap instanceof ConnectionlessBootstrap) {
            acceptChannel = ((ConnectionlessBootstrap) bootstrap).bind(socketAddress);
            final DefaultDatagramChannelConfig channelConfig = (DefaultDatagramChannelConfig) acceptChannel.getConfig();
            receiveBufferSize = channelConfig.getReceiveBufferSize();
        } else if (bootstrap instanceof ServerBootstrap) {
            acceptChannel = ((ServerBootstrap) bootstrap).bind(socketAddress);
            final ServerSocketChannelConfig channelConfig = (ServerSocketChannelConfig) acceptChannel.getConfig();
            receiveBufferSize = channelConfig.getReceiveBufferSize();
        } else {
            log.error("Unknown Netty bootstrap class returned: {}. Cannot safely bind.", bootstrap);
            throw new IllegalStateException("Unknown netty bootstrap class returned: " + bootstrap + ". Cannot safely bind.");
        }
        if (receiveBufferSize != getRecvBufferSize()) {
            log.warn("receiveBufferSize (SO_RCVBUF) for input {} should be {} but is {}.", input, getRecvBufferSize(), receiveBufferSize);
        }
    } catch (Exception e) {
        throw new MisfireException(e);
    }
}
Also used : MisfireException(org.graylog2.plugin.inputs.MisfireException) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) DefaultDatagramChannelConfig(org.jboss.netty.channel.socket.DefaultDatagramChannelConfig) ServerSocketChannelConfig(org.jboss.netty.channel.socket.ServerSocketChannelConfig) Callable(java.util.concurrent.Callable) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) MisfireException(org.graylog2.plugin.inputs.MisfireException) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Aggregations

Callable (java.util.concurrent.Callable)1 MisfireException (org.graylog2.plugin.inputs.MisfireException)1 ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 ChannelHandler (org.jboss.netty.channel.ChannelHandler)1 SimpleChannelHandler (org.jboss.netty.channel.SimpleChannelHandler)1 DefaultDatagramChannelConfig (org.jboss.netty.channel.socket.DefaultDatagramChannelConfig)1 ServerSocketChannelConfig (org.jboss.netty.channel.socket.ServerSocketChannelConfig)1