Skip to content

Commit

Permalink
1.0.11-SNAPSHOT
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
leonchen83 committed Sep 16, 2016
1 parent 9339bfb commit 46d29fe
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void open() throws IOException {
SyncMode syncMode = trySync(reply);
if (syncMode == SyncMode.PSYNC) {
//heart beat send REPLCONF ACK ${slave offset}

heartBeat = new Timer("heart beat");
heartBeat.schedule(new TimerTask() {
@Override
Expand All @@ -100,11 +101,10 @@ public void run() {
send("REPLCONF".getBytes(), "ACK".getBytes(), String.valueOf(configuration.getOffset()).getBytes());
} catch (IOException e) {
//NOP
logger.error("error", e);
}

}
}, configuration.getHeartBeatDelay(), configuration.getHeartBeatPeriod());
logger.info("heart beat started.");
}
//sync command
while (connected.get()) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public void handle(long len) {
//connected = false
break;
} catch (SocketException | SocketTimeoutException | InterruptedException | EOFException e) {
logger.error(e);
logger.error("socket error", e);
//close socket manual
if (!connected.get()) {
break;
Expand All @@ -152,7 +152,7 @@ public void handle(long len) {
//server disconnect connection EOFException
close();
//retry psync in next loop.
logger.info("retry connect to redis.");
logger.info("reconnect to redis-server. retry times:" + i);
try {
Thread.sleep(configuration.getRetryTimeInterval());
} catch (InterruptedException e1) {
Expand Down Expand Up @@ -305,15 +305,28 @@ private void connect() throws IOException {
}

@Override
public void close() throws IOException {
public void close() {
if (!connected.compareAndSet(true, false)) return;
if (heartBeat != null) {
heartBeat.cancel();
heartBeat = null;
logger.info("heart beat canceled.");
}
try {
if (inputStream != null) inputStream.close();
} catch (IOException e) {
//NOP
}
try {
if (outputStream != null) outputStream.close();
} catch (IOException e) {
//NOP
}
try {
if (socket != null && !socket.isClosed()) socket.close();
} catch (IOException e) {
//NOP
}
if (inputStream != null) inputStream.close();
if (outputStream != null) outputStream.close();
if (socket != null && !socket.isClosed()) socket.close();
doCloseListener();
logger.info("channel closed");
}
Expand Down

0 comments on commit 46d29fe

Please sign in to comment.