Search in sources :

Example 1 with Scheduler

use of rx.Scheduler in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsSpecifiedScheduler.

@Test
public void defaultSchedulerReturnsSpecifiedScheduler() {
    Scheduler scheduler = mock(Scheduler.class);
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).defaultScheduler(scheduler).build();
    assertThat(storIOSQLite.defaultScheduler()).isSameAs(scheduler);
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) Scheduler(rx.Scheduler) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 2 with Scheduler

use of rx.Scheduler in project retrofit by square.

the class RxJavaObserveOnMainThread method main.

public static void main(String... args) {
    // Or use mainThread() for Android.
    Scheduler observeOn = Schedulers.computation();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com").addCallAdapterFactory(new ObserveOnMainCallAdapterFactory(observeOn)).addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(io())).build();
// Services created with this instance that use Observable will execute on the 'io' scheduler
// and notify their observer on the 'computation' scheduler.
}
Also used : Retrofit(retrofit2.Retrofit) Scheduler(rx.Scheduler)

Example 3 with Scheduler

use of rx.Scheduler in project ratpack by ratpack.

the class MultiExecControllerBackedScheduler method getDelegateScheduler.

private Scheduler getDelegateScheduler() {
    return ExecController.current().map(c -> map.computeIfAbsent(c, ExecControllerBackedScheduler::new)).orElseGet(() -> {
        if (fallback.get() == null) {
            int nThreads = Runtime.getRuntime().availableProcessors();
            ExecutorService executor = Executors.newFixedThreadPool(nThreads);
            Scheduler scheduler = Schedulers.from(executor);
            fallback.compareAndSet(null, scheduler);
        }
        return fallback.get();
    });
}
Also used : Schedulers(rx.schedulers.Schedulers) MapMaker(com.google.common.collect.MapMaker) Scheduler(rx.Scheduler) ExecController(ratpack.exec.ExecController) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutorService(java.util.concurrent.ExecutorService) Executors(java.util.concurrent.Executors) ConcurrentMap(java.util.concurrent.ConcurrentMap) Scheduler(rx.Scheduler) ExecutorService(java.util.concurrent.ExecutorService)

Example 4 with Scheduler

use of rx.Scheduler in project grakn by graknlabs.

the class BatchExecutorClient method add.

/**
 * Will block until there is space for the query to be submitted
 */
public Observable<QueryResponse> add(Query<?> query, Keyspace keyspace, boolean keepErrors) {
    QueryRequest queryRequest = new QueryRequest(query);
    queryRequest.acquirePermit();
    Context contextAddTimer = addTimer.time();
    Observable<QueryResponse> observable = new QueriesObservableCollapser(queryRequest, keyspace).observe().doOnError(error -> failureMeter.mark()).doOnEach(a -> {
        if (a.getThrowable() != null) {
            LOG.error("Error while executing statement", a.getThrowable());
        } else if (a.isOnNext()) {
            LOG.trace("Executed {}", a.getValue());
        }
    }).subscribeOn(scheduler).doOnTerminate(contextAddTimer::close);
    return keepErrors ? observable : ignoreErrors(observable);
}
Also used : Context(com.codahale.metrics.Timer.Context) HystrixRequestContext(com.netflix.hystrix.strategy.concurrency.HystrixRequestContext) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) Retryer(com.github.rholder.retry.Retryer) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) Keyspace(ai.grakn.Keyspace) RetryException(com.github.rholder.retry.RetryException) LoggerFactory(org.slf4j.LoggerFactory) HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties) Observable(rx.Observable) Meter(com.codahale.metrics.Meter) HystrixCollapserProperties(com.netflix.hystrix.HystrixCollapserProperties) Schedulers(rx.schedulers.Schedulers) Context(com.codahale.metrics.Timer.Context) ConnectException(java.net.ConnectException) ExecutorService(java.util.concurrent.ExecutorService) WaitStrategies(com.github.rholder.retry.WaitStrategies) HystrixCollapser(com.netflix.hystrix.HystrixCollapser) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) Collection(java.util.Collection) Attempt(com.github.rholder.retry.Attempt) API(ai.grakn.API) UUID(java.util.UUID) Scheduler(rx.Scheduler) RetryListener(com.github.rholder.retry.RetryListener) Collectors(java.util.stream.Collectors) Query(ai.grakn.graql.Query) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) HystrixRequestContext(com.netflix.hystrix.strategy.concurrency.HystrixRequestContext) HystrixCommand(com.netflix.hystrix.HystrixCommand) List(java.util.List) StopStrategies(com.github.rholder.retry.StopStrategies) Closeable(java.io.Closeable) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) MetricRegistry.name(com.codahale.metrics.MetricRegistry.name) SimpleURI(ai.grakn.util.SimpleURI)

Example 5 with Scheduler

use of rx.Scheduler in project vertx-examples by vert-x3.

the class Scheduled method start.

@Override
public void start() throws Exception {
    Observable<String> o = Observable.just("someID1", "someID2", "someID3", "someID4");
    // This scheduler can execute blocking actions
    Scheduler scheduler = io.vertx.rxjava.core.RxHelper.blockingScheduler(vertx);
    // All operations done on the observer now can be blocking
    o = o.observeOn(scheduler);
    // Load from a blocking api
    o = o.map(id -> blockingLoad(id));
    o.subscribe(item -> {
        System.out.println("Got item " + item);
    }, err -> {
        err.printStackTrace();
    }, () -> {
        System.out.println("Done");
    });
}
Also used : Scheduler(rx.Scheduler) Runner(io.vertx.example.util.Runner) AbstractVerticle(io.vertx.rxjava.core.AbstractVerticle) Observable(rx.Observable) Scheduler(rx.Scheduler)

Aggregations

Scheduler (rx.Scheduler)27 Test (org.junit.Test)13 TestScheduler (rx.schedulers.TestScheduler)9 Observable (rx.Observable)7 Schedulers (rx.schedulers.Schedulers)7 Executors (java.util.concurrent.Executors)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Logger (org.slf4j.Logger)5 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)4 Member (io.scalecube.cluster.Member)4 Message (io.scalecube.transport.Message)4 Transport (io.scalecube.transport.Transport)4 Collections (java.util.Collections)4 ExecutorService (java.util.concurrent.ExecutorService)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 TimeUnit (java.util.concurrent.TimeUnit)4 LoggerFactory (org.slf4j.LoggerFactory)4 Collection (java.util.Collection)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)3