Class SocketSource
- java.lang.Object
-
- org.apache.flink.table.examples.java.connectors.SocketSource
-
- All Implemented Interfaces:
Serializable
,Source<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>
,SourceReaderFactory<RowData,SocketSource.DummySplit>
,ResultTypeQueryable<RowData>
public final class SocketSource extends Object implements Source<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>, ResultTypeQueryable<RowData>
TheSocketSource
opens a socket and consumes bytes.It splits records by the given byte delimiter (`\n` by default) and delegates the decoding to a pluggable
DeserializationSchema
.Note: This is only an example and should not be used in production. The source is not fault-tolerant and can only work with a parallelism of 1.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SocketSource.DummyCheckpoint
Placeholder because the SocketSource does not support fault-tolerance and thus does not require actual checkpointing.static class
SocketSource.DummySplit
Placeholder because the socket itself implicitly represents the only split and does not require an actual split object.
-
Constructor Summary
Constructors Constructor Description SocketSource(String hostname, int port, byte byteDelimiter, DeserializationSchema<RowData> deserializer)
-
Method Summary
-
-
-
Constructor Detail
-
SocketSource
public SocketSource(String hostname, int port, byte byteDelimiter, DeserializationSchema<RowData> deserializer)
-
-
Method Detail
-
getProducedType
public TypeInformation<RowData> getProducedType()
Description copied from interface:ResultTypeQueryable
Gets the data type (as aTypeInformation
) produced by this function or input format.- Specified by:
getProducedType
in interfaceResultTypeQueryable<RowData>
- Returns:
- The data type produced by this function or input format.
-
getBoundedness
public Boundedness getBoundedness()
Description copied from interface:Source
Get the boundedness of this source.- Specified by:
getBoundedness
in interfaceSource<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>
- Returns:
- the boundedness of this source.
-
createEnumerator
public SplitEnumerator<SocketSource.DummySplit,SocketSource.DummyCheckpoint> createEnumerator(SplitEnumeratorContext<SocketSource.DummySplit> enumContext) throws Exception
Description copied from interface:Source
Creates a new SplitEnumerator for this source, starting a new input.- Specified by:
createEnumerator
in interfaceSource<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>
- Parameters:
enumContext
- Thecontext
for the split enumerator.- Returns:
- A new SplitEnumerator.
- Throws:
Exception
- The implementor is free to forward all exceptions directly. Exceptions thrown from this method cause JobManager failure/recovery.
-
restoreEnumerator
public SplitEnumerator<SocketSource.DummySplit,SocketSource.DummyCheckpoint> restoreEnumerator(SplitEnumeratorContext<SocketSource.DummySplit> enumContext, SocketSource.DummyCheckpoint checkpoint) throws Exception
Description copied from interface:Source
Restores an enumerator from a checkpoint.- Specified by:
restoreEnumerator
in interfaceSource<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>
- Parameters:
enumContext
- Thecontext
for the restored split enumerator.checkpoint
- The checkpoint to restore the SplitEnumerator from.- Returns:
- A SplitEnumerator restored from the given checkpoint.
- Throws:
Exception
- The implementor is free to forward all exceptions directly. Exceptions thrown from this method cause JobManager failure/recovery.
-
getSplitSerializer
public SimpleVersionedSerializer<SocketSource.DummySplit> getSplitSerializer()
Description copied from interface:Source
Creates a serializer for the source splits. Splits are serialized when sending them from enumerator to reader, and when checkpointing the reader's current state.- Specified by:
getSplitSerializer
in interfaceSource<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>
- Returns:
- The serializer for the split type.
-
getEnumeratorCheckpointSerializer
public SimpleVersionedSerializer<SocketSource.DummyCheckpoint> getEnumeratorCheckpointSerializer()
Description copied from interface:Source
Creates the serializer for theSplitEnumerator
checkpoint. The serializer is used for the result of theSplitEnumerator.snapshotState(long)
method.- Specified by:
getEnumeratorCheckpointSerializer
in interfaceSource<RowData,SocketSource.DummySplit,SocketSource.DummyCheckpoint>
- Returns:
- The serializer for the SplitEnumerator checkpoint.
-
createReader
public SourceReader<RowData,SocketSource.DummySplit> createReader(SourceReaderContext readerContext) throws Exception
Description copied from interface:SourceReaderFactory
Creates a new reader to read data from the splits it gets assigned. The reader starts fresh and does not have any state to resume.- Specified by:
createReader
in interfaceSourceReaderFactory<RowData,SocketSource.DummySplit>
- Parameters:
readerContext
- Thecontext
for the source reader.- Returns:
- A new SourceReader.
- Throws:
Exception
- The implementor is free to forward all exceptions directly. Exceptions thrown from this method cause task failure/recovery.
-
-