• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RxHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: fetchPage

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPage(String name, Handler<AsyncResult<JsonObject>> resultHandler) {
  dbClient.rxQueryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), new JsonArray().add(name))
    .map(result -> {
      if (result.getNumRows() > 0) {
        JsonArray row = result.getResults().get(0);
        return new JsonObject()
          .put("found", true)
          .put("id", row.getInteger(0))
          .put("rawContent", row.getString(1));
      } else {
        return new JsonObject().put("found", false);
      }
    })
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:18,代码来源:WikiDatabaseServiceImpl.java


示例2: fetchPageById

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPageById(int id, Handler<AsyncResult<JsonObject>> resultHandler) {
  // tag::rx-execute-query-with-params[]
  Single<ResultSet> resultSet = dbClient.rxQueryWithParams(
    sqlQueries.get(SqlQuery.GET_PAGE_BY_ID), new JsonArray().add(id));
  // end::rx-execute-query-with-params[]
  resultSet
    .map(result -> {
      if (result.getNumRows() > 0) {
        JsonObject row = result.getRows().get(0);
        return new JsonObject()
          .put("found", true)
          .put("id", row.getInteger("ID"))
          .put("name", row.getString("NAME"))
          .put("content", row.getString("CONTENT"));
      } else {
        return new JsonObject().put("found", false);
      }
    })
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:23,代码来源:WikiDatabaseServiceImpl.java


示例3: fetchPageById

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPageById(int id, Handler<AsyncResult<JsonObject>> resultHandler) {
  Single<ResultSet> resultSet = dbClient.rxQueryWithParams(
    sqlQueries.get(SqlQuery.GET_PAGE_BY_ID), new JsonArray().add(id));
  resultSet
    .map(result -> {
      if (result.getNumRows() > 0) {
        JsonObject row = result.getRows().get(0);
        return new JsonObject()
          .put("found", true)
          .put("id", row.getInteger("ID"))
          .put("name", row.getString("NAME"))
          .put("content", row.getString("CONTENT"));
      } else {
        return new JsonObject().put("found", false);
      }
    })
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:21,代码来源:WikiDatabaseServiceImpl.java


示例4: 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));
}
 
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:18,代码来源:RecentPurchasesHandler.java


示例5: chunkToDocument

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
/**
 * Convert a chunk to a Elasticsearch document
 * @param chunk the chunk to convert
 * @param fallbackCRSString a string representing the CRS that should be used
 * to index the chunk if it does not specify a CRS itself (may be null if no
 * CRS is available as fallback)
 * @param parserOperator the operator used to parse the chunk stream into
 * stream events
 * @param indexerFactories a sequence of indexer factories that should be
 * used to index the chunk
 * @param <T> the type of the stream events created by <code>parserOperator</code>
 * @return an observable that will emit the document
 */
private <T extends StreamEvent> Observable<Map<String, Object>> chunkToDocument(
    ChunkReadStream chunk, String fallbackCRSString,
    Operator<T, Buffer> parserOperator,
    List<? extends IndexerFactory> indexerFactories) {
  List<StreamIndexer<T>> indexers = new ArrayList<>();
  indexerFactories.forEach(factory -> {
    @SuppressWarnings("unchecked")
    StreamIndexer<T> i = (StreamIndexer<T>)factory.createIndexer();
    if (fallbackCRSString != null && i instanceof CRSAware) {
      ((CRSAware)i).setFallbackCRSString(fallbackCRSString);
    }
    indexers.add(i);
  });
  
  return RxHelper.toObservable(chunk)
    .lift(parserOperator)
    .doOnNext(e -> indexers.forEach(i -> i.onEvent(e)))
    .last() // "wait" until the whole chunk has been consumed
    .map(e -> {
      // create the Elasticsearch document
      Map<String, Object> doc = new HashMap<>();
      indexers.forEach(i -> doc.putAll(i.getResult()));
      return doc;
    });
}
 
开发者ID:georocket,项目名称:georocket,代码行数:39,代码来源:IndexerVerticle.java


示例6: testStreamRX

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Test
public void testStreamRX() {
  String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID";
  connection().queryStream(sql, onSuccess(res -> {

    final AtomicInteger cnt = new AtomicInteger(0);

    Observable<JsonArray> observable = RxHelper.toObservable(res);
    observable.subscribe(
      // handle one row
      row -> {
        assertEquals("doe", row.getString(res.column("lname")));
        cnt.incrementAndGet();
      },
      // it should not fail
      this::fail,
      () -> {
        assertEquals(2, cnt.get());
        testComplete();
      });
  }));

  await();
}
 
开发者ID:vert-x3,项目名称:vertx-jdbc-client,代码行数:25,代码来源:JDBCClientTest.java


示例7: start

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public void start() throws Exception {
    //TODO: Fix a better way of configuration other than system properties?
    Integer port = Integer.getInteger("websocket.port", 5556);

    ObservableFuture<HttpServer> httpServerObservable = RxHelper.observableFuture();
    HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions().setPort(port));
    httpServerObservable.subscribe(
            a -> log.info("Starting web socket listener..."),
            e -> log.error("Could not start web socket listener at port " + port, e),
            () -> log.info("Started web socket listener on port " + port)
    );

    Observable<Tup2<ServerWebSocket, Func1<Event, Boolean>>> eventObservable = EventObservable.convertFromWebSocketObservable(RxHelper.toObservable(httpServer.websocketStream()));
    eventObservable.subscribe(new EventToJsonAction(Riemann.getEvents(vertx), WebSocketFrameImpl::new), e -> {
        log.error(e);
        //TODO: Fix proper error handling
    });

    httpServer.listen(httpServerObservable.asHandler());
}
 
