Skip to end of metadata
Go to start of metadata

(this page will contain a description of all the Client API of BookKeeper)

Introduction to the Client API

BookKeeper Client API entry point is the org.apache.bookkeeper.client.BookKeeper class.

Usually a Client creates an instance of BookKeeper  and uses it to manage several Ledgers using the LedgerHandle API.

 

 

BookKeeper Client Builder API

In order to create a BookKeeper client you have to setup a ClientConfiguration object.

The most important parameter is the ZooKeeper connection string, which is needed to access to the BookKeeper ensemble.

If you already have a ZooKeeper handle and you want to share it you have to pass it the Builder

Beware that ClientConfiguration will be automatically filled  with System.getProperties()

Synch vs Asynch

BookKeeper API methods provide access to BookKeeper features, internally all is asynchronous and in general the asynch API will give you more control about whats going on and result in better performances.

For instance

 

A similar code using the synch API is:

 

The async API will be really more efficient from the standpoint of speed but you have to deal with callbacks, remember that:

  • callbacks are called in a different thread
  • exception will not be thrown in the main (callee) thread but you have to switch over the 'rc' (return code) parameter, using the BKException.Code class or BKException.create(rc) method
  • you have no direct control on the pool of threads which executes the callbacks

Writing to a Ledger

Reading from a Ledger

(brief explanation of fencing)

Closing a Ledger

You always have to call LedgerHandle.close(), this operation will ensure the consistency of all metadata of the ledger and will release resources assigned to the ledger, both locally to the client and on Bookies.

Deleting a Ledger

When a Ledger is no more in use it is better to delete it, in order to let all the Bookies release all the resources retained by the ledger. A ledger will also retain resources on ZooKeeper.

The code is simple:

List ledgers

If you need to discover all the ledgersyou can use the BookKeeperAdmin tool

 

Return Codes

 

  • No labels