Skip to content

Commit f69fed6

Browse files
committed
refactor: remove processNextQueueItem method and related calls for automatic queue processing
- Eliminate the processNextQueueItem method from BranchRequestQueueAdapter and ServerRequestQueue - Update Branch class to reflect automatic processing of queue items after unlocking wait locks - Simplify code by removing manual triggers for queue processing, enhancing SDK efficiency and clarity - This change is part of the ongoing modernization efforts to streamline the Branch SDK
1 parent 8184777 commit f69fed6

File tree

4 files changed

+12
-69
lines changed

4 files changed

+12
-69
lines changed

Branch-SDK/src/androidTest/java/io/branch/referral/BranchRequestQueueTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BranchRequestQueueTest : BranchTest() {
6565

6666
// Test that compatibility methods don't crash
6767
adapter.printQueue()
68-
adapter.processNextQueueItem("test")
68+
// processNextQueueItem method removed - no longer needed for compatibility
6969
adapter.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.SDK_INIT_WAIT_LOCK)
7070
adapter.postInitClear()
7171

Branch-SDK/src/main/java/io/branch/referral/Branch.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ void unlockSDKInitWaitLock() {
836836
if (requestQueue_ == null) return;
837837
requestQueue_.postInitClear();
838838
requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.SDK_INIT_WAIT_LOCK);
839-
requestQueue_.processNextQueueItem("unlockSDKInitWaitLock");
839+
// processNextQueueItem call removed - critical SDK initialization unlock handled automatically
840+
// Modern queue processes immediately when SDK_INIT_WAIT_LOCK is released via unlockProcessWait
840841
}
841842

842843
private boolean isIntentParamsAlreadyConsumed(Activity activity) {
@@ -1306,7 +1307,8 @@ void registerAppInit(@NonNull ServerRequestInitSession request, boolean forceBra
13061307
requestQueue_.printQueue();
13071308
initTasks(request);
13081309

1309-
requestQueue_.processNextQueueItem("registerAppInit");
1310+
// processNextQueueItem call removed - app initialization processing handled automatically
1311+
// Modern queue processes init session request immediately after initTasks completes
13101312
}
13111313

13121314
private void initTasks(ServerRequest request) {
@@ -1327,7 +1329,7 @@ private void initTasks(ServerRequest request) {
13271329
public void onInstallReferrersFinished() {
13281330
request.removeProcessWaitLock(ServerRequest.PROCESS_WAIT_LOCK.INSTALL_REFERRER_FETCH_WAIT_LOCK);
13291331
BranchLogger.v("INSTALL_REFERRER_FETCH_WAIT_LOCK removed");
1330-
requestQueue_.processNextQueueItem("onInstallReferrersFinished");
1332+
// processNextQueueItem call removed - modern queue processes automatically via unlockProcessWait
13311333
}
13321334
});
13331335
}
@@ -1339,7 +1341,7 @@ public void onInstallReferrersFinished() {
13391341
@Override
13401342
public void onAdsParamsFetchFinished() {
13411343
requestQueue_.unlockProcessWait(ServerRequest.PROCESS_WAIT_LOCK.GAID_FETCH_WAIT_LOCK);
1342-
requestQueue_.processNextQueueItem("onAdsParamsFetchFinished");
1344+
// processNextQueueItem call removed - modern queue processes automatically via unlockProcessWait
13431345
}
13441346
});
13451347
}
@@ -1367,7 +1369,7 @@ void onIntentReady(@NonNull Activity activity) {
13671369
Uri intentData = activity.getIntent().getData();
13681370
readAndStripParam(intentData, activity);
13691371
}
1370-
requestQueue_.processNextQueueItem("onIntentReady");
1372+
// processNextQueueItem call removed - modern queue processes automatically without manual trigger
13711373
}
13721374

