@Override public void run() { try { Properties properties = new Properties(); File file = new File(System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID()); file.deleteOnExit(); properties.setProperty("dataDir", file.getAbsolutePath()); properties.setProperty("clientPort", String.valueOf(clientPort)); QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); quorumPeerConfig.parseProperties(properties); zkServer = new ZooKeeperServerMain(); ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumPeerConfig); zkServer.runFromConfig(configuration); } catch (Exception e) { if (errorHandler != null) { errorHandler.handleError(e); } else { logger.error("Exception running embedded ZooKeeper", e); } } } }
private void startStandalone() throws IOException { logger.info("Starting Embedded ZooKeeper Server"); final ServerConfig config = new ServerConfig(); config.readFrom(quorumPeerConfig); try { transactionLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())); embeddedZkServer = new ZooKeeperServer(); embeddedZkServer.setTxnLogFactory(transactionLog); embeddedZkServer.setTickTime(config.getTickTime()); embeddedZkServer.setMinSessionTimeout(config.getMinSessionTimeout()); embeddedZkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); connectionFactory = ServerCnxnFactory.createFactory(); connectionFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); connectionFactory.startup(embeddedZkServer); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.warn("Embedded ZooKeeper Server interrupted", e); } catch (final IOException ioe) { throw new IOException("Failed to start embedded ZooKeeper Server", ioe); } catch (final Exception e) { throw new RuntimeException("Failed to start embedded ZooKeeper Server", e); } }
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServerException { 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); }
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(); } } }
public static ServerCnxnFactory startZookeeper(final String configResource, final String dataDirName) throws IOException, QuorumPeerConfig.ConfigException { ServerConfig sc = new ServerConfig(); sc.parse(pathToResource(configResource)); deleteDir(dataDirName); new File(dataDirName).mkdirs(); FileTxnSnapLog txnLog = null; try { ZooKeeperServer zkServer = new ZooKeeperServer(); txnLog = new FileTxnSnapLog(new File(sc.getDataDir()), new File( sc.getDataDir())); zkServer.setTxnLogFactory(txnLog); zkServer.setTickTime(sc.getTickTime()); zkServer.setMinSessionTimeout(sc.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(sc.getMaxSessionTimeout()); ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(sc.getClientPortAddress(), sc.getMaxClientCnxns()); cnxnFactory.startup(zkServer); return cnxnFactory; } catch (InterruptedException e) { throw new RuntimeException(e); } finally { if (txnLog != null) { txnLog.close(); } } }
ServerConfig config = new ServerConfig(); config.readFrom(qpc); this.connectionFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); try { this.connectionFactory.startup(zooKeeperServer);
Properties startupProperties = ... QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig(); try { quorumConfiguration.parseProperties(startupProperties); } catch(Exception e) { throw new RuntimeException(e); } zooKeeperServer = new ZooKeeperServerMain(); final ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumConfiguration); new Thread() { public void run() { try { zooKeeperServer.runFromConfig(configuration); } catch (IOException e) { log.error("ZooKeeper Failed", e); } } }.start();
public void readFrom(QuorumPeerConfig otherConfig) { config.readFrom(otherConfig); }
public void setupFromConfig() { try { txnLog = new FileTxnSnapLog(config.getDataLogDir(), config.getDataDir()); } catch (IOException e) { e.printStackTrace(); } zkServer = new ZooKeeperServer(txnLog, config.getTickTime(), config.getMinSessionTimeout(), config.getMaxSessionTimeout(), null); }
@Test public void testValidArguments() { String[] args = {"2181", "/data/dir", "60000", "10000"}; serverConfig.parse(args); assertEquals(2181, serverConfig.getClientPortAddress().getPort()); assertTrue(checkEquality("/data/dir", serverConfig.getDataDir())); assertEquals(60000, serverConfig.getTickTime()); assertEquals(10000, serverConfig.getMaxClientCnxns()); }
public class OrmConfig { ServerConfig config = new ServerConfig(); OrmConfig() { config.setName("mysql"); } }
ServerConfig saetrServerConfig = new ServerConfig(); saetrServerConfig.setName("distantdatabase"); saetrServerConfig.setDdlGenerate(false); // ddlGenerate drops all tables and create new tables saetrServerConfig.setDdlRun(false); // ddlRun run migration scripts saetrServerConfig.setDefaultServer(false); saetrServerConfig.setRegister(true); saetrServerConfig.setDataSourceConfig(ds); saetrServerConfig.setClasses(saetrClasses);
ServerConfig serverConfig = new ServerConfig(); serverConfig.setName("mydb"); // ddl.generate, ddl.createOnly and ddl.run should be set to true in // your ebean.properties file(if using one) else set them // programmatically serverConfig.loadFromProperties(); try { server = EbeanServerFactory.create(ebeanConfig); } catch(Exception e) { ebeanConfig.setDdlRun(false); server = EbeanServerFactory.create(ebeanConfig); }
zkServer.setMaxSessionTimeout(config.maxSessionTimeout); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer);
try { metricsProvider = MetricsProviderBootstrap .startMetricsProvider(config.getMetricsProviderClassName(), config.getMetricsProviderConfiguration()); } catch (MetricsProviderLifeCycleException error) { throw new IOException("Cannot boot MetricsProvider "+config.getMetricsProviderClassName(), error); if (config.getClientPortAddress() != null) { cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(), false); cnxnFactory.startup(zkServer); if (config.getSecureClientPortAddress() != null) { secureCnxnFactory = ServerCnxnFactory.createFactory(); secureCnxnFactory.configure(config.getSecureClientPortAddress(), config.getMaxClientCnxns(), true); secureCnxnFactory.startup(zkServer, needStartZKServer);
public void start() { // See ZooKeeperServerMain.runFromConfig LOG.info("Starting server"); boolean needStartZKServer = true; LogCtl.disable("org.apache.zookeeper.server.ZooKeeperServer"); // ZooKeeperServer logs an error because ZooKeeperServerShutdownHandler not set but that is not an accessible class. try { if (config.getClientPortAddress() != null) { cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(), false); cnxnFactory.startup(zkServer); // zkServer has been started. So we don't need to start it again in secureCnxnFactory. needStartZKServer = false; } if (config.getSecureClientPortAddress() != null) { secureCnxnFactory = ServerCnxnFactory.createFactory(); secureCnxnFactory.configure(config.getSecureClientPortAddress(), config.getMaxClientCnxns(), true); secureCnxnFactory.startup(zkServer, needStartZKServer); } if ( needStartZKServer ) zkServer.startup(); } catch (IOException e) { throw new RuntimeIOException(e); } catch (InterruptedException e) { // Note from ZookeeperServerMain: "warn, but generally this is ok" LOG.warn("Server interrupted", e); } finally { LogCtl.setLevel("org.apache.zookeeper.server.ZooKeeperServer", "WARN"); } }
public InetSocketAddress getClientPortAddress() { return config.getClientPortAddress(); }
public String getDataDir() { return config.getDataDir(); }
public int getTickTime() { return config.getTickTime(); }
newServerConfig.getMaxClientCnxns();