@Override public void run() { try { SocketClientSink<String> simpleSink = new SocketClientSink<>(host, port, simpleSchema, 0); simpleSink.open(new Configuration()); simpleSink.invoke(TEST_MESSAGE + '\n', SinkContextUtil.forTimestamp(0)); simpleSink.close(); } catch (Throwable t) { error.set(t); } } };
/** * Initialize the connection with the Socket in the server. * @param parameters Configuration. */ @Override public void open(Configuration parameters) throws Exception { try { synchronized (lock) { createConnection(); } } catch (IOException e) { throw new IOException("Cannot connect to socket server at " + hostName + ":" + port, e); } }
serverRunner.start(); SocketClientSink<String> simpleSink = new SocketClientSink<>(host, port, simpleSchema, 0, true); simpleSink.open(new Configuration()); simpleSink.invoke(TEST_MESSAGE + '\n', SinkContextUtil.forTimestamp(0)); assertEquals(0, simpleSink.getCurrentNumberOfRetries());
final int port = server.getLocalPort(); final SocketClientSink<String> simpleSink = new SocketClientSink<>(host, port, simpleSchema, 0, true); simpleSink.open(new Configuration()); simpleSink.close(); server.close();
/** * Writes the DataStream to a socket as a byte array. The format of the * output is specified by a {@link SerializationSchema}. * * @param hostName * host of the socket * @param port * port of the socket * @param schema * schema for serialization * @return the closed DataStream */ @PublicEvolving public DataStreamSink<T> writeToSocket(String hostName, int port, SerializationSchema<T> schema) { DataStreamSink<T> returnStream = addSink(new SocketClientSink<>(hostName, port, schema, 0)); returnStream.setParallelism(1); // It would not work if multiple instances would connect to the same port return returnStream; }
@Override public Void call() throws Exception { // Send next payload => server is down, should try to reconnect. // We need to send more than just one packet to notice the closed connection. while (retryLatch.getCount() != 0) { sink.invoke("1\n"); } return null; } };
@Override public void close() throws Exception { super.close(); LOG.info("Sink closed"); }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); this.getRuntimeContext().addAccumulator("sink counter", this.sinkCounter); this.getRuntimeContext().addAccumulator("sink hourly count", dateTimeAccumulator); LOG.info("Sink opened"); }
/** * Writes the DataStream to a socket as a byte array. The format of the * output is specified by a {@link SerializationSchema}. * * @param hostName * host of the socket * @param port * port of the socket * @param schema * schema for serialization * @return the closed DataStream */ @PublicEvolving public DataStreamSink<T> writeToSocket(String hostName, int port, SerializationSchema<T> schema) { DataStreamSink<T> returnStream = addSink(new SocketClientSink<>(hostName, port, schema, 0)); returnStream.setParallelism(1); // It would not work if multiple instances would connect to the same port return returnStream; }
@Override public void run() { try { // need two messages here: send a fin to cancel the client state:FIN_WAIT_2 while the server is CLOSE_WAIT simpleSink.invoke(TEST_MESSAGE + '\n', SinkContextUtil.forTimestamp(0)); } catch (Throwable t) { error.set(t); } } };
final SocketClientSink<String> sink = new SocketClientSink<>( host, serverSocket[0].getLocalPort(), simpleSchema, -1, true); sink.open(new Configuration()); sink.invoke("0\n", SinkContextUtil.forTimestamp(0)); assertEquals(0, sink.getCurrentNumberOfRetries()); while (sink.getCurrentNumberOfRetries() == 0) {
/** * Writes the DataStream to a socket as a byte array. The format of the * output is specified by a {@link SerializationSchema}. * * @param hostName * host of the socket * @param port * port of the socket * @param schema * schema for serialization * @return the closed DataStream */ @PublicEvolving public DataStreamSink<T> writeToSocket(String hostName, int port, SerializationSchema<T> schema) { DataStreamSink<T> returnStream = addSink(new SocketClientSink<>(hostName, port, schema, 0)); returnStream.setParallelism(1); // It would not work if multiple instances would connect to the same port return returnStream; }
@Override public void invoke(MetricHistogram histo) throws Exception { histo.done(); super.invoke(histo); this.sinkCounter.add(1); this.dateTimeAccumulator.add(formatter.format(new Date(histo.getTimestamp()))); }
/** * Initialize the connection with the Socket in the server. * @param parameters Configuration. */ @Override public void open(Configuration parameters) throws Exception { try { synchronized (lock) { createConnection(); } } catch (IOException e) { throw new IOException("Cannot connect to socket server at " + hostName + ":" + port, e); } }
/** * Writes the DataStream to a socket as a byte array. The format of the * output is specified by a {@link SerializationSchema}. * * @param hostName * host of the socket * @param port * port of the socket * @param schema * schema for serialization * @return the closed DataStream */ @PublicEvolving public DataStreamSink<T> writeToSocket(String hostName, int port, SerializationSchema<T> schema) { DataStreamSink<T> returnStream = addSink(new SocketClientSink<>(hostName, port, schema, 0)); returnStream.setParallelism(1); // It would not work if multiple instances would connect to the same port return returnStream; }
/** * Initialize the connection with the Socket in the server. * @param parameters Configuration. */ @Override public void open(Configuration parameters) throws Exception { try { synchronized (lock) { createConnection(); } } catch (IOException e) { throw new IOException("Cannot connect to socket server at " + hostName + ":" + port, e); } }
/** * Initialize the connection with the Socket in the server. * @param parameters Configuration. */ @Override public void open(Configuration parameters) throws Exception { try { synchronized (lock) { createConnection(); } } catch (IOException e) { throw new IOException("Cannot connect to socket server at " + hostName + ":" + port, e); } }