refactoring
This commit is contained in:
parent
f68158c550
commit
e318b49c2d
@ -209,11 +209,11 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
|
|||||||
this.lastActivityTime = System.currentTimeMillis();
|
this.lastActivityTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void sendPing() {
|
synchronized void sendPing(long currentTime) {
|
||||||
try {
|
try {
|
||||||
if (System.currentTimeMillis() - lastActivityTime >= pingTimeout) {
|
if (currentTime - lastActivityTime >= pingTimeout) {
|
||||||
this.asyncRemote.sendPing(ByteBuffer.wrap(new byte[]{}));
|
this.asyncRemote.sendPing(ByteBuffer.wrap(new byte[]{}));
|
||||||
lastActivityTime = System.currentTimeMillis();
|
lastActivityTime = currentTime;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.trace("[{}] Failed to send ping msg", session.getId(), e);
|
log.trace("[{}] Failed to send ping msg", session.getId(), e);
|
||||||
@ -313,13 +313,13 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPing(TelemetryWebSocketSessionRef sessionRef) throws IOException {
|
public void sendPing(TelemetryWebSocketSessionRef sessionRef, long currentTime) throws IOException {
|
||||||
String externalId = sessionRef.getSessionId();
|
String externalId = sessionRef.getSessionId();
|
||||||
String internalId = externalSessionMap.get(externalId);
|
String internalId = externalSessionMap.get(externalId);
|
||||||
if (internalId != null) {
|
if (internalId != null) {
|
||||||
SessionMetaData sessionMd = internalSessionMap.get(internalId);
|
SessionMetaData sessionMd = internalSessionMap.get(internalId);
|
||||||
if (sessionMd != null) {
|
if (sessionMd != null) {
|
||||||
sessionMd.sendPing();
|
sessionMd.sendPing(currentTime);
|
||||||
} else {
|
} else {
|
||||||
log.warn("[{}][{}] Failed to find session by internal id", externalId, internalId);
|
log.warn("[{}][{}] Failed to find session by internal id", externalId, internalId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -754,10 +754,11 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPing() {
|
private void sendPing() {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
wsSessionsMap.values().forEach(md ->
|
wsSessionsMap.values().forEach(md ->
|
||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
try {
|
try {
|
||||||
msgEndpoint.sendPing(md.getSessionRef());
|
msgEndpoint.sendPing(md.getSessionRef(), currentTime);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("[{}] Failed to send ping: {}", md.getSessionRef().getSessionId(), e);
|
log.warn("[{}] Failed to send ping: {}", md.getSessionRef().getSessionId(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public interface TelemetryWebSocketMsgEndpoint {
|
|||||||
|
|
||||||
void send(TelemetryWebSocketSessionRef sessionRef, int subscriptionId, String msg) throws IOException;
|
void send(TelemetryWebSocketSessionRef sessionRef, int subscriptionId, String msg) throws IOException;
|
||||||
|
|
||||||
void sendPing(TelemetryWebSocketSessionRef sessionRef) throws IOException;
|
void sendPing(TelemetryWebSocketSessionRef sessionRef, long currentTime) throws IOException;
|
||||||
|
|
||||||
void close(TelemetryWebSocketSessionRef sessionRef, CloseStatus withReason) throws IOException;
|
void close(TelemetryWebSocketSessionRef sessionRef, CloseStatus withReason) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user