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);
});
}
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;
}
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);
}
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();
}
});
}
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);
}
}
Aggregations