Search in sources :

Example 1 with BalancerUrlRewriteFilter

use of org.mobicents.tools.http.urlrewriting.BalancerUrlRewriteFilter 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)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 ServletException (javax.servlet.ServletException)1 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)1 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)1 BalancerUrlRewriteFilter (org.mobicents.tools.http.urlrewriting.BalancerUrlRewriteFilter)1