当前位置: 首页>>代码示例>>Java>>正文


Java ObservableHandler类代码示例

本文整理汇总了Java中io.vertx.rx.java.ObservableHandler的典型用法代码示例。如果您正苦于以下问题:Java ObservableHandler类的具体用法?Java ObservableHandler怎么用?Java ObservableHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ObservableHandler类属于io.vertx.rx.java包,在下文中一共展示了ObservableHandler类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: observeGetObject

import io.vertx.rx.java.ObservableHandler; //导入依赖的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));
}
 
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:18,代码来源:RecentPurchasesHandler.java

示例2: hello4

import io.vertx.rx.java.ObservableHandler; //导入依赖的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");
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:30,代码来源:MyResource.java

示例3: observeUserExists

import io.vertx.rx.java.ObservableHandler; //导入依赖的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;
        });
}
 
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:30,代码来源:RecentPurchasesHandler.java

示例4: observableHandler

import io.vertx.rx.java.ObservableHandler; //导入依赖的package包/类
public void observableHandler(Vertx vertx) {
  ObservableHandler<Long> observable = RxHelper.observableHandler();
  observable.subscribe(id -> {
    // Fired
  });
  vertx.setTimer(1000, observable.toHandler());
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:8,代码来源:NativeExamples.java

示例5: testMultiNotifyBeforeSubscribe

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:9,代码来源:ObservableHandlerTest.java

示例6: testSingleNotifyBeforeSubscribe

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:9,代码来源:ObservableHandlerTest.java

示例7: testMultiNotifyAfterSubscribe

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:ObservableHandlerTest.java

示例8: testSingleNotifyAfterSubscribe

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:ObservableHandlerTest.java

示例9: testMultiUnsubscribeBeforeNotify

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:12,代码来源:ObservableHandlerTest.java

示例10: testSingleUnsubscribeBeforeNotify

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:12,代码来源:ObservableHandlerTest.java

示例11: testMultiNotifyTwice

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:ObservableHandlerTest.java

示例12: testSingleNotifyTwice

import io.vertx.rx.java.ObservableHandler; //导入依赖的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();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:ObservableHandlerTest.java


注:本文中的io.vertx.rx.java.ObservableHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。