开发者ID:blakepettersson,项目名称:reactmann,代码行数:22,代码来源:WebSocketVerticle.java


示例8: testScheduledTimer

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Test
public void testScheduledTimer() {
  vertx.runOnContext(v -> {
    long startTime = System.currentTimeMillis();
    Context initCtx = Vertx.currentContext();
    Observable.timer(100, 100, TimeUnit.MILLISECONDS, io.vertx.rxjava.core.RxHelper.scheduler(vertx)).take(10).subscribe(new Observer<Long>() {
      public void onNext(Long value) {
        assertEquals(initCtx.getDelegate(), Vertx.currentContext().getDelegate());
      }

      public void onError(Throwable e) {
        fail("unexpected failure");
      }

      public void onCompleted() {
        long timeTaken = System.currentTimeMillis() - startTime;
        assertTrue("Was expecting to have time taken | " + timeTaken + " -  1000 | < 200", Math.abs(timeTaken - 1000) < 1000);
        testComplete();
      }
    });
  });
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:24,代码来源:CoreApiTest.java


示例9: testObserverToHandler

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Test
public void testObserverToHandler() throws Exception {
  AtomicInteger count = new AtomicInteger();
  Observer<Long> observer = new Observer<Long>() {
    @Override
    public void onCompleted() {
      assertEquals(1, count.get());
      testComplete();
    }

    @Override
    public void onError(Throwable e) {
      fail(e.getMessage());
    }

    @Override
    public void onNext(Long l) {
      count.incrementAndGet();
    }
  };
  vertx.setTimer(1, RxHelper.toHandler(observer));
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:24,代码来源:CoreApiTest.java


示例10: 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");
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:30,代码来源:MyResource.java


示例11: WikiDatabaseServiceImpl

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
WikiDatabaseServiceImpl(io.vertx.ext.jdbc.JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
  this.dbClient = new JDBCClient(dbClient);
  this.sqlQueries = sqlQueries;

  getConnection()
    .flatMap(conn -> conn.rxExecute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE)))
    .map(v -> this)
    .subscribe(RxHelper.toSubscriber(readyHandler));
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:10,代码来源:WikiDatabaseServiceImpl.java


示例12: fetchAllPages

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
// tag::rx-data-flow[]
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
  dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES))
    .flatMapObservable(res -> {  // <1>
      List<JsonArray> results = res.getResults();
      return Observable.from(results); // <2>
    })
    .map(json -> json.getString(0)) // <3>
    .sorted() // <4>
    .collect(JsonArray::new, JsonArray::add) // <5>
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:15,代码来源:WikiDatabaseServiceImpl.java


示例13: createPage

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService createPage(String title, String markdown, Handler<AsyncResult<Void>> resultHandler) {
  dbClient.rxUpdateWithParams(sqlQueries.get(SqlQuery.CREATE_PAGE), new JsonArray().add(title).add(markdown))
    .map(res -> (Void) null)
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:8,代码来源:WikiDatabaseServiceImpl.java


示例14: savePage

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService savePage(int id, String markdown, Handler<AsyncResult<Void>> resultHandler) {
  dbClient.rxUpdateWithParams(sqlQueries.get(SqlQuery.SAVE_PAGE), new JsonArray().add(markdown).add(id))
    .map(res -> (Void) null)
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:8,代码来源:WikiDatabaseServiceImpl.java


示例15: deletePage

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService deletePage(int id, Handler<AsyncResult<Void>> resultHandler) {
  JsonArray data = new JsonArray().add(id);
  dbClient.rxUpdateWithParams(sqlQueries.get(SqlQuery.DELETE_PAGE), data)
    .map(res -> (Void) null)
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:9,代码来源:WikiDatabaseServiceImpl.java


示例16: fetchAllPagesData

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchAllPagesData(Handler<AsyncResult<List<JsonObject>>> resultHandler) { // <1>
  dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES_DATA))
    .map(ResultSet::getRows)
    .subscribe(RxHelper.toSubscriber(resultHandler));  // <2>
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:8,代码来源:WikiDatabaseServiceImpl.java


示例17: fetchAllPages

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
  dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES))
    .flatMapObservable(res -> {
      List<JsonArray> results = res.getResults();
      return Observable.from(results);
    })
    .map(json -> json.getString(0))
    .sorted()
    .collect(JsonArray::new, JsonArray::add)
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:14,代码来源:WikiDatabaseServiceImpl.java


示例18: fetchAllPagesData

import io.vertx.rx.java.RxHelper; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchAllPagesData(Handler<AsyncResult<List<JsonObject>>> resultHandler) {
  dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES_DATA))
    .map(ResultSet::getRows)
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:8,代码来源:WikiDatabaseServiceImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SignData类代码示例发布时间:2022-05-22
下一篇:
Java TerrainLodControl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap