當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。