I
- type of values produced by this inputpublic abstract class InputReader<I> extends Object implements Serializable
Created by Input
to read input for a given shard. Reads input for
a shard as a number of slices, where the slicing is up to the caller.
beginShard()
is called before any calls to beginSlice()
or next()
to setup the reader.
Each slice is read by calling beginSlice()
, then next()
and/or getProgress()
any number of times in any order, then
endSlice()
. Between two slices, before the first slice, or after the
final slice, the InputReader
may go through serialization and
deserialization.
If a slice is aborted, there is no guarantee whether endSlice()
will be called; however, if it is not called, the InputReader
will
not be serialized. If the slice is retried later, the InputReader
serialized after the previous slice will be deserialized again.
At the end of the final slice, endShard()
will be called after endSlice()
.
Constructor and Description |
---|
InputReader() |
Modifier and Type | Method and Description |
---|---|
void |
beginShard()
Performs setup at the beginning of the shard.
|
void |
beginSlice()
Prepares the
InputReader for reading, after possibly having gone
through serialization and deserialization. |
void |
close()
Deprecated.
Override endShard instead.
|
void |
endShard()
Called after endSlice if there will not be any subsequent calls to beginSlice or next.
|
void |
endSlice()
Prepares the
InputReader for serialization. |
long |
estimateMemoryRequirement()
Returns the estimated memory that will be used by this reader in bytes.
|
ShardContext |
getContext()
Returns the current context, or null if none.
|
Double |
getProgress()
Returns the relative progress reading this input as a number from 0 to 1.
|
abstract I |
next()
Returns the next input value, or throws
NoSuchElementException
when there is no more input data. |
void |
open()
Deprecated.
Override beginShard instead.
|
void |
setContext(ShardContext context)
Used internally to sets the context to be used for the processing that follows.
|
public void setContext(ShardContext context)
public ShardContext getContext()
public abstract I next() throws IOException, NoSuchElementException
NoSuchElementException
when there is no more input data. This is done rather than providing a
hasNext() function, to allow the implementation to deal with streams and
remain serializable, even if the item being read is not.IOException
NoSuchElementException
public Double getProgress()
public void beginSlice() throws IOException
InputReader
for reading, after possibly having gone
through serialization and deserialization.IOException
- in the event of failurepublic void endSlice() throws IOException
InputReader
for serialization.IOException
- in the event of failure@Deprecated public void open() throws IOException
IOException
- in the event of failurepublic void beginShard() throws IOException
beginSlice()
. It will not be invoked again unless the shard restarts. When a shard is
restarted, this method is invoked and the input should be read from the beginning.IOException
- in the event of failure@Deprecated public void close() throws IOException
IOException
- in the event of failurepublic void endShard() throws IOException
IOException
- in the event of failurepublic long estimateMemoryRequirement()
Copyright © 2015 Google. All rights reserved.