org.apache.bookkeeper.client
Class LedgerHandle

java.lang.Object
  extended by org.apache.bookkeeper.client.LedgerHandle
All Implemented Interfaces:
AsyncCallback.AddCallback, AsyncCallback.ReadCallback

public class LedgerHandle
extends Object
implements AsyncCallback.ReadCallback, AsyncCallback.AddCallback

Ledger handle on the client side. Contains ledger metadata used to access it. This api exposes the read and write to a ledger and also exposes a streaming api for the ledger.


Nested Class Summary
static class LedgerHandle.QMode
           
 
Method Summary
 void addComplete(int rc, LedgerHandle lh, long entry, Object ctx)
          Implementation of callback interface for synchronous read method.
 long addEntry(byte[] data)
          Add entry synchronously to an open ledger.
 void asyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, Object ctx)
          Add entry asynchronously to an open ledger.
 void asyncClose(AsyncCallback.CloseCallback cb, Object ctx)
          Asynchronous close
 void asyncReadEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx)
          Read a sequence of entries asynchronously.
 void close()
          Close ledger.
 long getId()
          Returns the ledger identifier
 long getLast()
          Returns the last entry identifier submitted
 int getThreshold()
           
 void readComplete(int rc, LedgerHandle lh, LedgerSequence seq, Object ctx)
          Implementation of callback interface for synchronous read method.
 LedgerSequence readEntries(long firstEntry, long lastEntry)
          Read a sequence of entries synchronously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getThreshold

public int getThreshold()

getId

public long getId()
Returns the ledger identifier

Returns:
long

getLast

public long getLast()
Returns the last entry identifier submitted

Returns:
long

close

public void close()
           throws KeeperException,
                  InterruptedException,
                  BKException
Close ledger.

Throws:
KeeperException
InterruptedException
BKException

asyncClose

public void asyncClose(AsyncCallback.CloseCallback cb,
                       Object ctx)
                throws InterruptedException
Asynchronous close

Parameters:
cb - callback implementation
ctx - control object
Throws:
InterruptedException

asyncReadEntries

public void asyncReadEntries(long firstEntry,
                             long lastEntry,
                             AsyncCallback.ReadCallback cb,
                             Object ctx)
                      throws BKException,
                             InterruptedException
Read a sequence of entries asynchronously.

Parameters:
firstEntry - id of first entry of sequence
lastEntry - id of last entry of sequence
cb - object implementing read callback interface
ctx - control object
Throws:
BKException
InterruptedException

readEntries

public LedgerSequence readEntries(long firstEntry,
                                  long lastEntry)
                           throws InterruptedException,
                                  BKException
Read a sequence of entries synchronously.

Parameters:
firstEntry - id of first entry of sequence
lastEntry - id of last entry of sequence
Throws:
InterruptedException
BKException

asyncAddEntry

public void asyncAddEntry(byte[] data,
                          AsyncCallback.AddCallback cb,
                          Object ctx)
                   throws InterruptedException,
                          BKException
Add entry asynchronously to an open ledger.

Parameters:
data - array of bytes to be written
cb - object implementing callbackinterface
ctx - some control object
Throws:
InterruptedException
BKException

addEntry

public long addEntry(byte[] data)
              throws InterruptedException,
                     BKException
Add entry synchronously to an open ledger.

Parameters:
data - byte[]
Throws:
InterruptedException
BKException

readComplete

public void readComplete(int rc,
                         LedgerHandle lh,
                         LedgerSequence seq,
                         Object ctx)
Implementation of callback interface for synchronous read method.

Specified by:
readComplete in interface AsyncCallback.ReadCallback
Parameters:
rc - return code
leder - ledger identifier
seq - sequence of entries
ctx - control object

addComplete

public void addComplete(int rc,
                        LedgerHandle lh,
                        long entry,
                        Object ctx)
Implementation of callback interface for synchronous read method.

Specified by:
addComplete in interface AsyncCallback.AddCallback
Parameters:
rc - return code
leder - ledger identifier
entry - entry identifier
ctx - control object