Skip to content

Commit

Permalink
refactor: better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
okg-cxf committed Aug 8, 2024
1 parent 2b57334 commit 19e6463
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,9 @@ public int getFlyingCmdNum() {
return flyingCmdNum;
}

private int total = 0;

public int getTotal() {
return total;
}

public final HasOngoingSendLoop hasOngoingSendLoop = new HasOngoingSendLoop();

public void add(int n) {
this.total += n;
this.flyingCmdNum += n;
}

Expand All @@ -100,7 +93,7 @@ public void done(int n) {

public boolean isDone() {
if (this.flyingCmdNum < 0) {
logger.error("[unexpected] flyingCmdNum < 0, flyingCmdNum: {}, total: {}", this.flyingCmdNum, this.total);
logger.error("[unexpected] flyingCmdNum < 0, flyingCmdNum: {}", this.flyingCmdNum);
return true;
}
return this.flyingCmdNum == 0;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/io/lettuce/core/protocol/ConnectionWatchdog.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class ConnectionWatchdog extends ChannelInboundHandlerAdapter {

private volatile Timeout reconnectScheduleTimeout;

private Runnable doReconnectOnEndpointQuiescence;
private Runnable doReconnectOnAutoBatchFlushEndpointQuiescence;

/**
* Create a new watchdog that adds to new connections to the supplied {@link ChannelGroup} and establishes a new
Expand Down Expand Up @@ -204,7 +204,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
doReconnectOnEndpointQuiescence = null;
doReconnectOnAutoBatchFlushEndpointQuiescence = null;

logger.debug("{} channelInactive()", logPrefix());
if (!armed) {
Expand All @@ -225,10 +225,10 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
return;
}

doReconnectOnEndpointQuiescence = this::scheduleReconnect;
if (!useAutoBatchFlushEndpoint) {
doReconnectOnEndpointQuiescence.run();
this.scheduleReconnect();
}
doReconnectOnAutoBatchFlushEndpointQuiescence = this::scheduleReconnect;
// otherwise, will be called later by BatchFlushEndpoint#onEndpointQuiescence
} else {
logger.debug("{} Reconnect scheduling disabled", logPrefix(), ctx);
Expand All @@ -237,8 +237,12 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
}

void reconnectOnEndpointQuiescence() {
doReconnectOnEndpointQuiescence.run();
boolean willReconnect() {
return doReconnectOnAutoBatchFlushEndpointQuiescence != null;
}

void reconnectOnAutoBatchFlushEndpointQuiescence() {
doReconnectOnAutoBatchFlushEndpointQuiescence.run();
}

/**
Expand Down Expand Up @@ -482,8 +486,4 @@ private String logPrefix() {
return logPrefix = buffer;
}

public boolean willReconnect() {
return doReconnectOnEndpointQuiescence != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void notifyReconnectFailed(Throwable t) {

if (!CHANNEL.compareAndSet(this, DummyContextualChannelInstances.CHANNEL_CONNECTING,
DummyContextualChannelInstances.CHANNEL_RECONNECT_FAILED)) {
onUnexpectedState("notifyReconnectFailed", ConnectionContext.State.CONNECTING);
syncAfterTerminated(() -> onUnexpectedState("notifyReconnectFailed", ConnectionContext.State.CONNECTING));
return;
}

Expand Down Expand Up @@ -741,7 +741,7 @@ private void onEndpointQuiescence() {
}

// neither connectionWatchdog nor doReconnectOnEndpointQuiescence could be null
connectionWatchdog.reconnectOnEndpointQuiescence();
connectionWatchdog.reconnectOnAutoBatchFlushEndpointQuiescence();
}

private void onWillReconnect(@Nonnull final ConnectionContext.CloseStatus closeStatus,
Expand Down

0 comments on commit 19e6463

Please sign in to comment.