Search in sources :

Example 16 with Scheduler

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

the class Periodic method start.

@Override
public void start() throws Exception {
    // 
    Scheduler scheduler = io.vertx.rxjava.core.RxHelper.scheduler(vertx);
    // Create a periodic event stream using Vertx scheduler
    Observable<Long> o = Observable.timer(0, 1000, TimeUnit.MILLISECONDS, scheduler);
    o.subscribe(item -> {
        System.out.println("Got item " + item);
    });
}
Also used : Scheduler(rx.Scheduler)

Example 17 with Scheduler

use of rx.Scheduler in project kork by spinnaker.

the class StackdriverConfig method defaultStackdriverWriter.

/**
 * Schedule a thread to flush our registry into stackdriver periodically.
 *
 * <p>This configures our StackdriverWriter as well.
 */
@Bean
public StackdriverWriter defaultStackdriverWriter(Environment environment, Registry registry, SpectatorStackdriverConfigurationProperties spectatorStackdriverConfigurationProperties) throws IOException {
    Logger log = LoggerFactory.getLogger("StackdriverConfig");
    log.info("Creating StackdriverWriter.");
    Predicate<Measurement> filterNotSpring = new Predicate<Measurement>() {

        public boolean test(Measurement measurement) {
            // These are from spring; those of interest were replicated in spectator.
            if (measurement.id().tags().iterator().hasNext()) {
                return true;
            }
            return false;
        }
    };
    Predicate<Measurement> measurementFilter;
    final String prototypeFilterPath = spectatorStackdriverConfigurationProperties.getWebEndpoint().getPrototypeFilter().getPath();
    if (!prototypeFilterPath.isEmpty()) {
        log.error("Ignoring prototypeFilterPath because it is not yet supported.");
        measurementFilter = null;
        log.info("Configuring stackdriver filter from {}", prototypeFilterPath);
        measurementFilter = PrototypeMeasurementFilter.loadFromPath(prototypeFilterPath).and(filterNotSpring);
    } else {
        measurementFilter = filterNotSpring;
    }
    InetAddress hostaddr = serverProperties.getAddress();
    if (hostaddr.equals(InetAddress.getLoopbackAddress())) {
        hostaddr = InetAddress.getLocalHost();
    }
    String host = hostaddr.getCanonicalHostName();
    String hostPort = host + ":" + serverProperties.getPort();
    ConfigParams params = new ConfigParams.Builder().setCounterStartTime(new Date().getTime()).setCustomTypeNamespace("spinnaker").setProjectName(spectatorStackdriverConfigurationProperties.getStackdriver().getProjectName()).setApplicationName(spectatorStackdriverConfigurationProperties.getApplicationName(environment.getProperty("spring.application.name"))).setCredentialsPath(spectatorStackdriverConfigurationProperties.getStackdriver().getCredentialsPath()).setMeasurementFilter(measurementFilter).setInstanceId(hostPort).build();
    stackdriver = new StackdriverWriter(params);
    Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(1));
    Observable.timer(spectatorStackdriverConfigurationProperties.getStackdriver().getPeriod(), TimeUnit.SECONDS).repeat().subscribe(interval -> {
        stackdriver.writeRegistry(registry);
    });
    return stackdriver;
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Scheduler(rx.Scheduler) StackdriverWriter(com.netflix.spectator.stackdriver.StackdriverWriter) Logger(org.slf4j.Logger) InetAddress(java.net.InetAddress) Date(java.util.Date) Predicate(java.util.function.Predicate) ConfigParams(com.netflix.spectator.stackdriver.ConfigParams) Bean(org.springframework.context.annotation.Bean)

Example 18 with Scheduler

use of rx.Scheduler in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method defaultSchedulerReturnsSpecifiedScheduler.

@Test
public void defaultSchedulerReturnsSpecifiedScheduler() {
    Scheduler scheduler = mock(Scheduler.class);
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(mock(ContentResolver.class)).defaultScheduler(scheduler).build();
    assertThat(storIOContentResolver.defaultScheduler()).isSameAs(scheduler);
}
Also used : Scheduler(rx.Scheduler) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 19 with Scheduler

use of rx.Scheduler in project goro by stanfy.

the class TestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GoroService.setup(this, Goro.create());
    Scheduler scheduler = new RxGoro(goro).scheduler("test-queue");
    Observable.just("ok").subscribeOn(scheduler).subscribe(new Action1<String>() {

        @Override
        public void call(String s) {
            result = "ok";
            resultSync.countDown();
        }
    });
    Observable.error(new RuntimeException("test error")).subscribeOn(scheduler).subscribe(Actions.empty(), new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            error = throwable;
            errorSync.countDown();
        }
    });
}
Also used : Scheduler(rx.Scheduler)

Example 20 with Scheduler

use of rx.Scheduler in project pictureapp by EyeSeeTea.

the class PullDhisSDKDataSource method pullData.

public void pullData(PullFilters pullFilters, List<OrganisationUnit> organisationUnits, IDataSourceCallback<List<Event>> callback) {
    boolean isNetworkAvailable = isNetworkAvailable();
    if (!isNetworkAvailable) {
        callback.onError(new NetworkException());
    } else {
        List<Event> events = new ArrayList<>();
        for (OrganisationUnit organisationUnit : organisationUnits) {
            if (pullFilters.getDataByOrgUnit() != null && !pullFilters.getDataByOrgUnit().equals("")) {
                if (!pullFilters.getDataByOrgUnit().equals(organisationUnit.getName())) {
                    continue;
                }
            }
            Scheduler pullEventsThread = Schedulers.newThread();
            EventFilters eventFilters = new EventFilters();
            eventFilters.setStartDate(pullFilters.getStartDate());
            eventFilters.setEndDate(pullFilters.getEndDate());
            eventFilters.setMaxEvents(pullFilters.getMaxEvents());
            eventFilters.setOrganisationUnitUId(organisationUnit.getUId());
            mPullDhisSDKDataSourceStrategy.setEventFilters(eventFilters);
            List<Event> eventsByOrgUnit = D2.events().pull(eventFilters).subscribeOn(pullEventsThread).observeOn(pullEventsThread).toBlocking().single();
            events.addAll(eventsByOrgUnit);
        }
        callback.onSuccess(events);
    }
}
Also used : OrganisationUnit(org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit) Scheduler(rx.Scheduler) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.client.sdk.models.event.Event) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) EventFilters(org.hisp.dhis.client.sdk.core.event.EventFilters)

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