예제 #1
0
        /// <summary>Startup: start ZK.</summary>
        /// <remarks>
        /// Startup: start ZK. It is only after this that
        /// the binding information is valid.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        protected override void ServiceStart()
        {
            SetupSecurity();
            ZooKeeperServer zkServer = new ZooKeeperServer();
            FileTxnSnapLog  ftxn     = new FileTxnSnapLog(dataDir, dataDir);

            zkServer.SetTxnLogFactory(ftxn);
            zkServer.SetTickTime(tickTime);
            Log.Info("Starting Local Zookeeper service");
            factory = ServerCnxnFactory.CreateFactory();
            factory.Configure(GetAddress(port), -1);
            factory.Startup(zkServer);
            string connectString = GetConnectionString();

            Log.Info("In memory ZK started at {}\n", connectString);
            if (Log.IsDebugEnabled())
            {
                StringWriter sw = new StringWriter();
                PrintWriter  pw = new PrintWriter(sw);
                zkServer.DumpConf(pw);
                pw.Flush();
                Log.Debug(sw.ToString());
            }
            binding = new BindingInformation();
            binding.ensembleProvider = new FixedEnsembleProvider(connectString);
            binding.description      = GetName() + " reachable at \"" + connectString + "\"";
            AddDiagnostics(binding.description);
            // finally: set the binding information in the config
            GetConfig().Set(KeyRegistryZkQuorum, connectString);
        }
예제 #2
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        internal static ServerCnxnFactory CreateNewServerInstance(FilePath dataDir, ServerCnxnFactory
                                                                  factory, string hostPort, int maxCnxns)
        {
            ZooKeeperServer zks  = new ZooKeeperServer(dataDir, dataDir, 3000);
            int             Port = GetPort(hostPort);

            if (factory == null)
            {
                factory = ServerCnxnFactory.CreateFactory(Port, maxCnxns);
            }
            factory.Startup(zks);
            Assert.True("waiting for server up", ClientBaseWithFixes.WaitForServerUp
                            ("127.0.0.1:" + Port, ConnectionTimeout));
            return(factory);
        }