Java Code Examples for com.facebook.common.internal.Supplier#get()

The following examples show how to use com.facebook.common.internal.Supplier#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RetainingDataSourceSupplier.java    From fresco with MIT License 6 votes vote down vote up
public void setSupplier(@Nullable Supplier<DataSource<T>> supplier) {
  // early return without calling {@code supplier.get()} in case we are closed
  if (isClosed()) {
    return;
  }
  DataSource<T> oldDataSource;
  DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null;
  synchronized (RetainingDataSource.this) {
    if (isClosed()) {
      closeSafely(newDataSource);
      return;
    } else {
      oldDataSource = mDataSource;
      mDataSource = newDataSource;
    }
  }
  if (newDataSource != null) {
    newDataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
  }
  closeSafely(oldDataSource);
}
 
Example 2
Source File: ImagePipelineTest.java    From fresco with MIT License 6 votes vote down vote up
@Test
public void testGetBitmapCacheGetSupplier() {
  Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier =
      mImagePipeline.getDataSourceSupplier(
          mImageRequest, mCallerContext, ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE);
  Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class);
  when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest))
      .thenReturn(bitmapCacheSequence);
  dataSourceSupplier.get();
  verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false);
  verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false);
  ArgumentCaptor<ProducerContext> producerContextArgumentCaptor =
      ArgumentCaptor.forClass(ProducerContext.class);
  verify(bitmapCacheSequence)
      .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
  assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
  assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
 
Example 3
Source File: ImagePipelineTest.java    From fresco with MIT License 6 votes vote down vote up
@Test
public void testGetFullFetchSupplier() {
  Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier =
      mImagePipeline.getDataSourceSupplier(
          mImageRequest, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH);
  Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class);
  when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest))
      .thenReturn(decodedSequence);
  DataSource<CloseableReference<CloseableImage>> dataSource = dataSourceSupplier.get();
  assertFalse(dataSource.isFinished());
  verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false);
  verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false);
  ArgumentCaptor<ProducerContext> producerContextArgumentCaptor =
      ArgumentCaptor.forClass(ProducerContext.class);
  verify(decodedSequence)
      .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
  assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
  assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
 
Example 4
Source File: FirstAvailableDataSourceSupplier.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private boolean startNextDataSource() {
  Supplier<DataSource<T>> dataSourceSupplier = getNextSupplier();
  DataSource<T> dataSource = (dataSourceSupplier != null) ? dataSourceSupplier.get() : null;
  if (setCurrentDataSource(dataSource) && dataSource != null) {
    dataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
    return true;
  } else {
    closeSafely(dataSource);
    return false;
  }
}
 
Example 5
Source File: FirstAvailableDataSourceSupplier.java    From fresco with MIT License 5 votes vote down vote up
private boolean startNextDataSource() {
  Supplier<DataSource<T>> dataSourceSupplier = getNextSupplier();
  DataSource<T> dataSource = (dataSourceSupplier != null) ? dataSourceSupplier.get() : null;
  if (setCurrentDataSource(dataSource) && dataSource != null) {
    dataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
    return true;
  } else {
    closeSafely(dataSource);
    return false;
  }
}