Skip to content

Commit 3b3d867

Browse files
committed
refactoring
1 parent f072e6d commit 3b3d867

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/main/java/com/github/jlangch/venice/util/ipc/impl/ServerQueueManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ServerQueueManager(
5555
this.wal = wal;
5656
this.logger = logger;
5757
this.maxQueues = config.getMaxQueues();
58-
this.deadLetterQueue = creatDeadLetterQueue(config.getDeadLetterQueueSize());
58+
this.deadLetterQueue = createDeadLetterQueue(config.getDeadLetterQueueSize());
5959
}
6060

6161
/**
@@ -300,7 +300,7 @@ public void close() {
300300
}
301301
}
302302

303-
private IpcQueue<Message> creatDeadLetterQueue(final int size) {
303+
private IpcQueue<Message> createDeadLetterQueue(final int size) {
304304
final IpcQueue<Message> q = size > 0
305305
? new CircularBuffer<Message>(
306306
DEAD_LETTER_QUEUE_NAME,

src/main/java/com/github/jlangch/venice/util/ipc/impl/conn/ServerConnection.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
import java.nio.channels.SocketChannel;
5959
import java.nio.charset.Charset;
60+
import java.time.Instant;
6061
import java.util.HashMap;
6162
import java.util.List;
6263
import 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

Comments
 (0)