123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- <!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>Streaming with BookKeeper</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_1.3', 'skin/')" id="menu_1.3Title" class="menutitle">BookKeeper</div>
- <div id="menu_1.3" class="menuitemgroup">
- <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="menuitem">
- <a href="bookkeeperProgrammer.html">Programmer's guide</a>
- </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="bookkeeperStream.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
- PDF</a>
- </div>
- <h1>Streaming with BookKeeper</h1>
- <div id="front-matter">
- <div id="minitoc-area">
- <ul class="minitoc">
- <li>
- <a href="#bk_StreamSummary">Summary</a>
- </li>
- <li>
- <a href="#bk_LedgerOutputStream">Writing a stream of bytes</a>
- </li>
- <li>
- <a href="#bk_LedgerInputStream">Reading a stream of bytes</a>
- </li>
- </ul>
- </div>
- </div>
-
-
-
- <a name="bk_StreamSummary"></a>
- <h2 class="h3">Summary</h2>
- <div class="section">
- <p>
- When using the BookKeeper API, an application has to split the data to write into entries, each
- entry being a byte array. This is natural for many applications. For example, when using BookKeeper
- for write-ahead logging, an application typically wants to write the modifications corresponding
- to a command or a transaction. Some other applications, however, might not have a natural boundary
- for entries, and may prefer to write and read streams of bytes. This is exactly the purpose of the
- stream API we have implemented on top of BookKeeper.
- </p>
- <p>
- The stream API is implemented in the package <span class="codefrag computeroutput">Streaming</span>, and it contains two main classes: <span class="codefrag computeroutput">LedgerOutputStream</span> and
- <span class="codefrag computeroutput">LedgerInputStream</span>. The class names are indicative of what they do.
- </p>
- </div>
-
-
- <a name="bk_LedgerOutputStream"></a>
- <h2 class="h3">Writing a stream of bytes</h2>
- <div class="section">
- <p>
- Class <span class="codefrag computeroutput">LedgerOutputStream</span> implements two constructors and five public methods:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public LedgerOutputStream(LedgerHandle lh)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a ledger handle for a previously created and open ledger.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public LedgerOutputStream(LedgerHandle lh, int size)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a ledger handle for a previously created and open ledger.
- </p>
-
- </li>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">size</span> is the size of the byte buffer to store written bytes before flushing.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <strong>Closing a stream.</strong> This call closes the stream by flushing the write buffer.
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void close()
- </span>
-
- </p>
- <p>
- which has no parameters.
- </p>
- <p>
-
- <strong>Flushing a stream.</strong> This call essentially flushes the write buffer.
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized void flush()
- </span>
-
- </p>
- <p>
- which has no parameters.
- </p>
- <p>
-
- <strong>Writing bytes.</strong> There are three calls for writing bytes to a stream.
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized void write(byte[] b)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">b</span> is an array of bytes to write.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized void write(byte[] b, int off, int len)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">b</span> is an array of bytes to write.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">off</span> is a buffer offset.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">len</span> is the length to write.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized void write(int b)
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">b</span> contains a byte to write. The method writes the least significant byte of the integer four bytes.
- </p>
-
- </li>
-
- </ul>
- </div>
-
-
- <a name="bk_LedgerInputStream"></a>
- <h2 class="h3">Reading a stream of bytes</h2>
- <div class="section">
- <p>
- Class <span class="codefrag computeroutput">LedgerOutputStream</span> implements two constructors and four public methods:
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public LedgerInputStream(LedgerHandle lh)
- throws BKException, InterruptedException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a ledger handle for a previously created and open ledger.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public LedgerInputStream(LedgerHandle lh, int size)
- throws BKException, InterruptedException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">lh</span> is a ledger handle for a previously created and open ledger.
- </p>
-
- </li>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">size</span> is the size of the byte buffer to store bytes that the application
- will eventually read.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <strong>Closing.</strong> There is one call to close an input stream, but the call
- is currently empty and the application is responsible for closing the ledger handle.
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public void close()
- </span>
-
- </p>
- <p>
- which has no parameters.
- </p>
- <p>
-
- <strong>Reading.</strong> There are three calls to read from the stream.
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized int read()
- throws IOException
- </span>
-
- </p>
- <p>
- which has no parameters.
- </p>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized int read(byte[] b)
- throws IOException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">b</span> is a byte array to write to.
- </p>
-
- </li>
-
- </ul>
- <p>
-
- <span class="codefrag computeroutput">
- public synchronized int read(byte[] b, int off, int len)
- throws IOException
- </span>
-
- </p>
- <p>
- where:
- </p>
- <ul>
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">b</span> is a byte array to write to.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">off</span> is an offset for byte array <span class="codefrag computeroutput">b</span>.
- </p>
-
- </li>
-
-
- <li>
-
- <p>
-
- <span class="codefrag computeroutput">len</span> is the length in bytes to write to <span class="codefrag computeroutput">b</span>.
- </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>
|