/** * Request that a sequence of split points be prefetched. Code for the split * points in <code>splitPoints</code> will be downloaded and installed * whenever there is nothing else to download. Each call to this method * overwrites the entire prefetch queue with the newly specified one. */ public void setPrefetchQueue(int... runAsyncSplitPoints) { if (prefetchQueue == null) { prefetchQueue = new BoundedIntQueue(numEntries); } prefetchQueue.clear(); for (int sp : runAsyncSplitPoints) { prefetchQueue.add(sp); } startLoadingNextFragment(); }
requestedExclusives.clear();
requestedExclusives.clear();
/** * Inform the loader that a fragment has now finished loading. */ void fragmentHasLoaded(int fragment) { logFragmentLoaded(fragment); if (fragment < pendingDownloadErrorHandlers.length) { pendingDownloadErrorHandlers[fragment] = null; } if (isInitial(fragment)) { assert (fragment == remainingInitialFragments.peek()); remainingInitialFragments.remove(); } assert (fragment == fragmentLoading); fragmentLoading = -1; assert !isLoaded[fragment]; isLoaded[fragment] = true; startLoadingNextFragment(); }
/** * Clear out any inject and prefetch requests that are already loaded. Only * remove items from the head of each queue; any stale entries later in the * queue will be removed later. */ private void clearRequestsAlreadyLoaded() { while (requestedExclusives.size() > 0 && isLoaded[requestedExclusives.peek()]) { int offset = requestedExclusives.remove(); if (offset < pendingDownloadErrorHandlers.length) { pendingDownloadErrorHandlers[offset] = null; } } if (prefetchQueue != null) { while (prefetchQueue.size() > 0 && isLoaded[prefetchQueue.peek()]) { prefetchQueue.remove(); } } }
/** * Inform the loader that a fragment has now finished loading. */ void fragmentHasLoaded(int fragment) { logFragmentLoaded(fragment); if (fragment < pendingDownloadErrorHandlers.length) { pendingDownloadErrorHandlers[fragment] = null; } if (isInitial(fragment)) { assert (fragment == remainingInitialFragments.peek()); remainingInitialFragments.remove(); } assert (fragment == fragmentLoading); fragmentLoading = -1; assert !isLoaded[fragment]; isLoaded[fragment] = true; startLoadingNextFragment(); }
/** * Clear out any inject and prefetch requests that are already loaded. Only * remove items from the head of each queue; any stale entries later in the * queue will be removed later. */ private void clearRequestsAlreadyLoaded() { while (requestedExclusives.size() > 0 && isLoaded[requestedExclusives.peek()]) { int offset = requestedExclusives.remove(); if (offset < pendingDownloadErrorHandlers.length) { pendingDownloadErrorHandlers[offset] = null; } } if (prefetchQueue != null) { while (prefetchQueue.size() > 0 && isLoaded[prefetchQueue.peek()]) { prefetchQueue.remove(); } } }
/** * Requests a load of the code for the specified split point. If the load * fails, <code>loadErrorHandler</code> will be invoked. If it succeeds, then * the code will be installed, and the code is expected to invoke its own * on-success hooks, including a call to either * {@link #leftoversFragmentHasLoaded()} or {@link #fragmentHasLoaded(int)}. * * @param splitPoint the split point whose code needs to be loaded */ void inject(int splitPoint, LoadTerminatedHandler loadErrorHandler) { pendingDownloadErrorHandlers[splitPoint] = loadErrorHandler; if (!isInitial(splitPoint)) { requestedExclusives.add(splitPoint); } startLoadingNextFragment(); }
/** * Requests a load of the code for the specified split point. If the load * fails, <code>loadErrorHandler</code> will be invoked. If it succeeds, then * the code will be installed, and the code is expected to invoke its own * on-success hooks, including a call to either * {@link #leftoversFragmentHasLoaded()} or {@link #fragmentHasLoaded(int)}. * * @param splitPoint the split point whose code needs to be loaded */ void inject(int splitPoint, LoadTerminatedHandler loadErrorHandler) { pendingDownloadErrorHandlers[splitPoint] = loadErrorHandler; if (!isInitial(splitPoint)) { requestedExclusives.add(splitPoint); } startLoadingNextFragment(); }
/** * Request that a sequence of split points be prefetched. Code for the split * points in <code>splitPoints</code> will be downloaded and installed * whenever there is nothing else to download. Each call to this method * overwrites the entire prefetch queue with the newly specified one. */ public void setPrefetchQueue(int... runAsyncSplitPoints) { if (prefetchQueue == null) { prefetchQueue = new BoundedIntQueue(numEntries); } prefetchQueue.clear(); for (int sp : runAsyncSplitPoints) { prefetchQueue.add(sp); } startLoadingNextFragment(); }
private boolean anyPrefetchesRequested() { return prefetching && prefetchQueue != null && prefetchQueue.size() > 0; }
public AsyncFragmentLoader(int numEntries, int[] initialLoadSequence, LoadingStrategy loadingStrategy, Logger logger, OnSuccessExecutor executor) { this.numEntries = numEntries; this.initialLoadSequence = initialLoadSequence; this.loadingStrategy = loadingStrategy; this.logger = logger; this.onSuccessExecutor = executor; int numEntriesPlusOne = numEntries + 1; this.allCallbacks = new Object[numEntriesPlusOne][]; this.requestedExclusives = new BoundedIntQueue(numEntriesPlusOne); this.isLoaded = new boolean[numEntriesPlusOne]; this.pendingDownloadErrorHandlers = new LoadTerminatedHandler[numEntriesPlusOne]; }
public AsyncFragmentLoader(int numEntries, int[] initialLoadSequence, LoadingStrategy loadingStrategy, Logger logger, OnSuccessExecutor executor) { this.numEntries = numEntries; this.initialLoadSequence = initialLoadSequence; this.loadingStrategy = loadingStrategy; this.logger = logger; this.onSuccessExecutor = executor; int numEntriesPlusOne = numEntries + 1; this.allCallbacks = new Object[numEntriesPlusOne][]; this.requestedExclusives = new BoundedIntQueue(numEntriesPlusOne); this.isLoaded = new boolean[numEntriesPlusOne]; this.pendingDownloadErrorHandlers = new LoadTerminatedHandler[numEntriesPlusOne]; }
/** * Return whether all initial fragments have completed loading. */ private boolean haveInitialFragmentsLoaded() { return remainingInitialFragments != null && remainingInitialFragments.size() == 0; }
/** * Return whether all initial fragments have completed loading. */ private boolean haveInitialFragmentsLoaded() { return remainingInitialFragments != null && remainingInitialFragments.size() == 0; }
private boolean anyPrefetchesRequested() { return prefetching && prefetchQueue != null && prefetchQueue.size() > 0; }
/** * Initialize {@link #remainingInitialFragments} if it isn't already. */ private void initializeRemainingInitialFragments() { if (remainingInitialFragments == null) { remainingInitialFragments = new BoundedIntQueue(initialLoadSequence.length + 1); for (int sp : initialLoadSequence) { remainingInitialFragments.add(sp); } remainingInitialFragments.add(leftoversFragment()); } }
/** * Initialize {@link #remainingInitialFragments} if it isn't already. */ private void initializeRemainingInitialFragments() { if (remainingInitialFragments == null) { remainingInitialFragments = new BoundedIntQueue(initialLoadSequence.length + 1); for (int sp : initialLoadSequence) { remainingInitialFragments.add(sp); } remainingInitialFragments.add(leftoversFragment()); } }