private boolean loadPagesIfNecessary ( PagesSupplier pagesSupplier , DataSize maxSize ) { checkState ( ! Thread . holdsLock ( this ) , "Can not load pages while holding a lock on this" ) ; boolean dataAddedOrNoMorePages ; List < SerializedPageReference > pageReferences ; synchronized ( this ) { if ( noMorePages ) { return false ; } if ( ! pages . isEmpty ( ) ) { return false ; } // The page supplier has incremented the page reference count, and addPages below also increments // the reference count, so we need to drop the page supplier reference. The call dereferencePage // is performed outside of synchronized to avoid making a callback while holding a lock. pageReferences = pagesSupplier . getPages ( maxSize ) ; // add the pages to this buffer, which will increase the reference count addPages ( pageReferences ) ; // check for no more pages if ( ! pagesSupplier . mayHaveMorePages ( ) ) { noMorePages = true ; } dataAddedOrNoMorePages = ! pageReferences . isEmpty ( ) || noMorePages ; } // sent pages will have an initial reference count, so drop it pageReferences . forEach ( SerializedPageReference :: dereferencePage ) ; return dataAddedOrNoMorePages ; }
If there no data attempt to load some from the pages supplier .