Skip to content

Commit 21eca16

Browse files
committed
refactor: Remove push what offset and tweaked a typo
1 parent db36777 commit 21eca16

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

sdk/src/main/java/com/deploygate/sdk/CustomLogInstructionSerializer.java

+5-22
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/**
1717
* This class serialize the instructions for custom logs and process them in another thread in order of enqueued.
18-
* The internal handler class creates a buffer pool and grantee the order.
18+
* The internal handler class creates a buffer pool and guarantee the order.
1919
*
2020
* <p>
2121
* - Enqueue a new log to the buffer pool
@@ -220,9 +220,7 @@ private static class CustomLogHandler extends Handler {
220220
private final CustomLogInstructionSerializer serializer;
221221
private final CustomLogConfiguration.Backpressure backpressure;
222222
private final int bufferSize;
223-
private final int maxWhatOffset;
224223
private final LinkedList<CustomLog> customLogs;
225-
private int pushWhatOffset = 0;
226224

227225
/**
228226
* @param looper
@@ -244,7 +242,6 @@ private static class CustomLogHandler extends Handler {
244242
this.serializer = serializer;
245243
this.backpressure = backpressure;
246244
this.bufferSize = bufferSize;
247-
this.maxWhatOffset = bufferSize * 2;
248245
this.customLogs = new LinkedList<>();
249246
}
250247

@@ -271,7 +268,7 @@ void enqueueSendLogsInstruction() {
271268
* Enqueue new add-new-log instruction to the handler message queue.
272269
*/
273270
void enqueueAddNewLogInstruction(CustomLog log) {
274-
Message msg = obtainMessage(WHAT_ADD_NEW_LOG + getAndIncrementPushWhatOffset(), log);
271+
Message msg = obtainMessage(WHAT_ADD_NEW_LOG, log);
275272
sendMessage(msg);
276273
}
277274

@@ -342,27 +339,13 @@ public void handleMessage(Message msg) {
342339

343340
break;
344341
}
345-
default: {
346-
if (msg.what >= WHAT_ADD_NEW_LOG) {
347-
CustomLog log = (CustomLog) msg.obj;
348-
addLogToLast(log);
349-
}
342+
case WHAT_ADD_NEW_LOG: {
343+
CustomLog log = (CustomLog) msg.obj;
344+
addLogToLast(log);
350345

351346
break;
352347
}
353348
}
354349
}
355-
356-
/**
357-
* To avoid WHAT number conflicts, sdk uses a simple counter.
358-
*
359-
* @return positive number, which is greater than or equal to the value of {@link #WHAT_ADD_NEW_LOG}
360-
*/
361-
private int getAndIncrementPushWhatOffset() {
362-
if (pushWhatOffset > maxWhatOffset) {
363-
pushWhatOffset = 0;
364-
}
365-
return pushWhatOffset++;
366-
}
367350
}
368351
}

0 commit comments

Comments
 (0)