本文整理汇总了Java中io.vertx.rx.java.RxHelper.observableHandler方法的典型用法代码示例。如果您正苦于以下问题:Java RxHelper.observableHandler方法的具体用法?Java RxHelper.observableHandler怎么用?Java RxHelper.observableHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.rx.java.RxHelper
的用法示例。
在下文中一共展示了RxHelper.observableHandler方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: observeGetObject
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
private Observable<ObjectNode> observeGetObject(String endpoint) {
ObservableHandler<HttpClientResponse> responseObservable = RxHelper.observableHandler();
client.getNow(endpoint, responseObservable.toHandler());
return responseObservable
.flatMap(response -> {
if (response.statusCode() == HTTP_OK) {
ObservableHandler<Buffer> observable = RxHelper.observableHandler();
response.bodyHandler(observable.toHandler());
return observable;
} else {
throw new RuntimeException(String.format(
"Endpoint '%s' get returned %d status",
endpoint, response.statusCode()));
}
})
.map(buffer -> Json.decodeValue(buffer.toString(UTF_8.name()), ObjectNode.class));
}
示例2: hello4
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Path("4")
@GET
public void hello4(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
System.err.println("Creating client");
HttpClientOptions options = new HttpClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
HttpClient client = vertx.createHttpClient(options);
ObservableHandler<HttpClientResponse> responseHandler = RxHelper.observableHandler();
client.getNow(443,
"www.google.com",
"/robots.txt",
responseHandler.toHandler());
ObservableHandler<Buffer> bodyHandler = RxHelper.observableHandler();
responseHandler.subscribe(resp -> {
System.err.println("Got response");
resp.bodyHandler(bodyHandler.toHandler());
});
bodyHandler.subscribe(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.toString()).build());
});
System.err.println("Created client");
}
示例3: observeUserExists
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
private Observable<Boolean> observeUserExists(String username) {
String maybeJsonUser = usersCache.get(username);
if (maybeJsonUser != null) {
return Observable.just(true);
}
ObservableHandler<HttpClientResponse> responseObservable = RxHelper.observableHandler();
client.getNow(userEndpoint(username), responseObservable.toHandler());
return responseObservable
.flatMap(response -> {
if (response.statusCode() == HTTP_OK) {
ObservableHandler<Buffer> observable = RxHelper.observableHandler();
response.bodyHandler(observable.toHandler());
return observable;
} else {
throw new RuntimeException(String.format("User call returned %d status",
response.statusCode()));
}
})
.map(buffer -> Json.decodeValue(buffer.toString(UTF_8.name()), ObjectNode.class))
.map(user -> {
boolean exists = user.has("user");
if (exists) {
// FIXME: not caching "non existing" users.
usersCache.put(username, cacheSerialize(user));
}
return exists;
});
}
示例4: observableHandler
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
public void observableHandler(Vertx vertx) {
ObservableHandler<Long> observable = RxHelper.observableHandler();
observable.subscribe(id -> {
// Fired
});
vertx.setTimer(1000, observable.toHandler());
}
示例5: testMultiNotifyBeforeSubscribe
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testMultiNotifyBeforeSubscribe() {
ObservableHandler<String> o = RxHelper.observableHandler(true);
o.toHandler().handle("abc");
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
subscriber.assertEmpty();
}
示例6: testSingleNotifyBeforeSubscribe
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testSingleNotifyBeforeSubscribe() {
ObservableHandler<String> o = RxHelper.observableHandler();
o.toHandler().handle("abc");
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
subscriber.assertCompleted().assertEmpty();
}
示例7: testMultiNotifyAfterSubscribe
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testMultiNotifyAfterSubscribe() {
ObservableHandler<String> o = RxHelper.observableHandler(true);
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
subscriber.assertEmpty();
o.toHandler().handle("abc");
subscriber.assertItem("abc").assertEmpty();
}
示例8: testSingleNotifyAfterSubscribe
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testSingleNotifyAfterSubscribe() {
ObservableHandler<String> o = RxHelper.observableHandler();
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
subscriber.assertEmpty();
o.toHandler().handle("abc");
subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
示例9: testMultiUnsubscribeBeforeNotify
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testMultiUnsubscribeBeforeNotify() {
ObservableHandler<String> o = RxHelper.observableHandler(true);
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
subscriber.unsubscribe();
assertTrue(subscriber.isUnsubscribed());
subscriber.assertEmpty();
o.toHandler().handle("abc");
subscriber.assertEmpty();
}
示例10: testSingleUnsubscribeBeforeNotify
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testSingleUnsubscribeBeforeNotify() {
ObservableHandler<String> o = RxHelper.observableHandler();
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
subscriber.unsubscribe();
assertTrue(subscriber.isUnsubscribed());
subscriber.assertEmpty();
o.toHandler().handle("abc");
subscriber.assertEmpty();
}
示例11: testMultiNotifyTwice
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testMultiNotifyTwice() {
ObservableHandler<String> o = RxHelper.observableHandler(true);
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
o.toHandler().handle("abc");
o.toHandler().handle("def");
subscriber.assertItem("abc").assertItem("def").assertEmpty();
}
示例12: testSingleNotifyTwice
import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testSingleNotifyTwice() {
ObservableHandler<String> o = RxHelper.observableHandler();
SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
SimpleSubscriber.subscribe(o, subscriber);
o.toHandler().handle("abc");
o.toHandler().handle("def");
subscriber.assertItem("abc").assertCompleted().assertEmpty();
}