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());
}
});
}
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());
}
});
}
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());
}
});
}
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();
}
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();
}
Aggregations