public class StatefulSequenceSource extends RichParallelSourceFunction<Long> implements Checkpointed<Long>
SourceFunction.SourceContext<T>| Constructor and Description |
|---|
StatefulSequenceSource(long start,
long end)
Creates a source that emits all numbers from the given interval exactly once.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels the source.
|
void |
restoreState(Long state)
Restores the state of the function or operator to that of a previous checkpoint.
|
void |
run(SourceFunction.SourceContext<Long> ctx)
Starts the source.
|
Long |
snapshotState(long checkpointId,
long checkpointTimestamp)
Gets the current state of the function of operator.
|
close, getIterationRuntimeContext, getRuntimeContext, open, setRuntimeContextpublic StatefulSequenceSource(long start,
long end)
start - Start of the range of numbers to emit.end - End of the range of numbers to emit.public void run(SourceFunction.SourceContext<Long> ctx) throws Exception
SourceFunctionCollector parameter to emit
elements. Sources that implement
Checkpointed must lock on the
checkpoint lock (using a synchronized block) before updating internal state and/or emitting
elements. Also, the update of state and emission of elements must happen in the same
synchronized block.run in interface SourceFunction<Long>ctx - The context for interaction with the outside world.Exceptionpublic void cancel()
SourceFunctionSourceFunction.run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T>) method. You need to ensure that the source will break out of this loop. This
can be achieved by having a volatile field "isRunning" that is checked in the loop and that
is set to false in this method.cancel in interface SourceFunction<Long>public Long snapshotState(long checkpointId, long checkpointTimestamp)
CheckpointedsnapshotState in interface Checkpointed<Long>checkpointId - The ID of the checkpoint.checkpointTimestamp - The timestamp of the checkpoint, as derived by
System.currentTimeMillis() on the JobManager.public void restoreState(Long state)
CheckpointedrestoreState in interface Checkpointed<Long>state - The state to be restored.Copyright © 2014–2016 The Apache Software Foundation. All rights reserved.