com.facebook.common.executors.CallerThreadExecutor Java Examples
The following examples show how to use
com.facebook.common.executors.CallerThreadExecutor.
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: AbstractDraweeControllerTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { mDeferredReleaser = mock(DeferredReleaser.class); mCallerContext = mock(Object.class); mDataSourceSupplier = mock(Supplier.class); mDraweeHierarchy = mock(SettableDraweeHierarchy.class); mUiThreadExecutor = CallerThreadExecutor.getInstance(); mController = new FakeDraweeController( mDeferredReleaser, mUiThreadExecutor, mDataSourceSupplier, "id", mCallerContext); doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release(); return null; } }) .when(mDeferredReleaser) .scheduleDeferredRelease(any(DeferredReleaser.Releasable.class)); when(mDataSourceSupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create()); }
Example #2
Source File: ThrottlingProducerTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mThrottlingProducer = new ThrottlingProducer<Object>( MAX_SIMULTANEOUS_REQUESTS, CallerThreadExecutor.getInstance(), mInputProducer); for (int i = 0; i < 5; i++) { mConsumers[i] = mock(Consumer.class); mProducerContexts[i] = mock(ProducerContext.class); mProducerListeners[i] = mock(ProducerListener2.class); mResults[i] = mock(Object.class); when(mProducerContexts[i].getProducerListener()).thenReturn(mProducerListeners[i]); when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]); final int iFinal = i; doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mThrottlerConsumers[iFinal] = (Consumer<Object>) invocation.getArguments()[0]; return null; } }) .when(mInputProducer) .produceResults(any(Consumer.class), eq(mProducerContexts[i])); } }
Example #3
Source File: PriorityStarvingThrottlingProducerTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mThrottlingProducer = new PriorityStarvingThrottlingProducer<>( MAX_SIMULTANEOUS_REQUESTS, CallerThreadExecutor.getInstance(), mInputProducer); for (int i = 0; i < 7; i++) { mConsumers[i] = mock(Consumer.class); mProducerContexts[i] = mock(ProducerContext.class); mProducerListeners[i] = mock(ProducerListener2.class); mResults[i] = mock(Object.class); when(mProducerContexts[i].getProducerListener()).thenReturn(mProducerListeners[i]); when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]); final int iFinal = i; doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mThrottlerConsumers[iFinal] = (Consumer<Object>) invocation.getArguments()[0]; return null; } }) .when(mInputProducer) .produceResults(any(Consumer.class), eq(mProducerContexts[i])); } }
Example #4
Source File: FrescoImageloadHelper.java From nono-android with GNU General Public License v3.0 | 6 votes |
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds) { int w = destImageView.getWidth(); int h =destImageView.getHeight(); if(w<1){ w = destImageView.getLayoutParams().width; } if(h<1){ h =destImageView.getLayoutParams().height; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL)) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(bbds, CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(destImageView.getController()) .setAutoPlayAnimations(true) .build(); destImageView.setController(draweeController); }
Example #5
Source File: FrescoImageloadHelper.java From nono-android with GNU General Public License v3.0 | 6 votes |
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,Context context,BaseBitmapDataSubscriber bbds) { int w = destImageView.getWidth(); int h =destImageView.getHeight(); if(w<1){ w = destImageView.getLayoutParams().width; } if(h<1){ h =destImageView.getLayoutParams().height; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(bbds, CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(destImageView.getController()) .setAutoPlayAnimations(true) .build(); destImageView.setController(draweeController); }
Example #6
Source File: RetainingDataSourceSupplier.java From fresco with MIT License | 6 votes |
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 #7
Source File: DataSourceTestUtils.java From fresco with MIT License | 6 votes |
public void setUp() { mSrc1 = mock(DataSource.class); mSrc2 = mock(DataSource.class); mSrc3 = mock(DataSource.class); mDataSourceSupplier1 = mock(Supplier.class); mDataSourceSupplier2 = mock(Supplier.class); mDataSourceSupplier3 = mock(Supplier.class); when(mDataSourceSupplier1.get()).thenReturn(mSrc1); when(mDataSourceSupplier2.get()).thenReturn(mSrc2); when(mDataSourceSupplier3.get()).thenReturn(mSrc3); mDataSubscriber = mock(DataSubscriber.class); mExecutor = CallerThreadExecutor.getInstance(); mInOrder = inOrder( mSrc1, mSrc2, mSrc3, mDataSourceSupplier1, mDataSourceSupplier2, mDataSourceSupplier3, mDataSubscriber); mSuppliers = Arrays.asList(mDataSourceSupplier1, mDataSourceSupplier2, mDataSourceSupplier3); }
Example #8
Source File: CloseableProducerToDataSourceAdapterTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResourceReleaser = mock(ResourceReleaser.class); mResultRef1 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef2 = CloseableReference.of(new Object(), mResourceReleaser); mResultRef3 = CloseableReference.of(new Object(), mResourceReleaser); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); mProducer = mock(Producer.class); mDataSource = CloseableProducerToDataSourceAdapter.create( mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart(mSettableProducerContext); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
Example #9
Source File: ProducerToDataSourceAdapterTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResult1 = new Object(); mResult2 = new Object(); mResult3 = new Object(); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(true); mProducer = mock(Producer.class); mDataSource = ProducerToDataSourceAdapter.create(mProducer, mSettableProducerContext, mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart(mSettableProducerContext); verify(mProducer).produceResults(captor.capture(), any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1, CallerThreadExecutor.getInstance()); }
Example #10
Source File: ListDataSource.java From fresco with MIT License | 5 votes |
public static <T> ListDataSource<T> create(DataSource<CloseableReference<T>>... dataSources) { Preconditions.checkNotNull(dataSources); Preconditions.checkState(dataSources.length > 0); ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources); for (DataSource<CloseableReference<T>> dataSource : dataSources) { if (dataSource != null) { dataSource.subscribe( listDataSource.new InternalDataSubscriber(), CallerThreadExecutor.getInstance()); } } return listDataSource; }
Example #11
Source File: ListDataSourceTest.java From fresco with MIT License | 5 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mSettableDataSource1 = SettableDataSource.create(); mSettableDataSource2 = SettableDataSource.create(); mListDataSource = ListDataSource.create(mSettableDataSource1, mSettableDataSource2); mRef1 = CloseableReference.of(1, mResourceReleaser); mRef2 = CloseableReference.of(2, mResourceReleaser); mRuntimeException = new RuntimeException(); mListDataSource.subscribe(mDataSubscriber, CallerThreadExecutor.getInstance()); }
Example #12
Source File: CloseableProducerToDataSourceAdapterTest.java From fresco with MIT License | 5 votes |
private void testSubscribe(int expected) { mDataSource.subscribe(mDataSubscriber2, CallerThreadExecutor.getInstance()); switch (expected) { case NO_INTERACTIONS: break; case ON_NEW_RESULT: verify(mDataSubscriber2).onNewResult(mDataSource); break; case ON_FAILURE: verify(mDataSubscriber2).onFailure(mDataSource); break; } verifyNoMoreInteractionsAndReset(); }
Example #13
Source File: ProducerToDataSourceAdapterTest.java From fresco with MIT License | 5 votes |
private void testSubscribe(int expected) { mDataSource.subscribe(mDataSubscriber2, CallerThreadExecutor.getInstance()); switch (expected) { case NO_INTERACTIONS: break; case ON_NEW_RESULT: verify(mDataSubscriber2).onNewResult(mDataSource); break; case ON_FAILURE: verify(mDataSubscriber2).onFailure(mDataSource); break; } verifyNoMoreInteractionsAndReset(); }
Example #14
Source File: FirstAvailableDataSourceSupplier.java From fresco with MIT License | 5 votes |
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 #15
Source File: FrescoImageloadHelper.java From nono-android with GNU General Public License v3.0 | 5 votes |
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL, Context context, BaseBitmapDataSubscriber bbds , BasePostprocessor postprocessor) { int w = destImageView.getWidth(); int h =destImageView.getHeight(); if(w<1){ w = destImageView.getLayoutParams().width; } if(h<1){ h =destImageView.getLayoutParams().height; } ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL)) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true); if(postprocessor!=null){ builder.setPostprocessor(postprocessor); } ImageRequest imageRequest = builder .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context); dataSource.subscribe(bbds, CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(destImageView.getController()) .setAutoPlayAnimations(true) .build(); destImageView.setController(draweeController); }
Example #16
Source File: ListDataSource.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public static <T> ListDataSource<T> create( DataSource<CloseableReference<T>>... dataSources) { Preconditions.checkNotNull(dataSources); Preconditions.checkState(dataSources.length > 0); ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources); for (DataSource<CloseableReference<T>> dataSource : dataSources) { dataSource.subscribe( listDataSource.new InternalDataSubscriber(), CallerThreadExecutor.getInstance()); } return listDataSource; }
Example #17
Source File: FirstAvailableDataSourceSupplier.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
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 #18
Source File: IncreasingQualityDataSourceSupplier.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public IncreasingQualityDataSource() { final int n = mDataSourceSuppliers.size(); mIndexOfDataSourceWithResult = n; mDataSources = Lists.newArrayListWithCapacity(n); for (int i = 0; i < n; i++) { DataSource<T> dataSource = mDataSourceSuppliers.get(i).get(); mDataSources.add(dataSource); dataSource.subscribe(new InternalDataSubscriber(i), CallerThreadExecutor.getInstance()); // there's no point in creating data sources of lower quality // if the data source of a higher quality has some result already if (dataSource.hasResult()) { break; } } }
Example #19
Source File: DataFetchProducer.java From fresco with MIT License | 4 votes |
public DataFetchProducer(PooledByteBufferFactory pooledByteBufferFactory) { super(CallerThreadExecutor.getInstance(), pooledByteBufferFactory); }
Example #20
Source File: FrescoUtils.java From materialup with Apache License 2.0 | 4 votes |
private static final void setSubscribe(Context context, ImageRequest request, BaseDataSubscriber subscriber) { ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, context); dataSource.subscribe(subscriber, CallerThreadExecutor.getInstance()); }