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


Java RxHelper.observableFuture方法代码示例

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


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

示例1: 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

示例2: deployVerticle

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
/**
 * Deploy a new verticle with the standard configuration of this instance
 * @param cls the class of the verticle class to deploy
 * @return a single that will carry the verticle's deployment id
 */
protected Single<String> deployVerticle(Class<? extends Verticle> cls) {
  ObservableFuture<String> observable = RxHelper.observableFuture();
  DeploymentOptions options = new DeploymentOptions().setConfig(config());
  vertx.deployVerticle(cls.getName(), options, observable.toHandler());
  return observable.toSingle();
}
 
开发者ID:georocket,项目名称:georocket,代码行数:12,代码来源:GeoRocket.java

示例3: deployHttpServer

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
/**
 * Deploy the http server.
 * @return a single that will complete when the http server was started.
 */
protected Single<HttpServer> deployHttpServer() {
  String host = config().getString(ConfigConstants.HOST, ConfigConstants.DEFAULT_HOST);
  int port = config().getInteger(ConfigConstants.PORT, ConfigConstants.DEFAULT_PORT);

  Router router = createRouter();
  HttpServerOptions serverOptions = createHttpServerOptions();
  HttpServer server = vertx.createHttpServer(serverOptions);

  ObservableFuture<HttpServer> observable = RxHelper.observableFuture();
  server.requestHandler(router::accept).listen(port, host, observable.toHandler());
  return observable.toSingle();
}
 
开发者ID:georocket,项目名称:georocket,代码行数:17,代码来源:GeoRocket.java

示例4: detectContentType

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
/**
 * Try to detect the content type of a file
 * @param filepath the absolute path to the file to analyse
 * @return an observable emitting either the detected content type or an error
 * if the content type could not be detected or the file could not be read
 */
private Observable<String> detectContentType(String filepath) {
  ObservableFuture<String> result = RxHelper.observableFuture();
  Handler<AsyncResult<String>> resultHandler = result.toHandler();
  
  vertx.<String>executeBlocking(f -> {
    try {
      String mimeType = MimeTypeUtils.detect(new File(filepath));
      if (mimeType == null) {
        log.warn("Could not detect file type for " + filepath + ". Using "
          + "application/octet-stream.");
        mimeType = "application/octet-stream";
      }
      f.complete(mimeType);
    } catch (IOException e) {
      f.fail(e);
    }
  }, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      String ct = ar.result();
      if (ct != null) {
        resultHandler.handle(Future.succeededFuture(ar.result()));
      } else {
        resultHandler.handle(Future.failedFuture(new HttpException(215)));
      }
    }
  });
  
  return result;
}
 
开发者ID:georocket,项目名称:georocket,代码行数:38,代码来源:StoreEndpoint.java

示例5: getOne

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
  String absolutePath = Paths.get(root, path).toString();

  // check if chunk exists
  FileSystem fs = vertx.fileSystem();
  ObservableFuture<Boolean> observable = RxHelper.observableFuture();
  fs.exists(absolutePath, observable.toHandler());
  observable
    .flatMap(exists -> {
      if (!exists) {
        return Observable.error(new FileNotFoundException("Could not find chunk: " + path));
      }
      return Observable.just(exists);
    })
    .flatMap(exists -> {
      // get chunk's size
      ObservableFuture<FileProps> propsObservable = RxHelper.observableFuture();
      fs.props(absolutePath, propsObservable.toHandler());
      return propsObservable;
    })
    .map(props -> props.size())
    .flatMap(size -> {
      // open chunk
      ObservableFuture<AsyncFile> openObservable = RxHelper.observableFuture();
      OpenOptions openOptions = new OpenOptions().setCreate(false).setWrite(false);
      fs.open(absolutePath, openOptions, openObservable.toHandler());
      return openObservable.map(f -> new FileChunkReadStream(size, f));
    })
    .subscribe(readStream -> {
      // send chunk to peer
      handler.handle(Future.succeededFuture(readStream));
    }, err -> {
      handler.handle(Future.failedFuture(err));
    });
}
 
开发者ID:georocket,项目名称:georocket,代码行数:37,代码来源:FileStore.java

