コード例 #1
0
  @Setup
  public void setup() {
    source = Single.just(1);

    flatmapped =
        source.flatMap(
            new Func1<Integer, Single<Integer>>() {
              @Override
              public Single<Integer> call(Integer t) {
                return Single.just(t);
              }
            });

    flatmapped =
        source.flatMap(
            new Func1<Integer, Single<Integer>>() {
              @Override
              public Single<Integer> call(Integer t) {
                return source;
              }
            });

    sourceObserveOn = source.observeOn(Schedulers.computation());

    sourceSubscribeOn = source.subscribeOn(Schedulers.computation());

    // ----------

    scheduledExecutor = Executors.newScheduledThreadPool(1);

    Scheduler s = Schedulers.from(scheduledExecutor);

    sourceObserveOnScheduledExecutor = source.observeOn(s);

    sourceSubscribeOnScheduledExecutor = source.subscribeOn(s);

    // ----------

    executor = Executors.newSingleThreadExecutor();

    Scheduler se = Schedulers.from(executor);

    sourceObserveOnExecutor = source.observeOn(se);

    sourceSubscribeOnExecutor = source.subscribeOn(se);

    // --------

    //        Scheduler fj = Schedulers.from(ForkJoinPool.commonPool());

    //        sourceObserveOnFJ = source.observeOn(fj);

    //        sourceSubscribeOnFJ = source.subscribeOn(fj);
  }
コード例 #2
0
ファイル: S3Config.java プロジェクト: robfletcher/front50
 @Bean
 public S3PipelineDAO s3PipelineDAO(ObjectMapper objectMapper, AmazonS3 amazonS3) {
   return new S3PipelineDAO(
       objectMapper,
       amazonS3,
       Schedulers.from(Executors.newFixedThreadPool(25)),
       10000,
       bucket,
       rootFolder);
 }
コード例 #3
0
ファイル: S3Config.java プロジェクト: robfletcher/front50
 @Bean
 public S3NotificationDAO s3NotificationDAO(ObjectMapper objectMapper, AmazonS3 amazonS3) {
   return new S3NotificationDAO(
       objectMapper,
       amazonS3,
       Schedulers.from(Executors.newFixedThreadPool(5)),
       30000,
       bucket,
       rootFolder);
 }
コード例 #4
0
/** Created by gokhanbarisaker on 11/20/15. */
public class Application extends android.app.Application {

  public static final Executor EXECUTOR_BACKGROUND =
      DeviceUtilities.getCurrentDevice().getBackgroundThreadExecutor();
  public static final Scheduler SCHEDULER_BACKGROUND = Schedulers.from(EXECUTOR_BACKGROUND);
  public static final OkHttpClient client = new OkHttpClient();
  public static Context context;
  public static Picasso picasso;
  public static Retrofit retrofit;

  @Override
  public void onCreate() {
    super.onCreate();

    context = getApplicationContext();
    client.setConnectTimeout(30, TimeUnit.SECONDS);
    client.setReadTimeout(120, TimeUnit.SECONDS);
    client.setWriteTimeout(120, TimeUnit.SECONDS);
    client.setCache(getDiskCache("httpclient"));

    picasso = new Picasso.Builder(this).downloader(new OkHttpDownloader(client)).build();
    retrofit =
        new Retrofit.Builder()
            .baseUrl("http://private-524e0-ecommerce4.apiary-mock.com/")
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
  }

  // TODO: Convert to fluent API Just For Fun :)
  private Cache getDiskCache(final String label) {
    int size = 10 * 1024 * 1024; // 10 mb.
    File directory = getDiskCacheDirectory(label);
    return (directory == null) ? (null) : (new Cache(directory, size));
  }

  // TODO: Check ContextCompat to access cache directories
  private File getDiskCacheDirectory(final String label) {
    File rootDirectory = getExternalCacheDir();

    // If external storage failed to provide cache
    if (rootDirectory == null) {
      // Fallback to internal storage
      rootDirectory = getCacheDir();
    }

    return (rootDirectory == null) ? (null) : (new File(rootDirectory, label));
  }
}
コード例 #5
0
ファイル: RxRealm.java プロジェクト: kokeroulis/AndroidUtils
public final class RxRealm {
  private static final Scheduler scheduler = Schedulers.from(Executors.newSingleThreadExecutor());

  private RxRealm() {
    // No instances
  }

  public static <E extends RealmObject, R> Observable<R> query(
      final Query<E> query, final Mapper<E, R> mapper) {
    return Observable.create(
            new Observable.OnSubscribe<R>() {
              @Override
              public void call(final Subscriber<? super R> subscriber) {
                if (subscriber.isUnsubscribed()) {
                  return;
                }

                Realm realm = Realm.getDefaultInstance();

                RealmResults<E> results = query.call(realm).findAll();
                for (E data : results) {
                  subscriber.onNext(mapper.call(data));
                }
                realm.close();
                subscriber.onCompleted();
              }
            })
        .subscribeOn(scheduler);
  }

  public static Observable<Void> transaction(final Realm.Transaction transaction) {
    return Observable.create(
            new Observable.OnSubscribe<Void>() {
              @Override
              public void call(final Subscriber<? super Void> subscriber) {
                if (subscriber.isUnsubscribed()) {
                  return;
                }

                Realm realm = Realm.getDefaultInstance();
                realm.executeTransaction(transaction);
                realm.close();
                subscriber.onCompleted();
              }
            })
        .subscribeOn(scheduler)
        .observeOn(AndroidSchedulers.mainThread());
  }
}
コード例 #6
0
 private Observable<Boolean> createObs() {
   //        List<Boolean> range = new ArrayList<>();
   //        for (int i = 0; i < 10; i++) {
   //            range.add(ThreadLocalRandom.current().nextBoolean());
   //        }
   //        return Observable.from(range).delay(1000l, TimeUnit.MILLISECONDS);
   return Observable.<Boolean>create(
           s -> {
             logger.info("new random boolean");
             s.onNext(ThreadLocalRandom.current().nextBoolean());
             s.onCompleted();
           })
       .subscribeOn(Schedulers.from(executorService))
       .delay(800L, TimeUnit.MILLISECONDS)
       .repeat(5L);
 }
コード例 #7
0
 private Observable<BigDecimal> createObs(BigDecimal max) {
   return Observable.<BigDecimal>create(
           s -> {
             logger.info("new random");
             BigDecimal random =
                 new BigDecimal(
                     ThreadLocalRandom.current().nextInt(0, max.toBigInteger().intValue()));
             s.onNext(random);
             s.onCompleted();
           })
       .subscribeOn(Schedulers.from(executorService))
       .delay(700L, TimeUnit.MILLISECONDS)
       .repeat(5L);
   //        List<BigDecimal> range = IntStream.range(0, max.toBigInteger().intValue())
   //                .boxed().map(integer -> new BigDecimal(integer))
   //                .limit(10)
   //                .collect(Collectors.toList());
   //        return Observable.from(range).delay(1000l, TimeUnit.MILLISECONDS);
 }