org.apache.zookeeper.server
Class ZooKeeperServer

java.lang.Object
  extended by org.apache.zookeeper.server.ZooKeeperServer
All Implemented Interfaces:
ServerStats.Provider, SessionTracker.SessionExpirer
Direct Known Subclasses:
QuorumZooKeeperServer

public class ZooKeeperServer
extends Object
implements SessionTracker.SessionExpirer, ServerStats.Provider

This class implements a simple standalone ZooKeeperServer. It sets up the following chain of RequestProcessors to process requests: PrepRequestProcessor -> SyncRequestProcessor -> FinalRequestProcessor


Nested Class Summary
static class ZooKeeperServer.MissingSessionException
           
 
Field Summary
static int DEFAULT_TICK_TIME
           
protected  RequestProcessor firstProcessor
           
protected  long hzxid
           
protected  DataTreeBean jmxDataTreeBean
           
protected  ZooKeeperServerBean jmxServerBean
           
protected static org.slf4j.Logger LOG
           
protected  int maxSessionTimeout
          value of -1 indicates unset, use default
protected  int minSessionTimeout
          value of -1 indicates unset, use default
static Exception ok
           
protected  boolean running
           
protected  SessionTracker sessionTracker
           
protected  int tickTime
           
 
Constructor Summary
ZooKeeperServer()
          Creates a ZooKeeperServer instance.
ZooKeeperServer(File snapDir, File logDir, int tickTime)
          This constructor is for backward compatibility with the existing unit test code.
ZooKeeperServer(FileTxnSnapLog txnLogFactory)
          Default constructor, relies on the config for its agrument values
ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime)
          creates a zookeeperserver instance.
ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, ZKDatabase zkDb)
          Creates a ZooKeeperServer instance.
 
Method Summary
protected  boolean checkPasswd(long sessionId, byte[] passwd)
           
 void closeSession(long sessionId)
           
 void closeSession(ServerCnxn cnxn, RequestHeader requestHeader)
           
protected  void createSessionTracker()
           
 void decInProcess()
           
 void dumpConf(PrintWriter pwriter)
           
 void dumpEphemerals(PrintWriter pwriter)
           
 void expire(SessionTracker.Session session)
           
 void finishSessionInit(ServerCnxn cnxn, boolean valid)
           
 int getClientPort()
           
 int getGlobalOutstandingLimit()
           
 int getInProcess()
           
 long getLastProcessedZxid()
          return the last proceesed id from the datatree
 int getMaxSessionTimeout()
           
 int getMinSessionTimeout()
           
 long getOutstandingRequests()
          return the outstanding requests in the queue, which havent been processed yet
 ServerCnxnFactory getServerCnxnFactory()
           
 long getServerId()
           
static int getSnapCount()
           
 String getState()
           
 int getTickTime()
           
 FileTxnSnapLog getTxnLogFactory()
           
 ZKDatabase getZKDatabase()
          get the zookeeper database for this server
 long getZxid()
          This should be called from a synchronized block on this!
 void incInProcess()
           
 boolean isRunning()
           
protected  void killSession(long sessionId, long zxid)
           
 void loadData()
          Restore sessions and data
 void processConnectRequest(ServerCnxn cnxn, ByteBuffer incomingBuffer)
           
 void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer)
           
protected  void registerJMX()
           
 void reopenSession(ServerCnxn cnxn, long sessionId, byte[] passwd, int sessionTimeout)
           
protected  void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout)
           
 ServerStats serverStats()
           
 void setMaxSessionTimeout(int max)
           
 void setMinSessionTimeout(int min)
           
 void setOwner(long id, Object owner)
          set the owner of this session as owner
 void setServerCnxnFactory(ServerCnxnFactory factory)
           
 void setTickTime(int tickTime)
           
 void setTxnLogFactory(FileTxnSnapLog txnLog)
           
protected  void setupRequestProcessors()
           
 void setZKDatabase(ZKDatabase zkDb)
          set the zkdatabase for this zookeeper server
 void setZxid(long zxid)
           
 boolean shouldThrottle(long outStandingCount)
           
 void shutdown()
           
 void startdata()
           
 void startup()
           
 void submitRequest(Request si)
           
 void takeSnapshot()
           
 void truncateLog(long zxid)
          trunccate the log to get in sync with others if in a quorum
protected  void unregisterJMX()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.slf4j.Logger LOG

jmxServerBean

protected ZooKeeperServerBean jmxServerBean

jmxDataTreeBean

protected DataTreeBean jmxDataTreeBean

DEFAULT_TICK_TIME

public static final int DEFAULT_TICK_TIME
See Also:
Constant Field Values

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


sessionTracker

protected SessionTracker sessionTracker

hzxid

protected long hzxid

