Skip to content

Commit

Permalink
fixed unknown ConnectException on selector
Browse files Browse the repository at this point in the history
  • Loading branch information
adyliu committed May 12, 2016
1 parent d4bd939 commit 1b309a4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/com/sohu/jafka/consumer/SimpleOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@

import java.io.Closeable;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.nio.channels.ClosedByInterruptException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
* Simple operation with jafka broker
Expand Down Expand Up @@ -105,7 +109,17 @@ public KV<Receive, ErrorMapping> send(Request request) throws IOException {
reconnect();
blockingChannel.send(request);
return blockingChannel.receive();
} catch (IOException e2) {
} catch (SocketTimeoutException ste){
logger.error("Reconnect fail and recur now: {}",ste.getMessage());
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(1));
return send(request);
}
catch (ConnectException ce){
logger.error("Reconnect fail and recur now: {}",ce.getMessage());
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(1));
return send(request);
}
catch (IOException e2) {
throw e2;
}
}
Expand Down

0 comments on commit 1b309a4

Please sign in to comment.