File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed
src/main/java/com/rabbitmq/client/impl/nio Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ public void run() {
73
73
74
74
for (SelectionKey selectionKey : selector .keys ()) {
75
75
SocketChannelFrameHandlerState state = (SocketChannelFrameHandlerState ) selectionKey .attachment ();
76
- if (state .getConnection () != null && state .getConnection (). getHeartbeat () > 0 ) {
76
+ if (state .getConnection () != null && state .getHeartbeatNanoSeconds () > 0 ) {
77
77
long now = System .nanoTime ();
78
78
if ((now - state .getLastActivity ()) > state .getHeartbeatNanoSeconds () * 2 ) {
79
79
try {
Original file line number Diff line number Diff line change 24
24
import java .io .IOException ;
25
25
import java .net .InetAddress ;
26
26
import java .net .SocketException ;
27
+ import java .time .Duration ;
27
28
28
29
/**
29
30
*
@@ -61,6 +62,9 @@ public int getPort() {
61
62
@ Override
62
63
public void setTimeout (int timeoutMs ) throws SocketException {
63
64
state .getChannel ().socket ().setSoTimeout (timeoutMs );
65
+ if (state .getConnection () != null ) {
66
+ state .setHeartbeat (Duration .ofSeconds (state .getConnection ().getHeartbeat ()));
67
+ }
64
68
}
65
69
66
70
@ Override
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ public class SocketChannelFrameHandlerState {
43
43
private final NioQueue writeQueue ;
44
44
45
45
private volatile AMQConnection connection ;
46
- private volatile long heartbeat ;
46
+ private volatile long heartbeatNanoSeconds = - 1 ;
47
47
48
48
/** should be used only in the NIO read thread */
49
49
private long lastActivity ;
@@ -156,7 +156,10 @@ public AMQConnection getConnection() {
156
156
157
157
public void setConnection (AMQConnection connection ) {
158
158
this .connection = connection ;
159
- this .heartbeat = Duration .ofSeconds (connection .getHeartbeat ()).toNanos ();
159
+ }
160
+
161
+ void setHeartbeat (Duration ht ) {
162
+ this .heartbeatNanoSeconds = ht .toNanos ();
160
163
}
161
164
162
165
public void setLastActivity (long lastActivity ) {
@@ -168,7 +171,7 @@ public long getLastActivity() {
168
171
}
169
172
170
173
long getHeartbeatNanoSeconds () {
171
- return this .heartbeat ;
174
+ return this .heartbeatNanoSeconds ;
172
175
}
173
176
174
177
void prepareForWriteSequence () {
You can’t perform that action at this time.
0 commit comments