ok

public static final Exception ok

firstProcessor

protected RequestProcessor firstProcessor

running

protected volatile boolean running
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:
IOException

ZooKeeperServer

public ZooKeeperServer(FileTxnSnapLog txnLogFactory,
                       int tickTime,
                       int minSessionTimeout,
                       int maxSessionTimeout,
                       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)
                throws IOException
creates a zookeeperserver instance.

Parameters:
txnLogFactory - the file transaction snapshot logging class
tickTime - the ticktime for the server
treeBuilder - the datatree builder
Throws:
IOException

ZooKeeperServer

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

Throws:
IOException

ZooKeeperServer

public ZooKeeperServer(FileTxnSnapLog txnLogFactory)
                throws IOException
Default constructor, relies on the config for its agrument values

Throws:
IOException
Method Detail

serverStats

public ServerStats serverStats()

dumpConf

public void dumpConf(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 IOException,
                     InterruptedException
Restore sessions and data

Throws:
IOException
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)

expire

public void expire(SessionTracker.Session session)
Specified by:
expire in interface SessionTracker.SessionExpirer

registerJMX

protected void registerJMX()

startdata

public void startdata()
               throws IOException,
                      InterruptedException
Throws:
IOException
InterruptedException

startup

public void startup()

setupRequestProcessors

protected void setupRequestProcessors()

createSessionTracker

protected void createSessionTracker()

isRunning

public boolean isRunning()

shutdown

public void shutdown()

unregisterJMX

protected void unregisterJMX()

incInProcess

public void incInProcess()

decInProcess

public void decInProcess()

getInProcess

public int getInProcess()

checkPasswd

protected boolean checkPasswd(long sessionId,
                              byte[] passwd)

setOwner

public void setOwner(long id,
                     Object owner)
              throws KeeperException.SessionExpiredException
set the owner of this session as owner

Parameters:
id - the session id
owner - the owner of the session
Throws:
KeeperException.SessionExpiredException

revalidateSession

protected void revalidateSession(ServerCnxn cnxn,
                                 long sessionId,
                                 int sessionTimeout)
                          throws IOException
Throws:
IOException

reopenSession

public void reopenSession(ServerCnxn cnxn,
                          long sessionId,
                          byte[] passwd,
                          int sessionTimeout)
                   throws IOException
Throws:
IOException

finishSessionInit

public void finishSessionInit(ServerCnxn cnxn,
                              boolean valid)

closeSession

public void closeSession(ServerCnxn cnxn,
                         RequestHeader requestHeader)

getServerId

public long getServerId()
Specified by:
getServerId in interface SessionTracker.SessionExpirer

submitRequest

public void submitRequest(Request si)

getSnapCount

public static int getSnapCount()

getGlobalOutstandingLimit

public int getGlobalOutstandingLimit()

setServerCnxnFactory

public void setServerCnxnFactory(ServerCnxnFactory factory)

getServerCnxnFactory

public ServerCnxnFactory getServerCnxnFactory()

getLastProcessedZxid

public long getLastProcessedZxid()
return the last proceesed id from the datatree

Specified by:
getLastProcessedZxid in interface ServerStats.Provider

getOutstandingRequests

public long getOutstandingRequests()
return the outstanding requests in the queue, which havent been processed yet

Specified by:
getOutstandingRequests in interface ServerStats.Provider

truncateLog

public void truncateLog(long zxid)
                 throws IOException
trunccate the log to get in sync with others if in a quorum

Parameters:
zxid - the zxid that it needs to get in sync with others
Throws:
IOException

getTickTime

public int getTickTime()

setTickTime

public void setTickTime(int tickTime)

getMinSessionTimeout

public int getMinSessionTimeout()

setMinSessionTimeout

public void setMinSessionTimeout(int min)

getMaxSessionTimeout

public int getMaxSessionTimeout()

setMaxSessionTimeout

public void setMaxSessionTimeout(int max)

getClientPort

public int getClientPort()

setTxnLogFactory

public void setTxnLogFactory(FileTxnSnapLog txnLog)

getTxnLogFactory

public FileTxnSnapLog getTxnLogFactory()

getState

public String getState()
Specified by:
getState in interface ServerStats.Provider

dumpEphemerals

public void dumpEphemerals(PrintWriter pwriter)

processConnectRequest

public void processConnectRequest(ServerCnxn cnxn,
                                  ByteBuffer incomingBuffer)
                           throws IOException
Throws:
IOException

shouldThrottle

public boolean shouldThrottle(long outStandingCount)

processPacket

public void processPacket(ServerCnxn cnxn,
                          ByteBuffer incomingBuffer)
                   throws IOException
Throws:
IOException


Copyright © 2011 The Apache Software Foundation