Class SocketClientSink<IN>

  • Type Parameters:
    IN - data to be written into the Socket.
    All Implemented Interfaces:
    Serializable, Function, RichFunction, SinkFunction<IN>

    @Internal
    public class SocketClientSink<IN>
    extends RichSinkFunction<IN>
    Deprecated.
    This interface will be removed in future versions. Use the new Sink interface instead.
    Socket client that acts as a streaming sink. The data is sent to a Socket as a byte array.

    The sink can be set to retry message sends after the sending failed.

    The sink can be set to 'autoflush', in which case the socket stream is flushed after every message. This significantly reduced throughput, but also decreases message latency.

    See Also:
    Serialized Form
    • Constructor Detail

      • SocketClientSink

        public SocketClientSink​(String hostName,
                                int port,
                                SerializationSchema<IN> schema)
        Deprecated.
        Creates a new SocketClientSink. The sink will not attempt to retry connections upon failure and will not auto-flush the stream.
        Parameters:
        hostName - Hostname of the server to connect to.
        port - Port of the server.
        schema - Schema used to serialize the data into bytes.
      • SocketClientSink

        public SocketClientSink​(String hostName,
                                int port,
                                SerializationSchema<IN> schema,
                                int maxNumRetries)
        Deprecated.
        Creates a new SocketClientSink that retries connections upon failure up to a given number of times. A value of -1 for the number of retries will cause the system to retry an infinite number of times. The sink will not auto-flush the stream.
        Parameters:
        hostName - Hostname of the server to connect to.
        port - Port of the server.
        schema - Schema used to serialize the data into bytes.
        maxNumRetries - The maximum number of retries after a message send failed.
      • SocketClientSink

        public SocketClientSink​(String hostName,
                                int port,
                                SerializationSchema<IN> schema,
                                int maxNumRetries,
                                boolean autoflush)
        Deprecated.
        Creates a new SocketClientSink that retries connections upon failure up to a given number of times. A value of -1 for the number of retries will cause the system to retry an infinite number of times.
        Parameters:
        hostName - Hostname of the server to connect to.
        port - Port of the server.
        schema - Schema used to serialize the data into bytes.
        maxNumRetries - The maximum number of retries after a message send failed.
        autoflush - Flag to indicate whether the socket stream should be flushed after each message.
    • Method Detail

      • open

        public void open​(OpenContext openContext)
                  throws Exception
        Deprecated.
        Description copied from interface: RichFunction
        Initialization method for the function. It is called before the actual working methods (like map or join) and thus suitable for one time setup work. For functions that are part of an iteration, this method will be invoked at the beginning of each iteration superstep.

        The openContext object passed to the function can be used for configuration and initialization. The openContext contains some necessary information that were configured on the function in the program composition.

        
         public class MyFilter extends RichFilterFunction<String> {
        
             private String searchString;
        
             public void open(OpenContext openContext) {
                 // initialize the value of searchString
             }
        
             public boolean filter(String value) {
                 return value.equals(searchString);
             }
         }
         
        Specified by:
        open in interface RichFunction
        Overrides:
        open in class AbstractRichFunction
        Parameters:
        openContext - The context containing information about the context in which the function is opened.
        Throws:
        Exception - Implementations may forward exceptions, which are caught by the runtime. When the runtime catches an exception, it aborts the task and lets the fail-over logic decide whether to retry the task execution.
      • invoke

        public void invoke​(IN value)
                    throws Exception
        Deprecated.
        Called when new data arrives to the sink, and forwards it to Socket.
        Parameters:
        value - The value to write to the socket.
        Throws:
        Exception
      • close

        public void close()
                   throws Exception
        Deprecated.
        Closes the connection with the Socket server.
        Specified by:
        close in interface RichFunction
        Overrides:
        close in class AbstractRichFunction
        Throws:
        Exception - Implementations may forward exceptions, which are caught by the runtime. When the runtime catches an exception, it aborts the task and lets the fail-over logic decide whether to retry the task execution.
      • getCurrentNumberOfRetries

        @VisibleForTesting
        public int getCurrentNumberOfRetries()
        Deprecated.