Search in sources :

Example 36 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class EventBusExamples method example14.

public void example14() {
    VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setClusterPublicHost("whatever").setClusterPublicPort(1234));
    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            EventBus eventBus = vertx.eventBus();
            System.out.println("We now have a clustered event bus: " + eventBus);
        } else {
            System.out.println("Failed: " + res.cause());
        }
    });
}
Also used : EventBusOptions(io.vertx.core.eventbus.EventBusOptions) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions)

Example 37 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class FileSystemExamples method asyncFilePump.

public void asyncFilePump() {
    Vertx vertx = Vertx.vertx();
    final AsyncFile output = vertx.fileSystem().openBlocking("target/classes/plagiary.txt", new OpenOptions());
    vertx.fileSystem().open("target/classes/les_miserables.txt", new OpenOptions(), result -> {
        if (result.succeeded()) {
            AsyncFile file = result.result();
            Pump.pump(file, output).start();
            file.endHandler((r) -> {
                System.out.println("Copy done");
            });
        } else {
            System.err.println("Cannot open file " + result.cause());
        }
    });
}
Also used : OpenOptions(io.vertx.core.file.OpenOptions) AsyncFile(io.vertx.core.file.AsyncFile) Vertx(io.vertx.core.Vertx)

Example 38 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class FileSystemExamples method asyncFileRead.

public void asyncFileRead() {
    Vertx vertx = Vertx.vertx();
    vertx.fileSystem().open("target/classes/les_miserables.txt", new OpenOptions(), result -> {
        if (result.succeeded()) {
            AsyncFile file = result.result();
            Buffer buff = Buffer.buffer(1000);
            for (int i = 0; i < 10; i++) {
                file.read(buff, i * 100, i * 100, 100, ar -> {
                    if (ar.succeeded()) {
                        System.out.println("Read ok!");
                    } else {
                        System.err.println("Failed to write: " + ar.cause());
                    }
                });
            }
        } else {
            System.err.println("Cannot open file " + result.cause());
        }
    });
}
Also used : OpenOptions(io.vertx.core.file.OpenOptions) Buffer(io.vertx.core.buffer.Buffer) AsyncFile(io.vertx.core.file.AsyncFile) Vertx(io.vertx.core.Vertx)

Example 39 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class StreamsExamples method pump5.

public void pump5(Vertx vertx) {
    NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
    server.connectHandler(sock -> {
        Pump.pump(sock, sock).start();
    }).listen();
}
Also used : NetServerOptions(io.vertx.core.net.NetServerOptions) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) Vertx(io.vertx.core.Vertx) Pump(io.vertx.core.streams.Pump) Handler(io.vertx.core.Handler) NetSocket(io.vertx.core.net.NetSocket) NetServerOptions(io.vertx.core.net.NetServerOptions) NetServer(io.vertx.core.net.NetServer)

Example 40 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class StreamsExamples method pump3.

public void pump3(Vertx vertx) {
    NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
    server.connectHandler(sock -> {
        sock.handler(buffer -> {
            sock.write(buffer);
            if (sock.writeQueueFull()) {
                sock.pause();
            }
        });
    }).listen();
}
Also used : NetServerOptions(io.vertx.core.net.NetServerOptions) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) Vertx(io.vertx.core.Vertx) Pump(io.vertx.core.streams.Pump) Handler(io.vertx.core.Handler) NetSocket(io.vertx.core.net.NetSocket) NetServerOptions(io.vertx.core.net.NetServerOptions) NetServer(io.vertx.core.net.NetServer)

Aggregations

Vertx (io.vertx.core.Vertx)43 Test (org.junit.Test)17 VertxOptions (io.vertx.core.VertxOptions)11 Buffer (io.vertx.core.buffer.Buffer)10 Handler (io.vertx.core.Handler)8 NetSocket (io.vertx.core.net.NetSocket)7 Pump (io.vertx.core.streams.Pump)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 DeploymentOptions (io.vertx.core.DeploymentOptions)6 VertxInternal (io.vertx.core.impl.VertxInternal)6 NetServer (io.vertx.core.net.NetServer)6 NetServerOptions (io.vertx.core.net.NetServerOptions)6 JsonObject (io.vertx.core.json.JsonObject)5 Launcher (io.vertx.core.Launcher)4 RunCommandTest (io.vertx.core.impl.launcher.commands.RunCommandTest)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 AbstractVerticle (io.vertx.core.AbstractVerticle)3 AsyncResult (io.vertx.core.AsyncResult)3