Search in sources :

Example 1 with SmppBalancerRunner

use of org.mobicents.tools.smpp.balancer.core.SmppBalancerRunner in project load-balancer by RestComm.

the class SipBalancerShutdownHook method start.

public void start(LoadBalancerConfiguration lbConfig) {
    if (statsReporter == null)
        statsReporter = new RestcommStatsReporter();
    String ipAddress = lbConfig.getCommonConfiguration().getHost();
    if (ipAddress == null) {
        ipAddress = lbConfig.getSipConfiguration().getInternalLegConfiguration().getHost();
    }
    if (ipAddress == null) {
        ipAddress = lbConfig.getSipConfiguration().getExternalLegConfiguration().getHost();
    }
    InetAddress addr = null;
    try {
        addr = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        logger.error("Couldn't get the InetAddress from the host " + ipAddress, e);
        return;
    }
    balancerContext.securityRequired = lbConfig.getCommonConfiguration().getSecurityRequired();
    if (balancerContext.securityRequired) {
        balancerContext.login = lbConfig.getCommonConfiguration().getLogin();
        balancerContext.password = lbConfig.getCommonConfiguration().getPassword();
    }
    balancerContext.algorithmClassName = lbConfig.getSipConfiguration().getAlgorithmConfiguration().getAlgorithmClass();
    balancerContext.terminateTLSTraffic = lbConfig.getSslConfiguration().getTerminateTLSTraffic();
    balancerContext.smppToProviderAlgorithmClassName = lbConfig.getSmppConfiguration().getSmppToProviderAlgorithmClass();
    if (lbConfig.getSmppConfiguration().isMuxMode())
        balancerContext.smppToNodeAlgorithmClassName = lbConfig.getSmppConfiguration().getSmppToNodeAlgorithmClass();
    balancerContext.shutdownTimeout = lbConfig.getCommonConfiguration().getShutdownTimeout();
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        RouterImpl.setRegister(reg);
        reg = new NodeRegisterImpl(addr);
        reg.balancerRunner = this;
        reg.setNodeExpirationTaskInterval(lbConfig.getCommonConfiguration().getHeartbeatInterval());
        reg.setNodeExpiration(lbConfig.getCommonConfiguration().getNodeTimeout());
        if (logger.isInfoEnabled()) {
            logger.info("Node timeout" + " = " + reg.getNodeExpiration());
            logger.info("Heartbeat interval" + " = " + reg.getNodeExpirationTaskInterval());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("LB will use next class for registry nodes : " + lbConfig.getHeartbeatConfigurationClass());
        }
        HeartbeatConfig heartbeatConfig = lbConfig.getHeartbeatConfiguration();
        if (heartbeatConfig == null) {
            logger.warn("Configuration of heartbeat is not set, we will use http heartbeat protocol default values");
            heartbeatConfig = new HeartbeatConfigHttp();
        }
        balancerContext.nodeCommunicationProtocolClassName = heartbeatConfig.getProtocolClassName();
        reg.startRegistry(heartbeatConfig);
        if (logger.isDebugEnabled()) {
            logger.debug("adding shutdown hook");
        }
        String statisticsServer = Version.getVersionProperty(STATISTICS_SERVER);
        if (statisticsServer == null || !statisticsServer.contains("http")) {
            statisticsServer = DEFAULT_STATISTICS_SERVER;
        }
        // define remote server address (optionally)
        statsReporter.setRemoteServer(statisticsServer);
        String projectName = System.getProperty("RestcommProjectName", "loadbalancer");
        String projectType = System.getProperty("RestcommProjectType", "community");
        String projectVersion = System.getProperty("RestcommProjectVersion", Version.getVersionProperty(Version.RELEASE_VERSION));
        if (logger.isDebugEnabled()) {
            logger.debug("Restcomm Stats " + projectName + " " + projectType + " " + projectVersion);
        }
        statsReporter.setProjectName(projectName);
        statsReporter.setProjectType(projectType);
        statsReporter.setVersion(projectVersion);
        // define periodicy - default to once a day
        statsReporter.start(86400, TimeUnit.SECONDS);
        Version.printVersion();
        sipForwarder = new SIPBalancerForwarder(lbConfig, this, reg);
        sipForwarder.start();
        if (lbConfig.getHttpConfiguration().getHttpPort() != null) {
            httpBalancerForwarder = new HttpBalancerForwarder();
            httpBalancerForwarder.balancerRunner = this;
            try {
                httpBalancerForwarder.start();
            } catch (org.jboss.netty.channel.ChannelException e) {
                logger.warn("HTTP forwarder could not be restarted.");
            }
        }
        // register the sip balancer
        ObjectName on = new ObjectName(SIP_BALANCER_JMX_NAME);
        if (server.isRegistered(on)) {
            server.unregisterMBean(on);
        }
        server.registerMBean(this, on);
        shutdownHook = new SipBalancerShutdownHook(this);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
    } catch (Exception e) {
        logger.error("An unexpected error occurred while starting the load balancer", e);
        return;
    }
    if (lbConfig.getSmppConfiguration().getSmppPort() != null) {
        smppBalancerRunner = new SmppBalancerRunner(this);
        smppBalancerRunner.start();
    }
}
Also used : HeartbeatConfig(org.mobicents.tools.heartbeat.api.HeartbeatConfig) HttpBalancerForwarder(org.mobicents.tools.http.balancer.HttpBalancerForwarder) UnknownHostException(java.net.UnknownHostException) UnknownHostException(java.net.UnknownHostException) ObjectName(javax.management.ObjectName) SmppBalancerRunner(org.mobicents.tools.smpp.balancer.core.SmppBalancerRunner) RestcommStatsReporter(org.restcomm.commons.statistics.reporter.RestcommStatsReporter) HeartbeatConfigHttp(org.mobicents.tools.heartbeat.impl.HeartbeatConfigHttp) InetAddress(java.net.InetAddress) MBeanServer(javax.management.MBeanServer)

Aggregations

InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 HeartbeatConfig (org.mobicents.tools.heartbeat.api.HeartbeatConfig)1 HeartbeatConfigHttp (org.mobicents.tools.heartbeat.impl.HeartbeatConfigHttp)1 HttpBalancerForwarder (org.mobicents.tools.http.balancer.HttpBalancerForwarder)1 SmppBalancerRunner (org.mobicents.tools.smpp.balancer.core.SmppBalancerRunner)1 RestcommStatsReporter (org.restcomm.commons.statistics.reporter.RestcommStatsReporter)1