-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Espresso idling resource for Apollo GraphQL client #469
Changes from 1 commit
7a1664d
3ad4610
1210f32
0dda9b8
51817a7
76780b3
0af44d1
989e102
b68e8e5
ff6fa0d
7158335
873f393
5525529
43a90b6
53801bf
4483920
190ae11
664b033
41dcb1d
72484ae
cbf6574
de9a829
1cc6187
07d4b91
5d23a9f
69a28d5
d934cc0
8d1a6d6
7610a67
c75d4c4
79d2f99
f5ba765
85581e0
7471952
f3f1e48
fa598f1
0d495e1
8133815
1860193
f47672b
c8102ba
dd3cb51
95c9383
f9d36a8
ac1e4a8
516615b
4fab454
57c401d
c4e5ab5
3dad93e
9820c66
2096424
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
/** | ||
* ApolloCallTracker is responsible for keeping track of running {@link ApolloCall} & {@link ApolloPrefetch} objects. | ||
*/ | ||
public class ApolloCallTracker { | ||
|
||
private Runnable idleCallback; | ||
|
@@ -18,10 +21,25 @@ public class ApolloCallTracker { | |
public ApolloCallTracker() { | ||
} | ||
|
||
void syncPrefetchInProgress(ApolloPrefetch apolloPrefetch) { | ||
/** | ||
* <p>Adds this {@link ApolloPrefetch} to the underlying data structure keeping track of the in progress synchronous | ||
* prefetch objects.</p> | ||
* | ||
* <p><b>Note</b>: This method needs to be called right before a prefetch call is executed.</p> | ||
*/ | ||
synchronized void syncPrefetchInProgress(ApolloPrefetch apolloPrefetch) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess would be better to add |
||
runningSyncPrefetches.add(apolloPrefetch); | ||
} | ||
|
||
/** | ||
* <p>Removes this {@link ApolloPrefetch} from the underlying data structure keeping track of the in progress | ||
* synchronous prefetch objects, if it is found, else throws an {@link AssertionError}.</p> If the removal operation | ||
* is successful and no active running calls are found, then the registered {@link ApolloCallTracker#idleCallback} is | ||
* invoked. | ||
* | ||
* <p><b>Note</b>: This method needs to be called right after a prefetch call is completed (whether successful or | ||
* failed).</p> | ||
*/ | ||
void syncPrefetchFinished(ApolloPrefetch apolloPrefetch) { | ||
Runnable idleCallback; | ||
int runningCallsCount; | ||
|
@@ -35,10 +53,25 @@ void syncPrefetchFinished(ApolloPrefetch apolloPrefetch) { | |
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback); | ||
} | ||
|
||
/** | ||
* <p>Adds this asyncCall representing an asynchronous {@link ApolloPrefetch} to the underlying data structure keeping | ||
* track of the in progress asynchronous prefetch objects.</p> | ||
* | ||
* <p><b>Note</b>: This method needs to be called right before a prefetch call is executed.</p> | ||
*/ | ||
synchronized void asyncPrefetchInProgress(RealApolloPrefetch.AsyncCall asyncCall) { | ||
runningAsyncPrefetches.add(asyncCall); | ||
} | ||
|
||
/** | ||
* <p>Removes this asyncCall representing an asynchronous {@link ApolloPrefetch} from the underlying data structure | ||
* keeping track of the in progress asynchronous prefetch objects, if it is found, else throws an {@link | ||
* AssertionError}.</p> If the removal operation is successful and no active running calls are found, then the | ||
* registered {@link ApolloCallTracker#idleCallback} is invoked. | ||
* | ||
* <p><b>Note</b>: This method needs to be called right after a prefetch call is completed (whether successful or | ||
* failed).</p> | ||
*/ | ||
void asyncPrefetchFinished(RealApolloPrefetch.AsyncCall asyncCall) { | ||
Runnable idleCallback; | ||
int runningCallsCount; | ||
|
@@ -52,10 +85,25 @@ void asyncPrefetchFinished(RealApolloPrefetch.AsyncCall asyncCall) { | |
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback); | ||
} | ||
|
||
/** | ||
* <p>Adds this {@link ApolloCall} to the underlying data structure keeping track of the in progress synchronous | ||
* apolloCall objects.</p> | ||
* | ||
* <p><b>Note</b>: This method needs to be called right before an apolloCall is executed.</p> | ||
*/ | ||
synchronized void syncCallInProgress(ApolloCall apolloCall) { | ||
runningSyncCalls.add(apolloCall); | ||
} | ||
|
||
/** | ||
* <p>Removes this {@link ApolloCall} from the underlying data structure keeping track of the in progress synchronous | ||
* apolloCall objects, if it is found, else throws an {@link AssertionError}.</p> If the removal operation is | ||
* successful and no active running calls are found, then the registered {@link ApolloCallTracker#idleCallback} is | ||
* invoked. | ||
* | ||
* <p><b>Note</b>: This method needs to be called right after an apolloCall is completed (whether successful or | ||
* failed).</p> | ||
*/ | ||
void syncCallFinished(ApolloCall apolloCall) { | ||
Runnable idleCallback; | ||
int runningCallsCount; | ||
|
@@ -69,10 +117,25 @@ void syncCallFinished(ApolloCall apolloCall) { | |
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback); | ||
} | ||
|
||
/** | ||
* <p>Adds this asyncCall representing an asynchronous {@link ApolloCall} to the underlying data structure keeping | ||
* track of the in progress asynchronous apolloCall objects.</p> | ||
* | ||
* <p><b>Note</b>: This method needs to be called right before an apolloCall is executed.</p> | ||
*/ | ||
synchronized void asyncCallInProgress(RealApolloCall<?>.AsyncCall asyncCall) { | ||
runningAsyncCalls.add(asyncCall); | ||
} | ||
|
||
/** | ||
* <p>Removes this asyncCall representing an asynchronous {@link ApolloCall} from the underlying data structure | ||
* keeping track of the in progress asynchronous apolloCall objects, if it is found, else throws an {@link | ||
* AssertionError}.</p> If the removal operation is successful and no active running calls are found, then the | ||
* registered {@link ApolloCallTracker#idleCallback} is invoked. | ||
* | ||
* <p><b>Note</b>: This method needs to be called right after an apolloCall is completed (whether successful or | ||
* failed).</p> | ||
*/ | ||
void asyncCallFinished(RealApolloCall<?>.AsyncCall asyncCall) { | ||
Runnable idleCallback; | ||
int runningCallsCount; | ||
|
@@ -86,6 +149,9 @@ void asyncCallFinished(RealApolloCall<?>.AsyncCall asyncCall) { | |
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback); | ||
} | ||
|
||
/** | ||
* Registers idleCallback which is invoked when the apolloClient becomes idle. | ||
*/ | ||
public synchronized void setIdleCallback(Runnable idleCallback) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don;t think we need it to be synchronized, it doesn't have any value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. |
||
this.idleCallback = idleCallback; | ||
} | ||
|
@@ -96,6 +162,9 @@ private void executeCallBackIfCallsAreFinished(int runningCallsCount, Runnable i | |
} | ||
} | ||
|
||
/** | ||
* Returns a total count of in progress {@link ApolloCall} & {@link ApolloPrefetch} objects. | ||
*/ | ||
public int getRunningCallsCount() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
return runningAsyncCalls.size() + | ||
runningSyncCalls.size() + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final