Class ZooKeeperServer

    • Field Detail

      • LOG

        protected static final org.slf4j.Logger LOG
      • tickTime

        protected int tickTime
      • minSessionTimeout

        protected int minSessionTimeout
        value of -1 indicates unset, use default
      • maxSessionTimeout

        protected int maxSessionTimeout
        value of -1 indicates unset, use default
      • ok

        public static final java.lang.Exception ok
    • Constructor Detail

      • ZooKeeperServer

        public ZooKeeperServer()
        Creates a ZooKeeperServer instance. Nothing is setup, use the setX methods to prepare the instance (eg datadir, datalogdir, ticktime, builder, etc...)
        Throws:
        java.io.IOException
      • ZooKeeperServer

        public ZooKeeperServer​(FileTxnSnapLog txnLogFactory,
                               int tickTime,
                               int minSessionTimeout,
                               int maxSessionTimeout,
                               ZooKeeperServer.DataTreeBuilder treeBuilder,
                               ZKDatabase zkDb)
        Creates a ZooKeeperServer instance. It sets everything up, but doesn't actually start listening for clients until run() is invoked.
        Parameters:
        dataDir - the directory to put the data
      • ZooKeeperServer

        public ZooKeeperServer​(FileTxnSnapLog txnLogFactory,
                               int tickTime,
                               ZooKeeperServer.DataTreeBuilder treeBuilder)
                        throws java.io.IOException
        creates a zookeeperserver instance.
        Parameters:
        txnLogFactory - the file transaction snapshot logging class
        tickTime - the ticktime for the server
        treeBuilder - the datatree builder
        Throws:
        java.io.IOException
      • ZooKeeperServer

        public ZooKeeperServer​(java.io.File snapDir,
                               java.io.File logDir,
                               int tickTime)
                        throws java.io.IOException
        This constructor is for backward compatibility with the existing unit test code. It defaults to FileLogProvider persistence provider.
        Throws:
        java.io.IOException
      • ZooKeeperServer

        public ZooKeeperServer​(FileTxnSnapLog txnLogFactory,
                               ZooKeeperServer.DataTreeBuilder treeBuilder)
                        throws java.io.IOException
        Default constructor, relies on the config for its agrument values
        Throws:
        java.io.IOException
    • Method Detail

      • dumpConf

        public void dumpConf​(java.io.PrintWriter pwriter)
      • getZKDatabase

        public ZKDatabase getZKDatabase()
        get the zookeeper database for this server
        Returns:
        the zookeeper database for this server
      • setZKDatabase

        public void setZKDatabase​(ZKDatabase zkDb)
        set the zkdatabase for this zookeeper server
        Parameters:
        zkDb -
      • loadData

        public void loadData()
                      throws java.io.IOException,
                             java.lang.InterruptedException
        Restore sessions and data
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • takeSnapshot

        public void takeSnapshot()
      • getZxid

        public long getZxid()
        This should be called from a synchronized block on this!
      • setZxid

        public void setZxid​(long zxid)
      • closeSession

        public void closeSession​(long sessionId)
      • killSession

        protected void killSession​(long sessionId,
                                   long zxid)
      • registerJMX

        protected void registerJMX()
      • startdata

        public void startdata()
                       throws java.io.IOException,
                              java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • startup

        public void startup()
      • setupRequestProcessors

        protected void setupRequestProcessors()
      • createSessionTracker

        protected void createSessionTracker()
      • startSessionTracker

        protected void startSessionTracker()
      • setState

        protected void setState​(ZooKeeperServer.State state)
        Sets the state of ZooKeeper server. After changing the state, it notifies the server state change to a registered shutdown handler, if any.

        The following are the server state transitions:

      • During startup the server will be in the INITIAL state.
      • After successfully starting, the server sets the state to RUNNING.
      • The server transitions to the ERROR state if it hits an internal error. ZooKeeperServerListenerImpl notifies any critical resource error events, e.g., SyncRequestProcessor not being able to write a txn to disk.
      • During shutdown the server sets the state to SHUTDOWN, which corresponds to the server not running.
Parameters:
state - new server state.