@@ -133,6 +133,8 @@ protected static void cancelCommandOnEndpointClose(RedisCommand<?, ?, ?> cmd) {
133
133
134
134
protected volatile @ Nonnull ContextualChannel channel = DummyContextualChannelInstances .CHANNEL_CONNECTING ;
135
135
136
+ private volatile Throwable failedToReconnectReason ;
137
+
136
138
private final Consumer <RedisCommand <?, ?, ?>> callbackOnClose ;
137
139
138
140
private final boolean rejectCommandsWhileDisconnected ;
@@ -153,19 +155,17 @@ protected static void cancelCommandOnEndpointClose(RedisCommand<?, ?, ?> cmd) {
153
155
154
156
private ConnectionFacade connectionFacade ;
155
157
156
- private volatile Throwable connectionError ;
157
-
158
158
private final String cachedEndpointId ;
159
159
160
160
protected final UnboundedOfferFirstQueue <Object > taskQueue ;
161
161
162
162
private final boolean canFire ;
163
163
164
- private volatile boolean inProtectMode ;
164
+ private volatile EventLoop lastEventLoop = null ;
165
165
166
- private volatile Throwable failedToReconnectReason ;
166
+ private volatile Throwable connectionError ;
167
167
168
- private volatile EventLoop lastEventLoop = null ;
168
+ private volatile boolean inProtectMode ;
169
169
170
170
private final int writeSpinCount ;
171
171
@@ -316,17 +316,16 @@ private <V, K> void writeAndFlushActivationCommands(ContextualChannel chan,
316
316
@ Override
317
317
public void notifyChannelActive (Channel channel ) {
318
318
final ContextualChannel contextualChannel = new ContextualChannel (channel , ConnectionContext .State .CONNECTED );
319
-
320
- this .logPrefix = null ;
321
- this .connectionError = null ;
322
-
323
319
if (!CHANNEL .compareAndSet (this , DummyContextualChannelInstances .CHANNEL_CONNECTING , contextualChannel )) {
324
320
channel .close ();
325
321
onUnexpectedState ("notifyChannelActive" , ConnectionContext .State .CONNECTING );
326
322
return ;
327
323
}
328
324
329
- lastEventLoop = channel .eventLoop ();
325
+ this .lastEventLoop = channel .eventLoop ();
326
+ this .connectionError = null ;
327
+ this .inProtectMode = false ;
328
+ this .logPrefix = null ;
330
329
331
330
// Created a synchronize-before with set channel to CHANNEL_CONNECTING,
332
331
if (isClosed ()) {
@@ -398,7 +397,7 @@ public void notifyChannelInactive(Channel channel) {
398
397
399
398
@ Override
400
399
public void notifyChannelInactiveAfterWatchdogDecision (Channel channel ,
401
- Deque <RedisCommand <?, ?, ?>> retryableQueuedCommands ) {
400
+ Deque <RedisCommand <?, ?, ?>> retryablePendingCommands ) {
402
401
final ContextualChannel inactiveChan = this .channel ;
403
402
if (!inactiveChan .context .initialState .isConnected ()) {
404
403
logger .error ("[unexpected][{}] notifyChannelInactive: channel initial state not connected" , logPrefix ());
@@ -446,7 +445,7 @@ public void notifyChannelInactiveAfterWatchdogDecision(Channel channel,
446
445
CHANNEL .set (this , DummyContextualChannelInstances .CHANNEL_ENDPOINT_CLOSED );
447
446
}
448
447
inactiveChan .context
449
- .setCloseStatus (new ConnectionContext .CloseStatus (willReconnect , retryableQueuedCommands , exception ));
448
+ .setCloseStatus (new ConnectionContext .CloseStatus (willReconnect , retryablePendingCommands , exception ));
450
449
trySetEndpointQuiescence (inactiveChan );
451
450
}
452
451
@@ -945,11 +944,11 @@ private <K, V, T> RedisCommand<K, V, T> processActivationCommand(RedisCommand<K,
945
944
946
945
private Throwable validateWrite (ContextualChannel chan , int commands , boolean isActivationCommand ) {
947
946
if (isClosed ()) {
948
- return new RedisException ("Connection is closed" );
947
+ return new RedisException ("Endpoint is closed" );
949
948
}
950
949
951
950
final Throwable localConnectionErr = connectionError ;
952
- if (localConnectionErr != null /* different logic of DefaultEndpoint */ ) {
951
+ if (localConnectionErr != null /* attention: different logic of DefaultEndpoint */ ) {
953
952
return localConnectionErr ;
954
953
}
955
954
@@ -961,18 +960,19 @@ private Throwable validateWrite(ContextualChannel chan, int commands, boolean is
961
960
962
961
final ConnectionContext .State initialState = chan .context .initialState ;
963
962
final boolean rejectCommandsWhileDisconnectedLocal = this .rejectCommandsWhileDisconnected || isActivationCommand ;
963
+ final String rejectDesc = isActivationCommand ? "isActivationCommand" : "rejectCommandsWhileDisconnected" ;
964
964
switch (initialState ) {
965
965
case ENDPOINT_CLOSED :
966
966
return new RedisException ("Connection is closed" );
967
967
case RECONNECT_FAILED :
968
- return failedToReconnectReason ;
968
+ return getFailedToReconnectReason () ;
969
969
case WILL_RECONNECT :
970
970
case CONNECTING :
971
- return rejectCommandsWhileDisconnectedLocal
972
- ? new RedisException ("Currently not connected. Commands are rejected." )
971
+ return rejectCommandsWhileDisconnectedLocal ? new RedisException ("Currently not connected and " + rejectDesc )
973
972
: null ;
974
973
case CONNECTED :
975
- return !chan .isActive () && rejectCommandsWhileDisconnectedLocal ? new RedisException ("Channel is closed" )
974
+ return !chan .isActive () && rejectCommandsWhileDisconnectedLocal
975
+ ? new RedisException ("Channel is inactive and " + rejectDesc )
976
976
: null ;
977
977
default :
978
978
throw new IllegalStateException ("unexpected state: " + initialState );
0 commit comments