Search in sources :

Example 11 with Dempsy

use of com.nokia.dempsy.Dempsy in project Dempsy by Dempsy.

the class RunNode method run.

public static void run(String[] args) throws Throwable {
    //======================================================
    // Handle all of the options.
    String application = System.getProperty(applicationParam);
    if (application == null || application.length() == 0)
        usage("the java vm option \"-D" + applicationParam + "\" wasn't specified.");
    String[] clusterIdParts = application.split(":");
    if (clusterIdParts.length != 2)
        usage("invalid format for the -Dcluster option. It should be a clusterid of the form \"applicationName:clusterName.\"");
    System.setProperty("application", clusterIdParts[0]);
    System.setProperty("cluster", clusterIdParts[1]);
    String appCtxFilename = System.getProperty(appdefParam);
    if (appCtxFilename == null || appCtxFilename.length() == 0) {
        //         usage("the java vm option \"-D" + appdefParam + "\" wasn't specified.");
        appCtxFilename = "DempsyApplicationContext-" + clusterIdParts[0] + ".xml";
    }
    String zkConnect = System.getProperty(zk_connectParam);
    if (zkConnect == null || zkConnect.length() == 0)
        usage("the java vm option \"-D" + zk_connectParam + "\" wasn't specified.");
    String zkTimeout = System.getProperty(zk_timeoutParam);
    if (zkTimeout == null || zkTimeout.length() == 0)
        System.setProperty(zk_timeoutParam, zk_timeoutDefault);
    String totalSlots = System.getProperty(total_slots_per_clusterParam);
    if (totalSlots == null || totalSlots.length() == 0)
        System.setProperty(total_slots_per_clusterParam, total_slots_per_clusterDefault);
    String minNodes = System.getProperty(min_num_nodes_per_clusterParam);
    if (minNodes == null || minNodes.length() == 0)
        System.setProperty(min_num_nodes_per_clusterParam, min_num_nodes_per_clusterDefault);
    //======================================================
    String contextFile = "classpath:Dempsy-distributed.xml";
    ClassPathXmlApplicationContext context = null;
    try {
        // Initialize Spring
        context = new ClassPathXmlApplicationContext(new String[] { appCtxFilename, contextFile });
        context.registerShutdownHook();
    } catch (Throwable e) {
        logger.error(MarkerFactory.getMarker("FATAL"), "Failed to start the application ", e);
        throw e;
    }
    if (context != null) {
        try {
            context.getBean(Dempsy.class).waitToBeStopped();
        } catch (InterruptedException e) {
            logger.error("Interrupted . . . ", e);
        } finally {
            context.stop();
        }
        logger.info("Shut down dempsy appliction " + appCtxFilename + "-" + application + ", bye!");
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Dempsy(com.nokia.dempsy.Dempsy)

Aggregations

Dempsy (com.nokia.dempsy.Dempsy)11 Test (org.junit.Test)7 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)7 ClusterId (com.nokia.dempsy.config.ClusterId)6 Condition (com.nokia.dempsy.TestUtils.Condition)5 ClusterInfoSession (com.nokia.dempsy.cluster.ClusterInfoSession)5 ApplicationDefinition (com.nokia.dempsy.config.ApplicationDefinition)4 ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)3 MyMp (com.nokia.dempsy.cluster.zookeeper.FullApplication.MyMp)3 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 ClusterInfoSessionFactory (com.nokia.dempsy.cluster.ClusterInfoSessionFactory)2 ClusterDefinition (com.nokia.dempsy.config.ClusterDefinition)2 ClusterInfoWatcher (com.nokia.dempsy.cluster.ClusterInfoWatcher)1 LocalClusterSessionFactory (com.nokia.dempsy.cluster.invm.LocalClusterSessionFactory)1 MyRankMp (com.nokia.dempsy.cluster.zookeeper.FullApplication.MyRankMp)1 Destination (com.nokia.dempsy.messagetransport.Destination)1 TcpTransport (com.nokia.dempsy.messagetransport.tcp.TcpTransport)1 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)1 DecentralizedRoutingStrategy (com.nokia.dempsy.router.DecentralizedRoutingStrategy)1