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>
@Experimental public class SocketStreamIterator<T> extends Object implements 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()
orhasNext()
, 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
Constructors Constructor Description SocketStreamIterator(int port, InetAddress address, TypeSerializer<T> serializer)
Creates an iterator that returns the data from a socket stream with custom port and bind address.SocketStreamIterator(TypeSerializer<T> serializer)
Creates an iterator that returns the data from a socket stream with automatic port and bind address.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
InetAddress
getBindAddress()
int
getPort()
Returns the port on which the iterator is getting the data.boolean
hasNext()
Returns true if the DataStream has more elements.T
next()
Returns the next element of the DataStream.void
notifyOfError(Throwable error)
void
remove()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
SocketStreamIterator
public SocketStreamIterator(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, 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 Detail
-
getPort
public int getPort()
Returns the port on which the iterator is getting the data. (Used internally.)- Returns:
- The port
-
getBindAddress
public InetAddress 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
public T next()
Returns the next element of the DataStream. (Blocks if it is not available yet.)- Specified by:
next
in interfaceIterator<T>
- Returns:
- The element
- Throws:
NoSuchElementException
- if the stream has already ended
-
notifyOfError
public void notifyOfError(Throwable error)
-
-