All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.jasmine.zookeeper.ZooKeeperLauncher Maven / Gradle / Ivy

There is a newer version: 1.0.36
Show newest version
/**
 * JASMINe
 * Copyright (C) 2010 Bull S.A.S.
 * Contact: [email protected]
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: ZooKeeperLauncher.java 5575 2010-09-23 11:33:18Z veyjul $
 * --------------------------------------------------------------------------
 */
package org.ow2.jasmine.zookeeper;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.ow2.jonas.lib.bootstrap.JProp;

/**
 * Zookeeper launcher. Start the server when the bundle is valid, stop it when it's invalid.
 * 
 * @author veyj
 */
public class ZooKeeperLauncher implements BundleActivator {

    /**
     * jasmine agent properties file name
     */
    public static final String AGENT_CONFIGURATION_PROPERTIES_FILE_NAME = "jasmine-agent.properties";

    /**
     * zookeeper port property
     */
    public static final String ZOOKEEPER_PORT_PROPERTY = "zookeeper.port";

    /**
     * zookeeper snapshot directory
     */

    public static final String ZOOKEEPER_SNAPSHOT_DIRECTORY_PROPERTY = "zookeeper.snapshot";

    /**
     * a Zookeeper instance
     */
    private ZooKeeper zoo;

    /**
     * get the zookeeper server configuration
     * @return the configuration of the zookeeper server
     */
    public String[] getZooKeeperConfiguration() {
        String[] config = new String[2];
        JProp prop = JProp.getInstance(AGENT_CONFIGURATION_PROPERTIES_FILE_NAME);
        config[0] = prop.getValue(ZOOKEEPER_PORT_PROPERTY);
        config[1] = prop.getValue(ZOOKEEPER_SNAPSHOT_DIRECTORY_PROPERTY);
        return config;
    }

    /**
     * Get the zookeeper configuration from the property file
     * and start the zookeeper instance.
     */
    public void start(BundleContext arg0) throws Exception {
        String[] config = getZooKeeperConfiguration();
        zoo = new ZooKeeper(config[0], config[1]);
        zoo.startup();		
    }

    /**
     * Stop the zookeper instance.
     */
    public void stop(BundleContext arg0) throws Exception {
        zoo.shutdown();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy