15
15
16
16
/**
17
17
* 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.
19
19
*
20
20
* <p>
21
21
* - Enqueue a new log to the buffer pool
@@ -220,9 +220,7 @@ private static class CustomLogHandler extends Handler {
220
220
private final CustomLogInstructionSerializer serializer ;
221
221
private final CustomLogConfiguration .Backpressure backpressure ;
222
222
private final int bufferSize ;
223
- private final int maxWhatOffset ;
224
223
private final LinkedList <CustomLog > customLogs ;
225
- private int pushWhatOffset = 0 ;
226
224
227
225
/**
228
226
* @param looper
@@ -244,7 +242,6 @@ private static class CustomLogHandler extends Handler {
244
242
this .serializer = serializer ;
245
243
this .backpressure = backpressure ;
246
244
this .bufferSize = bufferSize ;
247
- this .maxWhatOffset = bufferSize * 2 ;
248
245
this .customLogs = new LinkedList <>();
249
246
}
250
247
@@ -271,7 +268,7 @@ void enqueueSendLogsInstruction() {
271
268
* Enqueue new add-new-log instruction to the handler message queue.
272
269
*/
273
270
void enqueueAddNewLogInstruction (CustomLog log ) {
274
- Message msg = obtainMessage (WHAT_ADD_NEW_LOG + getAndIncrementPushWhatOffset () , log );
271
+ Message msg = obtainMessage (WHAT_ADD_NEW_LOG , log );
275
272
sendMessage (msg );
276
273
}
277
274
@@ -342,27 +339,13 @@ public void handleMessage(Message msg) {
342
339
343
340
break ;
344
341
}
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 );
350
345
351
346
break ;
352
347
}
353
348
}
354
349
}
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
- }
367
350
}
368
351
}
0 commit comments