Example usage for io.vertx.core.http HttpServer listen

List of usage examples for io.vertx.core.http HttpServer listen

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServer listen.

Prototype

@Fluent
HttpServer listen(Handler<AsyncResult<HttpServer>> listenHandler);

Source Link

Document

Like #listen but supplying a handler that will be called when the server is actually listening (or has failed).

Usage

From source file:eu.rethink.mn.MsgNode.java

License:Apache License

@Override
public void start() throws Exception {
    final PipeRegistry register = new PipeRegistry(vertx, mgr, config.getDomain());
    register.installComponent(new SubscriptionManager(register));
    register.installComponent(new SessionManager(register));
    register.installComponent(new HypertyAllocationManager(register));
    register.installComponent(new ObjectAllocationManager(register));
    register.installComponent(new AllocationManager(register));

    final RegistryConnector rc = new RegistryConnector(register);
    register.installComponent(rc);/*from w w  w  .j  a  v  a  2s .c o m*/

    final GlobalRegistryConnector grc = new GlobalRegistryConnector(register);
    register.installComponent(grc);

    final Pipeline pipeline = new Pipeline(register).addHandler(new ValidatorPipeHandler()) //validation of mandatory fields
            .addHandler(new TransitionPipeHandler()) //inter-domain allocator and routing
            .addHandler(new PoliciesPipeHandler()).failHandler(error -> {
                out.println("PIPELINE-FAIL: " + error);
            });

    //HTTPS security configurations
    final JksOptions jksOptions = new JksOptions().setPath("server-keystore.jks").setPassword("rethink2015");

    final HttpServerOptions httpOptions = new HttpServerOptions().setTcpKeepAlive(true).setSsl(true)
            .setKeyStoreOptions(jksOptions).setMaxWebsocketFrameSize(6553600);

    final HttpServer server = vertx.createHttpServer(httpOptions);
    server.requestHandler(req -> {
        //just a land page to test connection
        System.out.println("HTTP-PING");
        req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello</h1></body></html>");
    });

    WebSocketServer.init(server, pipeline);
    server.listen(config.getPort());
    System.out.println("[Message-Node] Running with config: " + config);
}

From source file:examples.CoreExamples.java

License:Open Source License

public void exampleFutureAll1(HttpServer httpServer, NetServer netServer) {
    Future<HttpServer> httpServerFuture = Future.future();
    httpServer.listen(httpServerFuture.completer());

    Future<NetServer> netServerFuture = Future.future();
    netServer.listen(netServerFuture.completer());

    CompositeFuture.all(httpServerFuture, netServerFuture).setHandler(ar -> {
        if (ar.succeeded()) {
            // All servers started
        } else {/*from  w  ww .j a va  2 s.c  om*/
            // At least one server failed
        }
    });
}

From source file:io.nonobot.core.impl.BotImpl.java

License:Apache License

public static Bot createShared(Vertx vertx, BotOptions options, Handler<AsyncResult<Void>> completionHandler) {
    BotImpl bot = bots.computeIfAbsent(new Key(vertx, options.getName()),
            key -> new BotImpl(vertx, options.getName()));
    HttpServer server;
    if (options.getHttpServerOptions() != null) {
        server = vertx.createHttpServer(options.getHttpServerOptions());
        server.requestHandler(bot.webRouter::accept);
        server.listen(ar -> {
            if (ar.succeeded()) {
                completionHandler.handle(Future.succeededFuture());
            } else {
                completionHandler.handle(Future.failedFuture(ar.cause()));
            }//from w  w w .j  a v  a 2s  .  c o m
        });
    } else {
        server = null;
        completionHandler.handle(Future.succeededFuture());
    }
    return new Bot() {
        @Override
        public Vertx vertx() {
            return bot.vertx();
        }

        @Override
        public ChatRouter chatRouter() {
            return bot.chatRouter();
        }

        @Override
        public Router webRouter() {
            return bot.webRouter();
        }

        @Override
        public String name() {
            return bot.name();
        }

        @Override
        public void close() {
            boolean open = bot.closed;
            bot.close();
            if (open && server != null) {
                server.close();
            }
        }
    };
}

From source file:io.silverware.microservices.providers.cdi.internal.RestInterface.java

License:Apache License

@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.get("/rest").handler(this::listBeans);
    router.get("/rest/:microservice").handler(this::listMethods);
    router.get("/rest/:microservice/:method").handler(this::callNoParamMethod);
    router.post("/rest/:microservice/:method").handler(this::callMethod);

    HttpServerOptions options = new HttpServerOptions().setAcceptBacklog(1000);
    HttpServer server = vertx.createHttpServer(options).requestHandler(router::accept);
    if (host.isEmpty()) {
        server.listen(port);
    } else {//from   w w w  .  ja  va2s . c  om
        server.listen(port, host);
    }
}