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() 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 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 connection
      serializer - 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

      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.)
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true if the DataStream has more elements
    • next

      public T next()
      Returns the next element of the DataStream. (Blocks if it is not available yet.)
      Specified by:
      next in interface Iterator<T>
      Returns:
      The element
      Throws:
      NoSuchElementException - if the stream has already ended
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • notifyOfError

      public void notifyOfError(Throwable error)