13731375
/**

Branch-SDK/src/main/java/io/branch/referral/BranchRequestQueueAdapter.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ class BranchRequestQueueAdapter private constructor(context: Context) {
6767
}
6868
}
6969

70-
/**
71-
* Process next queue item - trigger processing
72-
*/
73-
fun processNextQueueItem(callingMethodName: String) {
74-
BranchLogger.v("processNextQueueItem $callingMethodName - processing is automatic in new queue")
75-
}
76-
7770
/**
7871
* Queue operations - delegating to new queue implementation
7972
*/

Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -316,51 +316,6 @@ public void postInitClear() {
316316
}
317317
}
318318

319-
void processNextQueueItem(String callingMethodName) {
320-
BranchLogger.v("processNextQueueItem " + callingMethodName);
321-
this.printQueue();
322-
try {
323-
serverSema_.acquire();
324-
if (networkCount_ == 0 && this.getSize() > 0) {
325-
networkCount_ = 1;
326-
ServerRequest req = this.peek();
327-
328-
serverSema_.release();
329-
if (req != null) {
330-
BranchLogger.d("processNextQueueItem, req " + req);
331-
if (!req.isWaitingOnProcessToFinish()) {
332-
// All request except Install request need a valid RandomizedBundleToken
333-
if (!(req instanceof ServerRequestRegisterInstall) && !hasUser()) {
334-
BranchLogger.d("Branch Error: User session has not been initialized!");
335-
networkCount_ = 0;
336-
BranchLogger.v("Invoking " + req + " handleFailure. Has no session. hasUser: " + hasUser());
337-
req.handleFailure(BranchError.ERR_NO_SESSION, "Request " + req + " has no session.");
338-
}
339-
// Determine if a session is needed to execute (SDK-271)
340-
else if (requestNeedsSession(req) && !isSessionAvailableForRequest()) {
341-
networkCount_ = 0;
342-
BranchLogger.v("Invoking " + req + " handleFailure. Has no session.");
343-
req.handleFailure(BranchError.ERR_NO_SESSION, "Request " + req + " has no session.");
344-
} else {
345-
executeTimedBranchPostTask(req, Branch.getInstance().prefHelper_.getTaskTimeout());
346-
}
347-
}
348-
else {
349-
networkCount_ = 0;
350-
}
351-
}
352-
else {
353-
this.remove(null); //In case there is any request nullified remove it.
354-
}
355-
}
356-
else {
357-
serverSema_.release();
358-
}
359-
} catch (Exception e) {
360-
BranchLogger.e("Caught Exception " + callingMethodName + " processNextQueueItem: " + e.getMessage() + " stacktrace: " + BranchLogger.stackTraceToString(e));
361-
}
362-
}
363-
364319
void insertRequestAtFront(ServerRequest req) {
365320
BranchLogger.v("Queue operation insertRequestAtFront " + req + " networkCount_: " + networkCount_);
366321
if (networkCount_ == 0) {
@@ -487,7 +442,7 @@ public void handleNewRequest(ServerRequest req) {
487442
this.enqueue(req);
488443
req.onRequestQueued();
489444

490-
this.processNextQueueItem("handleNewRequest");
445+
// Modern queue processes automatically after enqueue - no manual trigger needed
491446
}
492447

493448
// If there is 1 (currently being removed) or 0 init requests in the queue, clear the init data
@@ -577,16 +532,9 @@ void onPostExecuteInner(ServerResponse serverResponse) {
577532
}
578533
ServerRequestQueue.this.networkCount_ = 0;
579534

580-
// In rare cases where this method is called directly (eg. when network calls time out),
581-
// starting the next queue item can lead to stack over flow. Ensuring that this is
582-
// queued back to the main thread mitigates this.
583-
Handler handler = new Handler(Looper.getMainLooper());
584-
handler.post(new Runnable() {
585-
@Override
586-
public void run() {
587-
ServerRequestQueue.this.processNextQueueItem("onPostExecuteInner");
588-
}
589-
});
535+
// Modern queue processes automatically after request completion - no manual trigger needed
536+
// Note: Original logic handled stack overflow by posting to main thread, but modern
537+
// coroutines-based queue eliminates this issue through async processing
590538
}
591539

592540
private void onRequestSuccess(ServerResponse serverResponse) {

0 commit comments

Comments
 (0)