本文整理汇总了Java中org.apache.zookeeper.server.ServerConfig类的典型用法代码示例。如果您正苦于以下问题:Java ServerConfig类的具体用法?Java ServerConfig怎么用?Java ServerConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerConfig类属于org.apache.zookeeper.server包,在下文中一共展示了ServerConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startZookeeper
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
private void startZookeeper() throws IOException, InterruptedException {
File zkDir = folder.mkSubDir("embedded-zk-" + zookeeperPort);
ServerConfig config = new ServerConfig();
config.parse(new String[]{String.valueOf(zookeeperPort), zkDir.getAbsolutePath()});
zookeeperThread = new Thread(() -> {
try {
zookeeperServer.runFromConfig(config);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
zookeeperThread.setDaemon(true);
zookeeperThread.start();
// Await zookeeper startup.
zookeeperThread.join(ZOOKEEPER_AWAIT_TIME);
}
示例2: startZkLocal
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
private static void startZkLocal() throws Exception {
final File zkTmpDir = File.createTempFile("zookeeper", "test");
if (zkTmpDir.delete() && zkTmpDir.mkdir()) {
Properties zkProperties = new Properties();
zkProperties.setProperty("dataDir", zkTmpDir.getAbsolutePath());
zkProperties.setProperty("clientPort", String.valueOf(ZK_PORT));
ServerConfig configuration = new ServerConfig();
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
quorumConfiguration.parseProperties(zkProperties);
configuration.readFrom(quorumConfiguration);
new Thread() {
public void run() {
try {
new ZooKeeperServerMain().runFromConfig(configuration);
} catch (IOException e) {
System.out.println("Start of Local ZooKeeper Failed");
e.printStackTrace(System.err);
}
}
}.start();
} else {
System.out.println("Failed to delete or create data dir for Zookeeper");
}
}
示例3: createZooKeeperConf
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
private static ServerConfig createZooKeeperConf()
throws IOException, ConfigException {
// create conf file
File zkConfDir = new File(TEST_DIR);
zkConfDir.mkdirs();
File zkConfFile = new File(ZK_CONF_FILE);
zkConfFile.delete();
zkConfFile.createNewFile();
Properties zkConfProps = new Properties();
zkConfProps.setProperty("tickTime", "2000");
zkConfProps.setProperty("dataDir", ZK_DATA_DIR);
zkConfProps.setProperty("clientPort", new Integer(zkClientPort).toString());
zkConfProps.setProperty("maxClientCnxns", "500");
zkConfProps.store(new FileOutputStream(zkConfFile), "");
// create config object
ServerConfig zkConf = new ServerConfig();
zkConf.parse(ZK_CONF_FILE);
return zkConf;
}
示例4: createAndStartZooKeeper
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
public static void createAndStartZooKeeper()
throws IOException, ConfigException, InterruptedException {
logStateChange("Creating zookeeper server");
AvatarShell.retrySleep = 1000;
ServerConfig zkConf = createZooKeeperConf();
zooKeeper = new ZooKeeperServer();
FileTxnSnapLog ftxn = new
FileTxnSnapLog(new File(zkConf.getDataLogDir()),
new File(zkConf.getDataDir()));
zooKeeper.setTxnLogFactory(ftxn);
zooKeeper.setTickTime(zkConf.getTickTime());
zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());
cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(zkConf.getClientPortAddress(),
zkConf.getMaxClientCnxns());
cnxnFactory.startup(zooKeeper);
logStateChange("Creating zookeeper server - completed");
}
示例5: setUp
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
final String clientPort = "21818";
final String dataDirectory = System.getProperty("java.io.tmpdir");
zookeeperHost = "localhost:" + clientPort;
ServerConfig config = new ServerConfig();
config.parse(new String[] { clientPort, dataDirectory });
testConfig = new BaseConfiguration();
testConfig.setProperty("quorum", zookeeperHost);
testConfig.setProperty("znode", "/config");
testConfig.setProperty(APPNAME_PROPERTY, "test");
testConfig.setProperty(ROOTCONFIG_PROPERTY, "test");
zkServer = new ZookeeperTestUtil.ZooKeeperThread(config);
server = new Thread(zkServer);
server.start();
zookeeper = connect(zookeeperHost);
}
示例6: runFromConfig
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
private void runFromConfig(ServerConfig config) throws IOException {
zkServer = new ZooKeeperServer();
try {
txnLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir()));
zkServer.setTxnLogFactory(txnLog);
zkServer.setTickTime(config.getTickTime());
zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(),
config.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
} catch (InterruptedException e) {
if (zkServer.isRunning()) {
zkServer.shutdown();
}
}
}
示例7: startZookeeperServer
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
/**
* 启动zookeeper服务
*/
public static void startZookeeperServer()
throws ConfigException, IOException
{
String classPath = ApplicationParseTest.class.getResource("/").getPath();
String[] args = {classPath + File.separator + "zoo.cfg"};
ServerConfig config = new ServerConfig();
if (args.length == 1)
{
config.parse(args[0]);
}
else
{
config.parse(args);
}
LOG.info("start to startup zookeeper server");
runFromConfig(config);
}
示例8: initializeAndRun
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
protected void initializeAndRun(String[] args) throws ConfigException,
IOException {
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
log.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);
} else {
config.parse(args);
}
runFromConfig(config);
}
示例9: createZooKeeperConf
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
private static ServerConfig createZooKeeperConf()
throws IOException, ConfigException {
// create conf file
File zkConfDir = new File(TEST_DIR);
zkConfDir.mkdirs();
File zkConfFile = new File(ZK_CONF_FILE);
zkConfFile.delete();
zkConfFile.createNewFile();
Properties zkConfProps = new Properties();
zkConfProps.setProperty("tickTime", "2000");
zkConfProps.setProperty("dataDir", ZK_DATA_DIR);
zkConfProps.setProperty("clientPort", new Integer(zkClientPort).toString());
zkConfProps.setProperty("maxClientCnxns", "30");
zkConfProps.store(new FileOutputStream(zkConfFile), "");
// create config object
ServerConfig zkConf = new ServerConfig();
zkConf.parse(ZK_CONF_FILE);
return zkConf;
}
示例10: createAndStartZooKeeper
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
public static void createAndStartZooKeeper()
throws IOException, ConfigException, InterruptedException {
ServerConfig zkConf = createZooKeeperConf();
zooKeeper = new ZooKeeperServer();
FileTxnSnapLog ftxn = new
FileTxnSnapLog(new File(zkConf.getDataLogDir()),
new File(zkConf.getDataDir()));
zooKeeper.setTxnLogFactory(ftxn);
zooKeeper.setTickTime(zkConf.getTickTime());
zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());
cnxnFactory =
new NIOServerCnxn.Factory(zkConf.getClientPortAddress(),
zkConf.getMaxClientCnxns());
cnxnFactory.startup(zooKeeper);
}
示例11: runZKServer
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
if (zkConfig.isDistributed()) {
QuorumPeerMain qp = new QuorumPeerMain();
qp.runFromConfig(zkConfig);
} else {
ZooKeeperServerMain zk = new ZooKeeperServerMain();
ServerConfig serverConfig = new ServerConfig();
serverConfig.readFrom(zkConfig);
zk.runFromConfig(serverConfig);
}
}
示例12: start
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
public void start() throws Exception {
try {
// zkDir = genZookeeperDataDir();
zkConfig = genZookeeperConfig(zkDir);
port = Integer.valueOf(zkConfig.getProperty("clientPort"));
QuorumPeerConfig qpConfig = new QuorumPeerConfig();
qpConfig.parseProperties(zkConfig);
final ServerConfig sConfig = new ServerConfig();
sConfig.readFrom(qpConfig);
thread = new Thread() {
@Override
public void run() {
try {
LOGGER.info("Starting ZK server");
runFromConfig(sConfig);
} catch (Throwable t) {
LOGGER.error("Failure in embedded ZooKeeper", t);
}
}
};
thread.start();
Thread.sleep(500);
} catch (Throwable t) {
throw new Exception("Cannot start embedded zookeeper", t);
}
}
示例13: start
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
public void start() throws IOException, ConfigException, InterruptedException {
log.info("Starting Zookeeper on port {}", port);
Properties properties = new Properties();
properties.setProperty("dataDir", getDataDir().getAbsolutePath());
properties.setProperty("clientPort", Integer.toString(getPort()));
QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
quorumConfig.parseProperties(properties);
cleanupManager = new DatadirCleanupManager(quorumConfig.getDataDir(), quorumConfig.getDataLogDir(),
quorumConfig.getSnapRetainCount(), quorumConfig.getPurgeInterval());
cleanupManager.start();
ServerConfig serverConfig = new ServerConfig();
serverConfig.readFrom(quorumConfig);
zkServer = new ZooKeeperServer();
zkServer.setTickTime(serverConfig.getTickTime());
zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
transactionLog = new FileTxnSnapLog(new File(serverConfig.getDataLogDir().toString()),
new File(serverConfig.getDataDir().toString()));
zkServer.setTxnLogFactory(transactionLog);
connectionFactory = ServerCnxnFactory.createFactory();
connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
connectionFactory.startup(zkServer);
}
示例14: run
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
public void run() throws Exception {
pidFileLocker.lock();
server = new ZooKeeperServerMain();
QuorumPeerConfig qp = new QuorumPeerConfig();
qp.parseProperties(configuration);
ServerConfig sc = new ServerConfig();
sc.readFrom(qp);
server.runFromConfig(sc);
}
示例15: runFromConfig
import org.apache.zookeeper.server.ServerConfig; //导入依赖的package包/类
/**
* Run from a ServerConfig.
* @param config ServerConfig to use.
* @throws IOException on any error
*/
public void runFromConfig(ServerConfig config) throws IOException {
LOG.info(">>>>> Starting Test ZooKeep Server...");
FileTxnSnapLog txnLog = null;
try {
// Note that this thread isn't going to be doing anything else,
// so rather than spawning another thread, we will just call
// run() in this thread.
// create a file logger url from the command line args
zkServer = new ZooKeeperServer();
txnLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(
config.getDataDir()));
zkServer.setTxnLogFactory(txnLog);
zkServer.setTickTime(config.getTickTime());
zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(),
config.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
LOG.info("<<<<< Test ZooKeep Server Started.");
// cnxnFactory.join();
// if (zkServer.isRunning()) {
// zkServer.shutdown();
// }
} catch (InterruptedException e) {
// warn, but generally this is ok
LOG.warn("Server interrupted", e);
} finally {
// if (txnLog != null) {
// txnLog.close();
// }
}
}