123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta content="Apache Forrest" name="Generator">
- <meta name="Forrest-version" content="0.9">
- <meta name="Forrest-skin-name" content="pelt">
- <title>BookKeeper Getting Started Guide</title>
- <link type="text/css" href="skin/basic.css" rel="stylesheet">
- <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
- <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
- <link type="text/css" href="skin/profile.css" rel="stylesheet">
- <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
- <link rel="shortcut icon" href="images/favicon.ico">
- </head>
- <body onload="init()">
- <script type="text/javascript">ndeSetTextSize();</script>
- <div id="top">
- <!--+
- |breadtrail
- +-->
- <div class="breadtrail">
- <a href="http://www.apache.org/">Apache</a> > <a href="http://zookeeper.apache.org/">ZooKeeper</a> > <a href="http://zookeeper.apache.org/">ZooKeeper</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
- </div>
- <!--+
- |header
- +-->
- <div class="header">
- <!--+
- |start group logo
- +-->
- <div class="grouplogo">
- <a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
- </div>
- <!--+
- |end group logo
- +-->
- <!--+
- |start Project Logo
- +-->
- <div class="projectlogo">
- <a href="http://zookeeper.apache.org/"><img class="logoImage" alt="ZooKeeper" src="images/zookeeper_small.gif" title="ZooKeeper: distributed coordination"></a>
- </div>
- <!--+
- |end Project Logo
- +-->
- <!--+
- |start Search
- +-->
- <div class="searchbox">
- <form action="http://www.google.com/search" method="get" class="roundtopsmall">
- <input value="zookeeper.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">
- <input name="Search" value="Search" type="submit">
- </form>
- </div>
- <!--+
- |end search
- +-->
- <!--+
- |start Tabs
- +-->
- <ul id="tabs">
- <li>
- <a class="unselected" href="http://zookeeper.apache.org/">Project</a>
- </li>
- <li>
- <a class="unselected" href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/">Wiki</a>
- </li>
- <li class="current">
- <a class="selected" href="index.html">ZooKeeper 3.4 Documentation</a>
- </li>
- </ul>
- <!--+
- |end Tabs
- +-->
- </div>
- </div>
- <div id="main">
- <div id="publishedStrip">
- <!--+
- |start Subtabs
- +-->
- <div id="level2tabs"></div>
- <!--+
- |end Endtabs
- +-->
- <script type="text/javascript"><!--
- document.write("Last Published: " + document.lastModified);
- // --></script>
- </div>
- <!--+
- |breadtrail
- +-->
- <div class="breadtrail">
-
- </div>
- <!--+
- |start Menu, mainarea
- +-->
- <!--+
- |start Menu
- +-->
- <div id="menu">
- <div onclick="SwitchMenu('menu_1.1', 'skin/')" id="menu_1.1Title" class="menutitle">Overview</div>
- <div id="menu_1.1" class="menuitemgroup">
- <div class="menuitem">
- <a href="index.html">Welcome</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperOver.html">Overview</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperStarted.html">Getting Started</a>
- </div>
- <div class="menuitem">
- <a href="releasenotes.html">Release Notes</a>
- </div>
- </div>
- <div onclick="SwitchMenu('menu_1.2', 'skin/')" id="menu_1.2Title" class="menutitle">Developer</div>
- <div id="menu_1.2" class="menuitemgroup">
- <div class="menuitem">
- <a href="api/index.html">API Docs</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperProgrammers.html">Programmer's Guide</a>
- </div>
- <div class="menuitem">
- <a href="javaExample.html">Java Example</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperTutorial.html">Barrier and Queue Tutorial</a>
- </div>
- <div class="menuitem">
- <a href="recipes.html">Recipes</a>
- </div>
- </div>
- <div onclick="SwitchMenu('menu_selected_1.3', 'skin/')" id="menu_selected_1.3Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">BookKeeper</div>
- <div id="menu_selected_1.3" class="selectedmenuitemgroup" style="display: block;">
- <div class="menuitem">
- <a href="bookkeeperStarted.html">Getting started</a>
- </div>
- <div class="menuitem">
- <a href="bookkeeperOverview.html">Overview</a>
- </div>
- <div class="menuitem">
- <a href="bookkeeperConfig.html">Setup guide</a>
- </div>
- <div class="menupage">
- <div class="menupagetitle">Programmer's guide</div>
- </div>
- </div>
- <div onclick="SwitchMenu('menu_1.4', 'skin/')" id="menu_1.4Title" class="menutitle">Admin & Ops</div>
- <div id="menu_1.4" class="menuitemgroup">
- <div class="menuitem">
- <a href="zookeeperAdmin.html">Administrator's Guide</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperQuotas.html">Quota Guide</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperJMX.html">JMX</a>
- </div>
- <div class="menuitem">
- <a href="zookeeperObservers.html">Observers Guide</a>
- </div>
- </div>
- <div onclick="SwitchMenu('menu_1.5', 'skin/')" id="menu_1.5Title" class="menutitle">Contributor</div>
- <div id="menu_1.5" class="menuitemgroup">
- <div class="menuitem">
- <a href="zookeeperInternals.html">ZooKeeper Internals</a>
- </div>
- </div>
- <div onclick="SwitchMenu('menu_1.6', 'skin/')" id="menu_1.6Title" class="menutitle">Miscellaneous</div>
- <div id="menu_1.6" class="menuitemgroup">
- <div class="menuitem">
- <a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER">Wiki</a>
- </div>
- <div class="menuitem">
- <a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ">FAQ</a>
- </div>
- <div class="menuitem">
- <a href="http://zookeeper.apache.org/mailing_lists.html">Mailing Lists</a>
- </div>
- </div>
- <div id="credit"></div>
- <div id="roundbottom">
- <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
- <!--+
- |alternative credits
- +-->
- <div id="credit2"></div>
- </div>
- <!--+
- |end Menu
- +-->
- <!--+
- |start content
- +-->
- <div id="content">
- <div title="Portable Document Format" class="pdflink">
- <a class="dida" href="bookkeeperProgrammer.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
- PDF</a>
- </div>
- <h1>BookKeeper Getting Started Guide</h1>
- <div id="front-matter">
- <div id="minitoc-area">
- <ul class="minitoc">
- <li>
- <a href="#bk_GettingStarted">Programming with BookKeeper</a>
- <ul class="minitoc">
- <li>
- <a href="#bk_instance"> Instantiating BookKeeper.</a>
- </li>
- <li>
- <a href="#bk_createLedger"> Creating a ledger. </a>
- </li>
- <li>
- <a href="#bk_writeLedger"> Adding entries to a ledger. </a>
- </li>
- <li>
- <a href="#bk_closeLedger"> Closing a ledger. </a>
- </li>
- <li>
- <a href="#bk_openLedger"> Opening a ledger. </a>
- </li>
- <li>
- <a href="#bk_readLedger"> Reading from ledger </a>
- </li>
- <li>
- <a href="#bk_deleteLedger"> Deleting a ledger </a>
- </li>
- </ul>
- </li>
- </ul>
- </div>
- </div>
-
-
-
- <a name="bk_GettingStarted"></a>
- <h2 class="h3">Programming with BookKeeper</h2>
- <div class="section">
- <ul>
-
- <li>
-
- <p>
- <a href="#bk_instance"> Instantiating BookKeeper.</a>
- </p>
-
- </li>
-
- <li>
-
- <p>
- <a href="#bk_createLedger"> Creating a ledger. </a>
- </p>
-
- </li>
-
- <li>
-
- <p>
- <a href="#bk_writeLedger"> Adding entries to a ledger. </a>
- </p>
-
- </li>
-
- <li>
-
- <p>
- <a href="#bk_closeLedger"> Closing a ledger. </a>
- </p>
-
- </li>
-
-
- <li>
-
- <p>
- <a href="#bk_openLedger"> Opening a ledger. </a>
- </p>
-
- </li>
-
-
- <li>
-
- <p>
- <a href="#bk_readLedger"> Reading from ledger </a>
- </p>
-
- </li>
-
-
- <li>
-
- <p>
- <a href="#bk_deleteLedger"> Deleting a ledger </a>
- </p>
-
- </li>
-
-
- </ul>
- <a name="bk_instance"></a>
- <h3 class="h4"> Instantiating BookKeeper.</h3>
- <p>
- The first step to use BookKeeper is to instantiate a BookKeeper object:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- org.apache.bookkeeper.BookKeeper
- </span>
-
- </p>
- <p>
- There are three BookKeeper constructors:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public BookKeeper(String servers)
- throws KeeperException, IOException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">servers</span> is a comma-separated list of ZooKeeper servers.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public BookKeeper(ZooKeeper zk)
- throws InterruptedException, KeeperException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">zk</span> is a ZooKeeper object. This constructor is useful when
- the application also using ZooKeeper and wants to have a single instance of ZooKeeper.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public BookKeeper(ZooKeeper zk, ClientSocketChannelFactory channelFactory)
- throws InterruptedException, KeeperException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">zk</span> is a ZooKeeper object. This constructor is useful when
- the application also using ZooKeeper and wants to have a single instance of ZooKeeper.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">channelFactory</span> is a netty channel object
- (<span class="codefrag computeroutput">org.jboss.netty.channel.socket</span>).
- </p>
-
- </li>
-
- </ul>
- <a name="bk_createLedger"></a>
- <h3 class="h4"> Creating a ledger. </h3>
- <p> 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 <span class="codefrag computeroutput">org.apache.bookkeeper.client.BookKeeper</span>.
- </p>
- <p>
-
- <strong>Synchronous call:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public LedgerHandle createLedger(int ensSize, int qSize, DigestType type, byte passwd[])
- throws KeeperException, InterruptedException,
- IOException, BKException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ensSize</span> is the number of bookies (ensemble size);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">qSize</span> is the write quorum size;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">type</span> is the type of digest used with entries: either MAC or CRC32.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">passwd</span> is a password that authorizes the client to write to the
- ledger being created.
- </p>
-
- </li>
-
- </ul>
- <p>
- All further operations on a ledger are invoked through the <span class="codefrag computeroutput">LedgerHandle</span>
- object returned.
- </p>
- <p>
- As a convenience, we provide a <span class="codefrag computeroutput">createLedger</span> with default parameters (3,2,VERIFIABLE),
- and the only two input parameters it requires are a digest type and a password.
- </p>
- <p>
-
- <strong>Asynchronous call:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void asyncCreateLedger(int ensSize,
- int qSize,
- DigestType type,
- byte passwd[],
- CreateCallback cb,
- Object ctx
- )
- </span>
-
- </p>
- <p>
- The parameters are the same of the synchronous version, with the
- exception of <span class="codefrag computeroutput">cb</span> and <span class="codefrag computeroutput">ctx</span>. <span class="codefrag computeroutput">CreateCallback</span>
- is an interface in <span class="codefrag computeroutput">org.apache.bookkeeper.client.AsyncCallback</span>, and
- a class implementing it has to implement a method called <span class="codefrag computeroutput">createComplete</span>
- that has the following signature:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- void createComplete(int rc, LedgerHandle lh, Object ctx);
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">rc</span> is a return code (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKException</span> for a list);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a <span class="codefrag computeroutput">LedgerHandle</span> object to manipulate a ledger;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ctx</span> is a control object for accountability purposes. It can be essentially any object the application is happy with.
- </p>
-
- </li>
-
- </ul>
- <p>
- The <span class="codefrag computeroutput">ctx</span> object passed as a parameter to the call to create a ledger
- is the one same returned in the callback.
- </p>
- <a name="bk_writeLedger"></a>
- <h3 class="h4"> Adding entries to a ledger. </h3>
- <p>
- Once we have a ledger handle <span class="codefrag computeroutput">lh</span> 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 <span class="codefrag computeroutput">org.apache.bookkeeper.client.LedgerHandle</span>.
- </p>
- <p>
-
- <strong>Synchronous call:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public long addEntry(byte[] data)
- throws InterruptedException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">data</span> is a byte array;
- </p>
-
- </li>
-
- </ul>
- <p>
- A call to <span class="codefrag computeroutput">addEntry</span> returns the status of the operation (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKDefs</span> for a list);
- </p>
- <p>
-
- <strong>Asynchronous call:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void asyncAddEntry(byte[] data, AddCallback cb, Object ctx)
- </span>
-
- </p>
- <p>
- It also takes a byte array as the sequence of bytes to be stored as an entry. Additionaly, it takes
- a callback object <span class="codefrag computeroutput">cb</span> and a control object <span class="codefrag computeroutput">ctx</span>. The callback object must implement
- the <span class="codefrag computeroutput">AddCallback</span> interface in <span class="codefrag computeroutput">org.apache.bookkeeper.client.AsyncCallback</span>, and
- a class implementing it has to implement a method called <span class="codefrag computeroutput">addComplete</span>
- that has the following signature:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx);
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">rc</span> is a return code (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKDefs</span> for a list);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a <span class="codefrag computeroutput">LedgerHandle</span> object to manipulate a ledger;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">entryId</span> is the identifier of entry associated with this request;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ctx</span> is control object used for accountability purposes. It can be any object the application is happy with.
- </p>
-
- </li>
-
- </ul>
- <a name="bk_closeLedger"></a>
- <h3 class="h4"> Closing a ledger. </h3>
- <p>
- Once a client is done writing, it closes the ledger. The following methods belong
- to <span class="codefrag computeroutput">org.apache.bookkeeper.client.LedgerHandle</span>.
- </p>
- <p>
-
- <strong>Synchronous close:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void close()
- throws InterruptedException
- </span>
-
- </p>
- <p>
- It takes no input parameters.
- </p>
- <p>
-
- <strong>Asynchronous close:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void asyncClose(CloseCallback cb, Object ctx)
- throws InterruptedException
- </span>
-
- </p>
- <p>
- It takes a callback object <span class="codefrag computeroutput">cb</span> and a control object <span class="codefrag computeroutput">ctx</span>. The callback object must implement
- the <span class="codefrag computeroutput">CloseCallback</span> interface in <span class="codefrag computeroutput">org.apache.bookkeeper.client.AsyncCallback</span>, and
- a class implementing it has to implement a method called <span class="codefrag computeroutput">closeComplete</span>
- that has the following signature:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- void closeComplete(int rc, LedgerHandle lh, Object ctx)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">rc</span> is a return code (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKDefs</span> for a list);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a <span class="codefrag computeroutput">LedgerHandle</span> object to manipulate a ledger;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ctx</span> is control object used for accountability purposes.
- </p>
-
- </li>
-
- </ul>
- <a name="bk_openLedger"></a>
- <h3 class="h4"> Opening a ledger. </h3>
- <p>
- To read from a ledger, a client must open it first. The following methods belong
- to <span class="codefrag computeroutput">org.apache.bookkeeper.client.BookKeeper</span>.
- </p>
- <p>
-
- <strong>Synchronous open:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public LedgerHandle openLedger(long lId, DigestType type, byte passwd[])
- throws InterruptedException, BKException
- </span>
-
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ledgerId</span> is the ledger identifier;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">type</span> is the type of digest used with entries: either MAC or CRC32.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">passwd</span> is a password to access the ledger (used only in the case of <span class="codefrag computeroutput">VERIFIABLE</span> ledgers);
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <strong>Asynchronous open:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void asyncOpenLedger(long lId, DigestType type, byte passwd[], OpenCallback cb, Object ctx)
- </span>
-
- </p>
- <p>
- It also takes a a ledger identifier and a password. Additionaly, it takes a callback object
- <span class="codefrag computeroutput">cb</span> and a control object <span class="codefrag computeroutput">ctx</span>. The callback object must implement
- the <span class="codefrag computeroutput">OpenCallback</span> interface in <span class="codefrag computeroutput">org.apache.bookkeeper.client.AsyncCallback</span>, and
- a class implementing it has to implement a method called <span class="codefrag computeroutput">openComplete</span>
- that has the following signature:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void openComplete(int rc, LedgerHandle lh, Object ctx)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">rc</span> is a return code (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKDefs</span> for a list);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a <span class="codefrag computeroutput">LedgerHandle</span> object to manipulate a ledger;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ctx</span> is control object used for accountability purposes.
- </p>
-
- </li>
-
- </ul>
- <a name="bk_readLedger"></a>
- <h3 class="h4"> Reading from ledger </h3>
- <p>
- Read calls may request one or more consecutive entries. The following methods belong
- to <span class="codefrag computeroutput">org.apache.bookkeeper.client.LedgerHandle</span>.
- </p>
- <p>
-
- <strong>Synchronous read:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public Enumeration<LedgerEntry> readEntries(long firstEntry, long lastEntry)
- throws InterruptedException, BKException
- </span>
-
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">firstEntry</span> is the identifier of the first entry in the sequence of entries to read;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lastEntry</span> is the identifier of the last entry in the sequence of entries to read.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <strong>Asynchronous read:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void asyncReadEntries(long firstEntry,
- long lastEntry, ReadCallback cb, Object ctx)
- throws BKException, InterruptedException
- </span>
-
- </p>
- <p>
- It also takes a first and a last entry identifiers. Additionaly, it takes a callback object
- <span class="codefrag computeroutput">cb</span> and a control object <span class="codefrag computeroutput">ctx</span>. The callback object must implement
- the <span class="codefrag computeroutput">ReadCallback</span> interface in <span class="codefrag computeroutput">org.apache.bookkeeper.client.AsyncCallback</span>, and
- a class implementing it has to implement a method called <span class="codefrag computeroutput">readComplete</span>
- that has the following signature:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> seq, Object ctx)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">rc</span> is a return code (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKDefs</span> for a list);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a <span class="codefrag computeroutput">LedgerHandle</span> object to manipulate a ledger;
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">seq</span> is a <span class="codefrag computeroutput">Enumeration<LedgerEntry> </span> object to containing the list of entries requested;
- </p>
-
- </li>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ctx</span> is control object used for accountability purposes.
- </p>
-
- </li>
-
- </ul>
- <a name="bk_deleteLedger"></a>
- <h3 class="h4"> Deleting a ledger </h3>
- <p>
- Once a client is done with a ledger and is sure that nobody will ever need to read from it again, they can delete the ledger.
- The following methods belong to <span class="codefrag computeroutput">org.apache.bookkeeper.client.BookKeeper</span>.
- </p>
- <p>
-
- <strong>Synchronous delete:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void deleteLedger(long lId) throws InterruptedException, BKException
- </span>
-
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lId</span> is the ledger identifier;
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <strong>Asynchronous delete:</strong>
-
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void asyncDeleteLedger(long lId, DeleteCallback cb, Object ctx)
- </span>
-
- </p>
- <p>
- It takes a ledger identifier. Additionally, it takes a callback object
- <span class="codefrag computeroutput">cb</span> and a control object <span class="codefrag computeroutput">ctx</span>. The callback object must implement
- the <span class="codefrag computeroutput">DeleteCallback</span> interface in <span class="codefrag computeroutput">org.apache.bookkeeper.client.AsyncCallback</span>, and
- a class implementing it has to implement a method called <span class="codefrag computeroutput">deleteComplete</span>
- that has the following signature:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- void deleteComplete(int rc, Object ctx)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">rc</span> is a return code (please refer to <span class="codefrag computeroutput">org.apache.bookeeper.client.BKDefs</span> for a list);
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">ctx</span> is control object used for accountability purposes.
- </p>
-
- </li>
-
- </ul>
- </div>
- <p align="right">
- <font size="-2"></font>
- </p>
- </div>
- <!--+
- |end content
- +-->
- <div class="clearboth"> </div>
- </div>
- <div id="footer">
- <!--+
- |start bottomstrip
- +-->
- <div class="lastmodified">
- <script type="text/javascript"><!--
- document.write("Last Published: " + document.lastModified);
- // --></script>
- </div>
- <div class="copyright">
- Copyright ©
- 2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
- </div>
- <!--+
- |end bottomstrip
- +-->
- </div>
- </body>
- </html>
|