org.apache.bookkeeper.client
Class BookKeeper

java.lang.Object
  extended by org.apache.bookkeeper.client.BookKeeper
All Implemented Interfaces:
Watcher

public class BookKeeper
extends Object
implements Watcher

BookKeeper client. We assume there is one single writer to a ledger at any time. There are three possible operations: start a new ledger, write to a ledger, and read from a ledger. For the ZooKeeper layout, please refer to BKDefs.java.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
Watcher.Event
 
Constructor Summary
BookKeeper(String servers)
           
 
Method Summary
 void asyncCreateLedger(int ensSize, int qSize, LedgerHandle.QMode mode, byte[] passwd, AsyncCallback.CreateCallback cb, Object ctx)
          Asychronous call to create ledger
 void asyncOpenLedger(long lId, byte[] passwd, AsyncCallback.OpenCallback cb, Object ctx)
           
 LedgerHandle createLedger(byte[] passwd)
          Creates a new ledger.
 LedgerHandle createLedger(int ensSize, int qSize, LedgerHandle.QMode mode, byte[] passwd)
          Creates a new ledger.
 void halt()
          Halts all bookie handles
 boolean hasClosed(long ledgerId)
          Check if close node exists.
 LedgerHandle openLedger(long lId, byte[] passwd)
          Open existing ledger for reading.
 void process(WatchedEvent event)
          Watcher method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BookKeeper

public BookKeeper(String servers)
           throws KeeperException,
                  IOException
Throws:
KeeperException
IOException
Method Detail

process

public void process(WatchedEvent event)
Watcher method.

Specified by:
process in interface Watcher

createLedger

public LedgerHandle createLedger(int ensSize,
                                 int qSize,
                                 LedgerHandle.QMode mode,
                                 byte[] passwd)
                          throws KeeperException,
                                 InterruptedException,
                                 IOException,
                                 BKException
Creates a new ledger. To create a ledger, we need to specify the ensemble size, the quorum size, the operation mode, and a password. The ensemble size and the quorum size depend upon the operation mode. The operation mode can be GENERIC, VERIFIABLE, or FREEFORM (debugging). The password is used not only to authenticate access to a ledger, but also to verify entries in verifiable ledgers.

Parameters:
ensSize - ensemble size
qSize - quorum size
mode - quorum mode: VERIFIABLE (default), GENERIC, or FREEFORM
passwd - password
Throws:
KeeperException
InterruptedException
IOException
BKException

createLedger

public LedgerHandle createLedger(byte[] passwd)
                          throws KeeperException,
                                 BKException,
                                 InterruptedException,
                                 IOException
Creates a new ledger. Default of 3 servers, and quorum of 2 servers, verifiable ledger.

Parameters:
passwd - password
Throws:
KeeperException
BKException
InterruptedException
IOException

asyncCreateLedger

public void asyncCreateLedger(int ensSize,
                              int qSize,
                              LedgerHandle.QMode mode,
                              byte[] passwd,
                              AsyncCallback.CreateCallback cb,
                              Object ctx)
                       throws KeeperException,
                              InterruptedException,
                              IOException,
                              BKException
Asychronous call to create ledger

Parameters:
ensSize -
qSize -
mode -
passwd -
cb -
ctx -
Throws:
KeeperException
InterruptedException
IOException
BKException

openLedger

public LedgerHandle openLedger(long lId,
                               byte[] passwd)
                        throws KeeperException,
                               InterruptedException,
                               IOException,
                               BKException
Open existing ledger for reading. Default for quorum size is 2.

Parameters:
long - the long corresponding to the ledger id
byte[] - byte array corresponding to the password to access a ledger
int - the quorum size, it has to be at least ceil(n+1/2)
Throws:
KeeperException
InterruptedException
IOException
BKException

asyncOpenLedger

public void asyncOpenLedger(long lId,
                            byte[] passwd,
                            AsyncCallback.OpenCallback cb,
                            Object ctx)
                     throws InterruptedException
Throws:
InterruptedException

hasClosed

public boolean hasClosed(long ledgerId)
                  throws KeeperException,
                         InterruptedException
Check if close node exists.

Parameters:
ledgerId - id of the ledger to check
Throws:
KeeperException
InterruptedException

halt

public void halt()
          throws InterruptedException
Halts all bookie handles

Throws:
InterruptedException