Skip to content

Commit 31aa13f

Browse files
committed
IPC: msg compression cutoff size is now completely controlled by server
1 parent 708aa48 commit 31aa13f

File tree

3 files changed

+15
-44
lines changed

3 files changed

+15
-44
lines changed

src/main/java/com/github/jlangch/venice/impl/functions/IPCFunctions.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ public VncVal apply(final VncList args) {
182182
? 0
183183
: Coerce.toVncLong(maxConnVal).getIntValue();
184184

185-
final long maxMsgSize = convertMaxMessageSizeToLong(maxMsgSizeVal);
186-
final long maxQueues = convertMaxMessageSizeToLong(maxMaxQueuesVal);
187-
final long compressCutoffSize = convertMaxMessageSizeToLong(compressCutoffSizeVal);
185+
final long maxMsgSize = convertUnitValueToLong(maxMsgSizeVal);
186+
final long maxQueues = convertUnitValueToLong(maxMaxQueuesVal);
187+
final long compressCutoffSize = convertUnitValueToLong(compressCutoffSizeVal);
188188
final boolean encrypt = Coerce.toVncBoolean(encryptVal).getValue();
189189

190190
final File serverLogDir = serverLogDirVal == Nil
@@ -297,13 +297,6 @@ public VncVal apply(final VncList args) {
297297
"| port p | The server's TCP/IP port |\n" +
298298
"| host h | The server's TCP/IP host |\n\n" +
299299
"*Options:* \n\n" +
300-
"| :compress-cutoff-size n | The compression cutoff size for payload messages.¶" +
301-
" With a negative cutoff size payload messages will not be" +
302-
" compressed. If the payload message size is greater than the" +
303-
" cutoff size it will be compressed.¶" +
304-
" Defaults to -1 (no compression)¶" +
305-
" The cutoff size can be specified as a number like `1000`" +
306-
" or a number with a unit like `:1KB` or `:2MB`|\n" +
307300
"| :encrypt b | If `true` encrypt the payload data of all messages exchanged" +
308301
" between this client and its associated server.¶" +
309302
" The data is AES-256-GCM encrypted using a secret that is" +
@@ -325,7 +318,7 @@ public VncVal apply(final VncList args) {
325318
" \n" +
326319
" (try-with [server (ipc/server 33333 echo-handler) \n" +
327320
" client-1 (ipc/client 33333) \n" +
328-
" client-2 (ipc/client \"localhost\" 33333 :compress-cutoff-size 0) \n" +
321+
" client-2 (ipc/client \"localhost\" 33333) \n" +
329322
" client-3 (ipc/client :localhost 33333 :encrypt true)] \n" +
330323
" (send client-1 (ipc/plain-text-message \"1\" \"test\" \"hello\")) \n" +
331324
" (send client-2 (ipc/plain-text-message \"2\" \"test\" \"hello\")) \n" +
@@ -378,20 +371,14 @@ else if ( args.size() == 2) {
378371
final int port = Coerce.toVncLong(args.second()).getIntValue();
379372

380373
final VncHashMap options = VncHashMap.ofAll(args.slice(2));
381-
final VncVal compressCutoffSizeVal = options.get(new VncKeyword("compress-cutoff-size"));
382374
final VncVal encryptVal = options.get(new VncKeyword("encrypt"), VncBoolean.False);
383375

384-
final long compressCutoffSize = convertMaxMessageSizeToLong(compressCutoffSizeVal);
385376
final boolean encrypt = Coerce.toVncBoolean(encryptVal).getValue();
386377

387378
final TcpClient client = new TcpClient(host, port);
388379

389380
client.setEncryption(encrypt);
390381

391-
if (compressCutoffSize >= 0) {
392-
client.setCompressCutoffSize(compressCutoffSize);
393-
}
394-
395382
client.open();
396383

397384
return new VncJavaObject(client);
@@ -2897,7 +2884,7 @@ public VncVal apply(final VncList args) {
28972884
// Utils
28982885
// ------------------------------------------------------------------------
28992886

2900-
private static long convertMaxMessageSizeToLong(final VncVal val) {
2887+
private static long convertUnitValueToLong(final VncVal val) {
29012888
if (val == Nil) {
29022889
return 0L;
29032890
}
@@ -2916,11 +2903,11 @@ else if (sVal.matches("^[1-9][0-9]*MB$")) {
29162903
return Long.parseLong(StringUtil.removeEnd(sVal, "MB")) * 1024 * 1024;
29172904
}
29182905
else {
2919-
throw new VncException("Invalid max-message-size value! Use 20000, 500KB, 10MB, ...");
2906+
throw new VncException("Invalid unit value! Use 20000, 500KB, 10MB, ...");
29202907
}
29212908
}
29222909
else {
2923-
throw new VncException("Invalid max-message-size value! Use 20000, 500KB, 10MB, ...");
2910+
throw new VncException("Invalid unit value! Use 20000, 500KB, 10MB, ...");
29242911
}
29252912
}
29262913

src/main/java/com/github/jlangch/venice/util/ipc/TcpClient.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public TcpClient(final String host, final int port) {
104104
public Object clone() {
105105
final TcpClient client = new TcpClient(host, port);
106106
client.setEncryption(isEncrypted());
107-
client.setCompressCutoffSize(getCompressCutoffSize());
108-
return client;
107+
return client;
109108
}
110109

111110
/**
@@ -131,28 +130,6 @@ public boolean isEncrypted() {
131130
return encrypt.get();
132131
}
133132

134-
/**
135-
* Set the compression cutoff size for payload messages.
136-
*
137-
* <p>With a negative cutoff size payload messages will not be compressed.
138-
* If the payload message size is greater than the cutoff size it will be
139-
* compressed.
140-
*
141-
* <p>Defaults to -1 (no compression)
142-
*
143-
* @param cutoffSize the compress cutoff size in bytes
144-
* @return this server
145-
*/
146-
public TcpClient setCompressCutoffSize(final long cutoffSize) {
147-
if (opened.get()) {
148-
throw new VncException(
149-
"The compression cutoff size cannot be set anymore "
150-
+ "once the client has been opened!");
151-
}
152-
compressor.set(new Compressor(cutoffSize));
153-
return this;
154-
}
155-
156133
/**
157134
* @return return the client's payload message compression cutoff size
158135
*/
@@ -228,6 +205,12 @@ public void open() {
228205
config.get(
229206
new VncKeyword("max-msg-size"),
230207
new VncLong(MESSAGE_LIMIT_MAX))).toJavaLong());
208+
compressor.set(
209+
new Compressor(
210+
Coerce.toVncLong(
211+
config.get(
212+
new VncKeyword("compress-cutoff-size"),
213+
new VncLong(MESSAGE_LIMIT_MAX))).toJavaLong()));
231214
encrypt.set(
232215
encrypt.get() // client side encrypt request
233216
|| VncBoolean.isTrue( // server side encrypt request

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ private Message handleClientConfigRequest(final Message request) {
769769
request.getTopics(),
770770
new JsonBuilder()
771771
.add("max-msg-size", maxMessageSize.get())
772+
.add("compress-cutoff-size", compressor.cutoffSize())
772773
.add("encrypt", enforceEncryption)
773774
.toJson(false));
774775
}

0 commit comments

Comments
 (0)