5757
5858import java .nio .channels .SocketChannel ;
5959import java .nio .charset .Charset ;
60+ import java .time .Instant ;
6061import java .util .HashMap ;
6162import java .util .List ;
6263import java .util .Map ;
@@ -167,12 +168,9 @@ public void run() {
167168 publisherThread .setDaemon (true );
168169 publisherThread .start ();
169170
170- if (heartbeatIntervalSeconds <= 0L ) {
171- logInfo ("Heartbeat is not active" );
172- }
173- else {
174- logInfo ("Heartbeat (" + heartbeatIntervalSeconds + "s) is active" );
175- }
171+ logInfo (heartbeatIntervalSeconds <= 0L
172+ ? "Heartbeat is not active"
173+ : "Heartbeat (" + heartbeatIntervalSeconds + "s) is active" );
176174
177175 // enter message request processing loop
178176 while (!isStop ()) {
@@ -872,8 +870,8 @@ private Message handleDiffieHellmanKeyExchange(final Message request) {
872870 return createPlainTextResponse (
873871 request .getId (),
874872 DIFFIE_HELLMAN_NAK ,
875- null ,
876- null ,
873+ null , // no request id
874+ null , // no destination name
877875 "" ,
878876 "Error: Diffie-Hellman key already exchanged!" );
879877 }
@@ -899,8 +897,8 @@ private Message handleDiffieHellmanKeyExchange(final Message request) {
899897 return createPlainTextResponse (
900898 request .getId (),
901899 DIFFIE_HELLMAN_ACK ,
902- null ,
903- null ,
900+ null , // no request id
901+ null , // no destination name
904902 "" ,
905903 dhKeys .getPublicKeyBase64 ());
906904 }
@@ -910,8 +908,8 @@ private Message handleDiffieHellmanKeyExchange(final Message request) {
910908 return createPlainTextResponse (
911909 request .getId (),
912910 DIFFIE_HELLMAN_NAK ,
913- null ,
914- null ,
911+ null , // no request id
912+ null , // no destination name
915913 "" ,
916914 "Failed to exchange Diffie-Hellman key! Reason: " + ex .getMessage ());
917915 }
@@ -954,8 +952,8 @@ private Message handleTest(final Message request) {
954952 request .getRequestId (),
955953 RESPONSE ,
956954 OK ,
957- true , // oneway
958- false , // transient
955+ ONEWAY_MSG ,
956+ TRANSIENT_MSG ,
959957 false , // not a subscription msg
960958 Messages .EXPIRES_NEVER ,
961959 request .getSubject (),
@@ -1108,12 +1106,12 @@ private static Message createJsonResponse(
11081106 request .getRequestId (),
11091107 RESPONSE ,
11101108 status ,
1111- true , // oneway
1112- false , // transient
1109+ ONEWAY_MSG ,
1110+ TRANSIENT_MSG ,
11131111 false , // not a subscription msg
11141112 request .getDestinationName (),
11151113 null ,
1116- - 1L ,
1114+ Instant . now (). toEpochMilli () ,
11171115 Messages .EXPIRES_NEVER ,
11181116 Messages .NO_TIMEOUT ,
11191117 request .getSubject (),
@@ -1135,12 +1133,12 @@ private static Message createPlainTextResponse(
11351133 requestID ,
11361134 RESPONSE ,
11371135 status ,
1138- true , // oneway
1139- false , // transient
1136+ ONEWAY_MSG ,
1137+ TRANSIENT_MSG ,
11401138 false , // not a subscription msg
11411139 destinationName ,
11421140 null ,
1143- - 1L ,
1141+ Instant . now (). toEpochMilli () ,
11441142 Messages .EXPIRES_NEVER ,
11451143 Messages .NO_TIMEOUT ,
11461144 subject ,
@@ -1235,6 +1233,9 @@ private static byte[] toBytes(final String s, final String charset) {
12351233
12361234 public static final int ERROR_QUEUE_CAPACITY = 50 ;
12371235
1236+ private static final boolean ONEWAY_MSG = true ;
1237+ private static final boolean TRANSIENT_MSG = false ;
1238+
12381239
12391240 private volatile long lastHeartbeat = System .currentTimeMillis (); // Millis since epoch
12401241
0 commit comments