Search in sources :

Example 76 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-micrometer-metrics by vert-x3.

the class MetricsExamples method createPartialSnapshot.

public void createPartialSnapshot() {
    HttpServer server = vertx.createHttpServer();
    MetricsService metricsService = MetricsService.create(server);
    JsonObject metrics = metricsService.getMetricsSnapshot();
    System.out.println(metrics);
}
Also used : MetricsService(io.vertx.micrometer.MetricsService) HttpServer(io.vertx.core.http.HttpServer) JsonObject(io.vertx.core.json.JsonObject)

Example 77 with HttpServer

use of io.vertx.core.http.HttpServer in project strimzi by strimzi.

the class Session method stop.

/**
 * Stop the controller.
 */
@Override
public void stop(Future<Void> stopFuture) throws Exception {
    this.stopped = true;
    vertx.executeBlocking(blockingResult -> {
        long t0 = System.currentTimeMillis();
        long timeout = 120_000L;
        LOGGER.info("Stopping");
        LOGGER.debug("Stopping kube watch");
        topicCmWatch.close();
        LOGGER.debug("Stopping zk watches");
        topicsWatcher.stop();
        while (controller.isWorkInflight()) {
            if (System.currentTimeMillis() - t0 > timeout) {
                LOGGER.error("Timeout waiting for inflight work to finish");
                break;
            }
            LOGGER.debug("Waiting for inflight work to finish");
            try {
                Thread.sleep(1_000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        LOGGER.debug("Stopping kafka {}", kafka);
        kafka.stop();
        try {
            LOGGER.debug("Disconnecting from zookeeper {}", zk);
            zk.disconnect();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        LOGGER.debug("Closing AdminClient {}", adminClient);
        adminClient.close(timeout - (System.currentTimeMillis() - t0), TimeUnit.MILLISECONDS);
        HttpServer healthServer = this.healthServer;
        if (healthServer != null) {
            healthServer.close();
        }
        LOGGER.info("Stopped");
        blockingResult.complete();
    }, stopFuture);
}
Also used : HttpServer(io.vertx.core.http.HttpServer)

Example 78 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-sync by vert-x3.

the class TestVerticle method testFiberHandler.

@Suspendable
protected void testFiberHandler() {
    HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
    server.requestHandler(fiberHandler(req -> {
        String res = awaitResult(h -> ai.methodWithParamsAndHandlerNoReturn("oranges", 23, h));
        assertEquals("oranges23", res);
        req.response().end();
    }));
    server.listen(res -> {
        assertTrue(res.succeeded());
        HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
        client.getNow("/somepath", resp -> {
            assertTrue(resp.statusCode() == 200);
            client.close();
            server.close(res2 -> {
                complete();
            });
        });
    });
}
Also used : VertxException(io.vertx.core.VertxException) Strand(co.paralleluniverse.strands.Strand) HttpServer(io.vertx.core.http.HttpServer) Context(io.vertx.core.Context) Is(org.hamcrest.core.Is) Channel(co.paralleluniverse.strands.channels.Channel) Suspendable(co.paralleluniverse.fibers.Suspendable) EventBus(io.vertx.core.eventbus.EventBus) SyncVerticle(io.vertx.ext.sync.SyncVerticle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReturnedInterface(io.vertx.ext.sync.testmodel.ReturnedInterface) Channels(co.paralleluniverse.strands.channels.Channels) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Method(java.lang.reflect.Method) Sync(io.vertx.ext.sync.Sync) AsyncInterface(io.vertx.ext.sync.testmodel.AsyncInterface) Vertx(io.vertx.core.Vertx) HandlerReceiverAdaptor(io.vertx.ext.sync.HandlerReceiverAdaptor) Message(io.vertx.core.eventbus.Message) SuspendExecution(co.paralleluniverse.fibers.SuspendExecution) TimeUnit(java.util.concurrent.TimeUnit) ReceivePort(co.paralleluniverse.strands.channels.ReceivePort) HttpServerOptions(io.vertx.core.http.HttpServerOptions) AsyncInterfaceImpl(io.vertx.ext.sync.testmodel.AsyncInterfaceImpl) Assert(org.junit.Assert) HttpClient(io.vertx.core.http.HttpClient) HttpClient(io.vertx.core.http.HttpClient) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Suspendable(co.paralleluniverse.fibers.Suspendable)

Example 79 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-zero by silentbalanceyh.

the class ZeroSockAgent method start.

@Override
public void start() {
    // Server Listen
    ZeroAtomic.SOCK_OPTS.forEach((port, option) -> {
        /**
         * Create Server *
         */
        final HttpServer server = this.vertx.createHttpServer(option);
        final Router router = Router.router(this.vertx);
        /**
         * Handler *
         */
        server.requestHandler(router::accept).listen();
    });
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router)

Example 80 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-zero by silentbalanceyh.

the class ZeroHttpAgent method start.

@Override
public void start() {
    /**
     * 1.Call router hub to mount commont *
     */
    final Axis<Router> routerAxiser = Fn.poolThread(Pool.ROUTERS, () -> Instance.instance(RouterAxis.class));
    /**
     * 2.Call route hub to mount defined *
     */
    final Axis<Router> axiser = Fn.poolThread(Pool.EVENTS, () -> Instance.instance(EventAxis.class));
    /**
     * 3.Call route hub to mount walls *
     */
    final Axis<Router> wallAxiser = Fn.poolThread(Pool.WALLS, () -> Instance.instance(WallAxis.class, this.vertx));
    /**
     * 4.Call route hub to mount filters *
     */
    final Axis<Router> filterAxiser = Fn.poolThread(Pool.FILTERS, () -> Instance.instance(FilterAxis.class));
    /**
     * 5.Get the default HttpServer Options *
     */
    ZeroAtomic.HTTP_OPTS.forEach((port, option) -> {
        /**
         * 5.1.Single server processing *
         */
        final HttpServer server = this.vertx.createHttpServer(option);
        /**
         * 5.2. Build router with current option *
         */
        final Router router = Router.router(this.vertx);
        /**
         * 5.3. Mount data to router *
         */
        // Router
        routerAxiser.mount(router);
        // Wall
        wallAxiser.mount(router);
        // Event
        axiser.mount(router);
        // Filter
        filterAxiser.mount(router);
        /**
         * 5.4.Listen for router on the server *
         */
        server.requestHandler(router::accept).listen();
        {
            // 5.5. Log output
            this.registryServer(option, router);
        }
    });
}
Also used : EventAxis(io.vertx.up.rs.router.EventAxis) RouterAxis(io.vertx.up.rs.router.RouterAxis) WallAxis(io.vertx.up.rs.router.WallAxis) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) FilterAxis(io.vertx.up.rs.router.FilterAxis)

Aggregations

HttpServer (io.vertx.core.http.HttpServer)82 Router (io.vertx.ext.web.Router)37 HttpServerOptions (io.vertx.core.http.HttpServerOptions)32 Test (org.junit.Test)24 JsonObject (io.vertx.core.json.JsonObject)17 Buffer (io.vertx.core.buffer.Buffer)14 HttpServerResponse (io.vertx.core.http.HttpServerResponse)14 Future (io.vertx.core.Future)12 HttpClient (io.vertx.core.http.HttpClient)12 Vertx (io.vertx.core.Vertx)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 Handler (io.vertx.core.Handler)9 HttpMethod (io.vertx.core.http.HttpMethod)9 VertxOptions (io.vertx.core.VertxOptions)8 HttpClientOptions (io.vertx.core.http.HttpClientOptions)8 List (java.util.List)8 AbstractVerticle (io.vertx.core.AbstractVerticle)7 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 AsyncResult (io.vertx.core.AsyncResult)6