flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-2536][streaming]add a re-connect for so...
Date Mon, 24 Aug 2015 13:31:07 GMT
Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1030#discussion_r37750633
  
    --- Diff: flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/functions/sink/SocketClientSink.java
---
    @@ -73,13 +85,49 @@ public void intializeConnection() {
     	 *			The incoming data
     	 */
     	@Override
    -	public void invoke(IN value) {
    +	public void invoke(IN value) throws Exception {
     		byte[] msg = schema.serialize(value);
     		try {
     			dataOutputStream.write(msg);
     		} catch (IOException e) {
    -			throw new RuntimeException("Cannot send message " + value.toString() +
    -					" to socket server at " + hostName + ":" + port, e);
    +			Log.error("Cannot send message " + value.toString() +
    +					" to socket server at " + hostName + ":" + port + ". Caused by " + e.toString()
+
    +					". Trying to reconnect.");
    +			retries = 0;
    +			boolean success = false;
    +			while ((retries < maxRetry || retryForever) && !success && isRunning){
    +				try {
    +
    +					if (dataOutputStream != null) {
    +						dataOutputStream.close();
    +					}
    +
    +					if (client != null && !client.isClosed()) {
    +						client.close();
    +					}
    +
    +					if (!retryForever){
    +						retries++;
    +					}
    +
    +					client = new Socket(hostName, port);
    +					dataOutputStream = new DataOutputStream(client.getOutputStream());
    +					dataOutputStream.write(msg);
    +					success = true;
    +
    +				} catch(IOException ee) {
    +					Log.error("Reconnect to socket server and send message failed. Caused by " +
    +								ee.toString() + ". Retry time(s):" + retries);
    +					synchronized (this) {
    --- End diff --
    
    Locking on `this` is usually not recommended because outside code can influence your behaviour
here. Thus, use a private lock field here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message