Class SocketStreamIterator<T>
java.lang.Object
org.apache.flink.streaming.experimental.SocketStreamIterator<T>
- Type Parameters:
T- The type of elements returned from the iterator.
- All Implemented Interfaces:
Iterator<T>
An iterator that returns the data from a socket stream.
The iterator's constructor opens a server socket. In the first call to next() or
hasNext(), the iterator waits for a socket to connect, and starts receiving,
deserializing, and returning the data from that socket.
This experimental class is relocated from flink-streaming-contrib. Please see package-info.java for more information.
-
Constructor Summary
ConstructorsConstructorDescriptionSocketStreamIterator(int port, InetAddress address, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) Creates an iterator that returns the data from a socket stream with custom port and bind address.SocketStreamIterator(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) Creates an iterator that returns the data from a socket stream with automatic port and bind address. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
SocketStreamIterator
public SocketStreamIterator(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) throws IOException Creates an iterator that returns the data from a socket stream with automatic port and bind address.- Parameters:
serializer- serializer used for deserializing incoming records- Throws:
IOException- thrown if socket cannot be opened
-
SocketStreamIterator
public SocketStreamIterator(int port, InetAddress address, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) throws IOException Creates an iterator that returns the data from a socket stream with custom port and bind address.- Parameters:
port- port for the socket connection (0 means automatic port selection)address- address for the socket connectionserializer- serializer used for deserializing incoming records- Throws:
IOException- thrown if socket cannot be opened
-
-
Method Details
-
getPort
public int getPort()Returns the port on which the iterator is getting the data. (Used internally.)- Returns:
- The port
-
getBindAddress
-
close
public void close() -
hasNext
public boolean hasNext()Returns true if the DataStream has more elements. (Note: blocks if there will be more elements, but they are not available yet.) -
next
Returns the next element of the DataStream. (Blocks if it is not available yet.)- Specified by:
nextin interfaceIterator<T>- Returns:
- The element
- Throws:
NoSuchElementException- if the stream has already ended
-
remove
public void remove() -
notifyOfError
-