blob: 7ecc01d9f288c0ec370683b751eb27be4ef795fa [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc -->
<title>Source.Reader (Apache Beam 2.38.0-SNAPSHOT)</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Source.Reader (Apache Beam 2.38.0-SNAPSHOT)";
}
}
catch(err) {
}
//-->
var methods = {"i0":6,"i1":6,"i2":6,"i3":6,"i4":6,"i5":6};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/beam/sdk/io/TextIO.html" title="class in org.apache.beam.sdk.io"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/beam/sdk/io/Source.Reader.html" target="_top">Frames</a></li>
<li><a href="Source.Reader.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.beam.sdk.io</div>
<h2 title="Class Source.Reader" class="title">Class Source.Reader&lt;T&gt;</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>org.apache.beam.sdk.io.Source.Reader&lt;T&gt;</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd>java.lang.AutoCloseable</dd>
</dl>
<dl>
<dt>Direct Known Subclasses:</dt>
<dd><a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html" title="class in org.apache.beam.sdk.io">BoundedSource.BoundedReader</a>, <a href="../../../../../org/apache/beam/runners/spark/io/MicrobatchSource.Reader.html" title="class in org.apache.beam.runners.spark.io">MicrobatchSource.Reader</a>, <a href="../../../../../org/apache/beam/sdk/io/UnboundedSource.UnboundedReader.html" title="class in org.apache.beam.sdk.io">UnboundedSource.UnboundedReader</a></dd>
</dl>
<dl>
<dt>Enclosing class:</dt>
<dd><a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io">Source</a>&lt;<a href="../../../../../org/apache/beam/sdk/io/Source.html" title="type parameter in Source">T</a>&gt;</dd>
</dl>
<hr>
<br>
<pre>public abstract static class <span class="typeNameLabel">Source.Reader&lt;T&gt;</span>
extends java.lang.Object
implements java.lang.AutoCloseable</pre>
<div class="block">The interface that readers of custom input sources must implement.
<p>This interface is deliberately distinct from <code>Iterator</code> because the current
model tends to be easier to program and more efficient in practice for iterating over sources
such as files, databases etc. (rather than pure collections).
<p>Reading data from the <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io"><code>Source.Reader</code></a> must obey the following access pattern:
<ul>
<li>One call to <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a>
<ul>
<li>If <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> returned true, any number of calls to <code>getCurrent</code>* methods
</ul>
<li>Repeatedly, a call to <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a>. This may be called regardless of what the
previous <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a>/<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> returned.
<ul>
<li>If <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> returned true, any number of calls to <code>getCurrent</code>*
methods
</ul>
</ul>
<p>For example, if the reader is reading a fixed set of data:
<pre>
try {
for (boolean available = reader.start(); available; available = reader.advance()) {
T item = reader.getCurrent();
Instant timestamp = reader.getCurrentTimestamp();
...
}
} finally {
reader.close();
}
</pre>
<p>If the set of data being read is continually growing:
<pre>
try {
boolean available = reader.start();
while (true) {
if (available) {
T item = reader.getCurrent();
Instant timestamp = reader.getCurrentTimestamp();
...
resetExponentialBackoff();
} else {
exponentialBackoff();
}
available = reader.advance();
}
} finally {
reader.close();
}
</pre>
<p>Note: this interface is a work-in-progress and may change.
<p>All <code>Reader</code> functions except <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrentSource--"><code>getCurrentSource()</code></a> do not need to be thread-safe;
they may only be accessed by a single thread at once. However, <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrentSource--"><code>getCurrentSource()</code></a> needs
to be thread-safe, and other functions should assume that its returned value can change
asynchronously.</div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#Reader--">Reader</a></span>()</code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>abstract boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--">advance</a></span>()</code>
<div class="block">Advances the reader to the next valid record.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>abstract void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#close--">close</a></span>()</code>
<div class="block">Closes the reader.</div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>abstract <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="type parameter in Source.Reader">T</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrent--">getCurrent</a></span>()</code>
<div class="block">Returns the value of the data item that was read by the last <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> or <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> call.</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>abstract <a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io">Source</a>&lt;<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="type parameter in Source.Reader">T</a>&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrentSource--">getCurrentSource</a></span>()</code>
<div class="block">Returns a <code>Source</code> describing the same input that this <code>Reader</code> currently reads
(including items already read).</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>abstract <a href="https://static.javadoc.io/joda-time/joda-time/2.10.10/org/joda/time/Instant.html?is-external=true" title="class or interface in org.joda.time">Instant</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrentTimestamp--">getCurrentTimestamp</a></span>()</code>
<div class="block">Returns the timestamp associated with the current data item.</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>abstract boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--">start</a></span>()</code>
<div class="block">Initializes the reader and advances the reader to the first record.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="Reader--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>Reader</h4>
<pre>public&nbsp;Reader()</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="start--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>start</h4>
<pre>public abstract&nbsp;boolean&nbsp;start()
throws java.io.IOException</pre>
<div class="block">Initializes the reader and advances the reader to the first record.
<p>This method should be called exactly once. The invocation should occur prior to calling
<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> or <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrent--"><code>getCurrent()</code></a>. This method may perform expensive operations that
are needed to initialize the reader.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd><code>true</code> if a record was read, <code>false</code> if there is no more input available.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="advance--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>advance</h4>
<pre>public abstract&nbsp;boolean&nbsp;advance()
throws java.io.IOException</pre>
<div class="block">Advances the reader to the next valid record.
<p>It is an error to call this without having called <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> first.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd><code>true</code> if a record was read, <code>false</code> if there is no more input available.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="getCurrent--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getCurrent</h4>
<pre>public abstract&nbsp;<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="type parameter in Source.Reader">T</a>&nbsp;getCurrent()
throws java.util.NoSuchElementException</pre>
<div class="block">Returns the value of the data item that was read by the last <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> or <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> call. The returned value must be effectively immutable and remain valid
indefinitely.
<p>Multiple calls to this method without an intervening call to <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> should
return the same result.</div>
<dl>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.util.NoSuchElementException</code> - if <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> was never called, or if the last
<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> or <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> returned <code>false</code>.</dd>
</dl>
</li>
</ul>
<a name="getCurrentTimestamp--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getCurrentTimestamp</h4>
<pre>public abstract&nbsp;<a href="https://static.javadoc.io/joda-time/joda-time/2.10.10/org/joda/time/Instant.html?is-external=true" title="class or interface in org.joda.time">Instant</a>&nbsp;getCurrentTimestamp()
throws java.util.NoSuchElementException</pre>
<div class="block">Returns the timestamp associated with the current data item.
<p>If the source does not support timestamps, this should return <code>BoundedWindow.TIMESTAMP_MIN_VALUE</code>.
<p>Multiple calls to this method without an intervening call to <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> should
return the same result.</div>
<dl>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.util.NoSuchElementException</code> - if the reader is at the beginning of the input and <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> or <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> wasn't called, or if the last <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#start--"><code>start()</code></a> or <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#advance--"><code>advance()</code></a> returned <code>false</code>.</dd>
</dl>
</li>
</ul>
<a name="close--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>close</h4>
<pre>public abstract&nbsp;void&nbsp;close()
throws java.io.IOException</pre>
<div class="block">Closes the reader. The reader cannot be used after this method is called.</div>
<dl>
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.lang.AutoCloseable</code></dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="getCurrentSource--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>getCurrentSource</h4>
<pre>public abstract&nbsp;<a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io">Source</a>&lt;<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="type parameter in Source.Reader">T</a>&gt;&nbsp;getCurrentSource()</pre>
<div class="block">Returns a <code>Source</code> describing the same input that this <code>Reader</code> currently reads
(including items already read).
<p>Usually, an implementation will simply return the immutable <a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io"><code>Source</code></a> object from
which the current <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io"><code>Source.Reader</code></a> was constructed, or delegate to the base class. However,
when using or implementing this method on a <a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html" title="class in org.apache.beam.sdk.io"><code>BoundedSource.BoundedReader</code></a>, special
considerations apply, see documentation for <a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#getCurrentSource--"><code>BoundedSource.BoundedReader.getCurrentSource()</code></a>.</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/beam/sdk/io/TextIO.html" title="class in org.apache.beam.sdk.io"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/beam/sdk/io/Source.Reader.html" target="_top">Frames</a></li>
<li><a href="Source.Reader.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>