示例6: setupMockEndpoint

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
private static Observable<HttpServer> setupMockEndpoint() {
  JsonObject config = vertx.getOrCreateContext().config();
  String host = config.getString(ConfigConstants.HOST, ConfigConstants.DEFAULT_HOST);
  int port = config.getInteger(ConfigConstants.PORT, ConfigConstants.DEFAULT_PORT);

  HttpServerOptions serverOptions = new HttpServerOptions().setCompressionSupported(true);
  HttpServer server = vertxCore.createHttpServer(serverOptions);

  ObservableFuture<HttpServer> observable = RxHelper.observableFuture();
  server.requestHandler(getStoreEndpointRouter()::accept).listen(port, host, observable.toHandler());
  return observable;
}
 
开发者ID:georocket,项目名称:georocket,代码行数:13,代码来源:StoreEndpointTest.java

示例7: start

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

    ObservableFuture<NetServer> netServerObservable = RxHelper.observableFuture();
    NetServer netServer = vertx.createNetServer(new NetServerOptions().setPort(port));
    netServerObservable.subscribe(a ->
            log.info("Starting TCP listener.."),
            e -> log.error("Could not start TCP listener on port " + port, e),
            () -> log.info("Started TCP listener on port " + port + ".")
    );

    RxHelper.toObservable(netServer.connectStream())
            .flatMap(s -> Riemann.convertBufferStreamToMessages(s, RxHelper.toObservable(s)))
            .subscribe(s -> {
                sendResponse(Proto.Msg.newBuilder().setOk(true).build(), s.getLeft());
                vertx.eventBus().publish("riemann.stream", s.getRight().toByteArray());
            }, e -> {
                log.error(e);

                if (e instanceof NetSocketException) {
                    sendResponse(Proto.Msg.newBuilder().setError(e.getMessage()).build(), ((NetSocketException) e).getSocket());
                }
            });

    netServer.listen(netServerObservable.asHandler());
}
 
开发者ID:blakepettersson,项目名称:reactmann,代码行数:28,代码来源:TcpMessageVerticle.java

示例8: observableFuture

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
public void observableFuture(Vertx vertx) {
  ObservableFuture<HttpServer> observable = RxHelper.observableFuture();
  observable.subscribe(
      server -> {
        // Server is listening
      },
      failure -> {
        // Server could not start
      }
  );
  vertx.createHttpServer(new HttpServerOptions().
      setPort(1234).
      setHost("localhost")
  ).listen(observable.toHandler());
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:16,代码来源:NativeExamples.java

示例9: testCompleteWithSuccessBeforeSubscribe

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testCompleteWithSuccessBeforeSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  o.toHandler().handle(Future.succeededFuture("abc"));
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:9,代码来源:AsyncResultHandlerTest.java

示例10: testCompleteWithSuccessAfterSubscribe

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testCompleteWithSuccessAfterSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertEmpty();
  o.toHandler().handle(Future.succeededFuture("abc"));
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:AsyncResultHandlerTest.java

示例11: testCompleteWithFailureBeforeSubscribe

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testCompleteWithFailureBeforeSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  Throwable failure = new Throwable();
  o.toHandler().handle(Future.failedFuture(failure));
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertError(failure).assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:AsyncResultHandlerTest.java

示例12: testCompleteWithFailureAfterSubscribe

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testCompleteWithFailureAfterSubscribe() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  subscriber.assertEmpty();
  Throwable failure = new Throwable();
  o.toHandler().handle(Future.failedFuture(failure));
  subscriber.assertError(failure).assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:11,代码来源:AsyncResultHandlerTest.java

示例13: testUnsubscribeBeforeResolve

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testUnsubscribeBeforeResolve() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  subscriber.unsubscribe();
  assertTrue(subscriber.isUnsubscribed());
  subscriber.assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:AsyncResultHandlerTest.java

示例14: testCompleteTwice

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testCompleteTwice() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  o.toHandler().handle(Future.succeededFuture("abc"));
  o.toHandler().handle(Future.succeededFuture("def"));
  subscriber.assertItem("abc").assertCompleted().assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:10,代码来源:AsyncResultHandlerTest.java

示例15: testFailTwice

import io.vertx.rx.java.RxHelper; //导入方法依赖的package包/类
@Test
public void testFailTwice() {
  ObservableFuture<String> o = RxHelper.observableFuture();
  SimpleSubscriber<String> subscriber = new SimpleSubscriber<>();
  subscribe(o, subscriber);
  Throwable failure = new Throwable();
  o.toHandler().handle(Future.failedFuture(failure));
  o.toHandler().handle(Future.failedFuture(new Throwable()));
  subscriber.assertError(failure).assertEmpty();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:11,代码来源:AsyncResultHandlerTest.java


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