1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081 |
- <!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.8">
- <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://hadoop.apache.org/">Hadoop</a> > <a href="http://hadoop.apache.org/zookeeper/">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://hadoop.apache.org/zookeeper/"><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="hadoop.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://hadoop.apache.org/zookeeper/">Project</a>
- </li>
- <li>
- <a class="unselected" href="http://wiki.apache.org/hadoop/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="http://wiki.apache.org/hadoop/ZooKeeper">Wiki</a>
- </div>
- <div class="menuitem">
- <a href="http://wiki.apache.org/hadoop/ZooKeeper/FAQ">FAQ</a>
- </div>
- <div class="menuitem">
- <a href="http://hadoop.apache.org/zookeeper/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="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>
-
-
-
- <a name="N10009"></a><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="N1004A"></a><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="N100B1"></a><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="N10166"></a><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="N10201"></a><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="N10276"></a><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="N1030D"></a><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="N103A4"></a><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>
|