Creating a ledger.

Before writing entries to BookKeeper, it is necessary to create a ledger.
With the current BookKeeper API, it is possible to create a ledger both synchronously
or asynchronously. The following methods belong
to org.apache.bookkeeper.client.BookKeeper.

The parameters are the same of the synchronous version, with the
exception of cb and ctx. CreateCallback
is an interface in org.apache.bookkeeper.client.AsyncCallback, and
a class implementing it has to implement a method called createComplete
that has the following signature:

void createComplete(int rc, LedgerHandle lh, Object ctx);

where:

rc is a return code (please refer to org.apache.bookeeper.client.BKException for a list);

lh is a LedgerHandle object to manipulate a ledger;

ctx is a control object for accountability purposes. It can be essentially any object the application is happy with.

The ctx object passed as a parameter to the call to create a ledger
is the one same returned in the callback.

Adding entries to a ledger.

Once we have a ledger handle lh obtained through a call to create a ledger, we
can start writing entries. As with creating ledgers, we can write both synchronously and
asynchronously. The following methods belong
to org.apache.bookkeeper.client.LedgerHandle.

Synchronous call:

public long addEntry(byte[] data)
throws InterruptedException

where:

data is a byte array;

A call to addEntry returns the status of the operation (please refer to org.apache.bookeeper.client.BKDefs for a list);

Asynchronous call:

public void asyncAddEntry(byte[] data, AddCallback cb, Object ctx)

It also takes a byte array as the sequence of bytes to be stored as an entry. Additionaly, it takes
a callback object cb and a control object ctx. The callback object must implement
the AddCallback interface in org.apache.bookkeeper.client.AsyncCallback, and
a class implementing it has to implement a method called addComplete
that has the following signature:

void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx);

where:

rc is a return code (please refer to org.apache.bookeeper.client.BKDefs for a list);

lh is a LedgerHandle object to manipulate a ledger;

entryId is the identifier of entry associated with this request;

ctx is control object used for accountability purposes. It can be any object the application is happy with.

Closing a ledger.

Once a client is done writing, it closes the ledger. The following methods belong
to org.apache.bookkeeper.client.LedgerHandle.

It takes a callback object cb and a control object ctx. The callback object must implement
the CloseCallback interface in org.apache.bookkeeper.client.AsyncCallback, and
a class implementing it has to implement a method called closeComplete
that has the following signature:

void closeComplete(int rc, LedgerHandle lh, Object ctx)

where:

rc is a return code (please refer to org.apache.bookeeper.client.BKDefs for a list);

lh is a LedgerHandle object to manipulate a ledger;

ctx is control object used for accountability purposes.

Opening a ledger.

To read from a ledger, a client must open it first. The following methods belong
to org.apache.bookkeeper.client.BookKeeper.

It also takes a a ledger identifier and a password. Additionaly, it takes a callback object
cb and a control object ctx. The callback object must implement
the OpenCallback interface in org.apache.bookkeeper.client.AsyncCallback, and
a class implementing it has to implement a method called openComplete
that has the following signature:

public void openComplete(int rc, LedgerHandle lh, Object ctx)

where:

rc is a return code (please refer to org.apache.bookeeper.client.BKDefs for a list);

lh is a LedgerHandle object to manipulate a ledger;

ctx is control object used for accountability purposes.

Reading from ledger

Read calls may request one or more consecutive entries. The following methods belong
to org.apache.bookkeeper.client.LedgerHandle.

It also takes a first and a last entry identifiers. Additionaly, it takes a callback object
cb and a control object ctx. The callback object must implement
the ReadCallback interface in org.apache.bookkeeper.client.AsyncCallback, and
a class implementing it has to implement a method called readComplete
that has the following signature:

It takes a ledger identifier. Additionally, it takes a callback object
cb and a control object ctx. The callback object must implement
the DeleteCallback interface in org.apache.bookkeeper.client.AsyncCallback, and
a class implementing it has to implement a method called deleteComplete
that has the following signature:

void deleteComplete(int rc, Object ctx)

where:

rc is a return code (please refer to org.apache.bookeeper.client.BKDefs for a list);