org.ow2.jasmine.zookeeper.ZooKeeperLauncher Maven / Gradle / Ivy
/**
* Copyright 2008-2012 Bull S.A.S.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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();
}
}