Search in sources :

Example 26 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project load-balancer by RestComm.

the class HttpServer method start.

public void start() {
    executor = Executors.newCachedThreadPool();
    nioServerSocketChannelFactory = new NioServerSocketChannelFactory(executor, executor);
    serverBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    serverBootstrap.setPipelineFactory(new TestHttpServerPipelineFactory(true, requestCount, requests, chunkedresponse, badSever));
    serverChannel = serverBootstrap.bind(new InetSocketAddress("127.0.0.1", httpPort));
    serverSecureBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    serverSecureBootstrap.setPipelineFactory(new TestHttpServerPipelineFactory(false, requestCount, requests, chunkedresponse, badSever));
    serverSecureChannel = serverSecureBootstrap.bind(new InetSocketAddress("127.0.0.1", sslPort));
    // ping
    node = new Node("HttpServer", "127.0.0.1");
    node.getProperties().put("version", "0");
    node.getProperties().put("httpPort", "" + httpPort);
    node.getProperties().put("udpPort", "" + udpPort);
    node.getProperties().put("sslPort", "" + sslPort);
    node.getProperties().put(Protocol.SESSION_ID, "" + System.currentTimeMillis());
    node.getProperties().put(Protocol.HEARTBEAT_PORT, "" + heartbeatPort);
    if (instanceId != null)
        node.getProperties().put("Restcomm-Instance-Id", instanceId);
    clientController = new ClientController(this, lbAddress, lbPort, node, 5000, heartbeatPeriod, executor);
    clientController.startClient();
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) Node(org.mobicents.tools.heartbeat.api.Node) ClientController(org.mobicents.tools.heartbeat.impl.ClientController) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 27 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project load-balancer by RestComm.

the class Server method start.

@Override
public void start() {
    executor = Executors.newCachedThreadPool();
    nioServerSocketChannelFactory = new NioServerSocketChannelFactory(executor, executor);
    serverBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    serverBootstrap.setPipelineFactory(new ServerPipelineFactory(serverListener));
    serverChannel = serverBootstrap.bind(new InetSocketAddress(lbAddress, lbPort));
    logger.info("Heartbeat service started on " + lbAddress + ":" + lbPort + " (Load balancer's side)");
}
Also used : ServerPipelineFactory(org.mobicents.tools.heartbeat.server.ServerPipelineFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 28 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project load-balancer by RestComm.

the class HttpBalancerForwarder method start.

public void start() {
    executor = Executors.newCachedThreadPool();
    nioServerSocketChannelFactory = new NioServerSocketChannelFactory(executor, executor);
    nioClientSocketChannelFactory = new NioClientSocketChannelFactory(executor, executor);
    HttpChannelAssociations.serverBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    HttpChannelAssociations.serverSecureBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    HttpChannelAssociations.serverApiBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    HttpChannelAssociations.inboundBootstrap = new ClientBootstrap(nioClientSocketChannelFactory);
    HttpChannelAssociations.channels = new ConcurrentHashMap<AdvancedChannel, AdvancedChannel>();
    if (balancerRunner.getConfiguration().getHttpConfiguration().getUrlrewriteRule() != null) {
        HttpChannelAssociations.urlRewriteFilter = new BalancerUrlRewriteFilter();
        try {
            HttpChannelAssociations.urlRewriteFilter.init(balancerRunner);
        } catch (ServletException e) {
            throw new IllegalStateException("Can't init url filter due to [ " + e.getMessage() + " ] ", e);
        }
    }
    // https://telestax.atlassian.net/browse/LB-7 making the default port the same
    Integer httpPort = 2080;
    if (balancerRunner.balancerContext.lbConfig != null)
        httpPort = balancerRunner.balancerContext.lbConfig.getHttpConfiguration().getHttpPort();
    logger.info("HTTP LB listening on port " + httpPort);
    HttpChannelAssociations.serverBootstrap.setPipelineFactory(new HttpServerPipelineFactory(balancerRunner, false));
    HttpChannelAssociations.serverBootstrap.setOption("child.tcpNoDelay", true);
    HttpChannelAssociations.serverBootstrap.setOption("child.keepAlive", true);
    serverChannel = HttpChannelAssociations.serverBootstrap.bind(new InetSocketAddress(httpPort));
    Integer httpsPort = balancerRunner.balancerContext.lbConfig.getHttpConfiguration().getHttpsPort();
    if (httpsPort != null) {
        logger.info("HTTPS LB listening on port " + httpsPort);
        HttpChannelAssociations.serverSecureBootstrap.setPipelineFactory(new HttpServerPipelineFactory(balancerRunner, true));
        serverSecureChannel = HttpChannelAssociations.serverSecureBootstrap.bind(new InetSocketAddress(httpsPort));
        if (!balancerRunner.balancerContext.terminateTLSTraffic) {
            HttpChannelAssociations.inboundSecureBootstrap = new ClientBootstrap(nioClientSocketChannelFactory);
            HttpChannelAssociations.inboundSecureBootstrap.setPipelineFactory(new HttpClientPipelineFactory(balancerRunner, true));
            HttpChannelAssociations.inboundSecureBootstrap.setOption("child.tcpNoDelay", true);
            HttpChannelAssociations.inboundSecureBootstrap.setOption("child.keepAlive", true);
        }
    }
    Integer apiPort = balancerRunner.balancerContext.lbConfig.getCommonConfiguration().getStatisticPort();
    if (apiPort != null) {
        logger.info("Load balancer API port : " + apiPort);
        HttpChannelAssociations.serverApiBootstrap.setPipelineFactory(new HttpServerPipelineFactory(balancerRunner, false));
        HttpChannelAssociations.serverApiChannel = HttpChannelAssociations.serverApiBootstrap.bind(new InetSocketAddress(apiPort));
    }
    HttpChannelAssociations.inboundBootstrap.setPipelineFactory(new HttpClientPipelineFactory(balancerRunner, false));
}
Also used : NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ServletException(javax.servlet.ServletException) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) BalancerUrlRewriteFilter(org.mobicents.tools.http.urlrewriting.BalancerUrlRewriteFilter)

Example 29 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project traccar by tananaev.

the class TrackerServer method start.

public void start() {
    InetSocketAddress endpoint;
    if (address == null) {
        endpoint = new InetSocketAddress(port);
    } else {
        endpoint = new InetSocketAddress(address, port);
    }
    Channel channel = null;
    if (bootstrap instanceof ServerBootstrap) {
        channel = ((ServerBootstrap) bootstrap).bind(endpoint);
    } else if (bootstrap instanceof ConnectionlessBootstrap) {
        channel = ((ConnectionlessBootstrap) bootstrap).bind(endpoint);
    }
    if (channel != null) {
        getChannelGroup().add(channel);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 30 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project traccar by tananaev.

the class AdmProtocol method initTrackerServers.

@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 1, -3, 0));
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new AdmProtocolEncoder());
            pipeline.addLast("objectDecoder", new AdmProtocolDecoder(AdmProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
Also used : StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) TrackerServer(org.traccar.TrackerServer) LengthFieldBasedFrameDecoder(org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)94 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)58 TrackerServer (org.traccar.TrackerServer)42 InetSocketAddress (java.net.InetSocketAddress)38 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)34 ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)25 StringEncoder (org.jboss.netty.handler.codec.string.StringEncoder)16 Channel (org.jboss.netty.channel.Channel)13 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)12 StringDecoder (org.jboss.netty.handler.codec.string.StringDecoder)12 LengthFieldBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder)11 ChannelFactory (org.jboss.netty.channel.ChannelFactory)8 ExecutorService (java.util.concurrent.ExecutorService)5 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)5 Test (org.junit.Test)5 HostnamePort (org.neo4j.helpers.HostnamePort)5 CharacterDelimiterFrameDecoder (org.traccar.CharacterDelimiterFrameDecoder)5 IOException (java.io.IOException)4 ChannelException (org.jboss.netty.channel.ChannelException)4 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)4