use of io.vertx.core.Promise in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// The rcp service
PingPongServiceGrpc.PingPongServiceVertxImplBase service = new PingPongServiceGrpc.PingPongServiceVertxImplBase() {
@Override
public void unaryCall(Messages.SimpleRequest request, Promise<Messages.SimpleResponse> future) {
future.complete(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build());
}
};
// Create the server
VertxServer rpcServer = VertxServerBuilder.forPort(vertx, 8080).addService(service).build();
// start the server
rpcServer.start(ar -> {
if (ar.failed()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.core.Promise in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
URL featureFile = Util.getDefaultFeaturesFile();
features = Util.parseFeatures(featureFile);
VertxServer server = VertxServerBuilder.forAddress(vertx, "localhost", 8080).addService(new RouteGuideGrpc.RouteGuideVertxImplBase() {
@Override
public void getFeature(Point request, Promise<Feature> response) {
response.complete(checkFeature(request));
}
@Override
public void listFeatures(Rectangle request, GrpcWriteStream<Feature> response) {
int left = Math.min(request.getLo().getLongitude(), request.getHi().getLongitude());
int right = Math.max(request.getLo().getLongitude(), request.getHi().getLongitude());
int top = Math.max(request.getLo().getLatitude(), request.getHi().getLatitude());
int bottom = Math.min(request.getLo().getLatitude(), request.getHi().getLatitude());
for (Feature feature : features) {
if (!Util.exists(feature)) {
continue;
}
int lat = feature.getLocation().getLatitude();
int lon = feature.getLocation().getLongitude();
if (lon >= left && lon <= right && lat >= bottom && lat <= top) {
response.write(feature);
}
}
response.end();
}
@Override
public void recordRoute(GrpcReadStream<Point> request, Future<RouteSummary> response) {
request.exceptionHandler(err -> {
System.out.println("recordRoute cancelled");
});
RouteRecorder recorder = new RouteRecorder();
request.handler(recorder::append);
request.endHandler(v -> {
response.complete(recorder.build());
});
}
@Override
public void routeChat(GrpcBidiExchange<RouteNote, RouteNote> exchange) {
exchange.handler(note -> {
List<RouteNote> notes = getOrCreateNotes(note.getLocation());
// Respond with all previous notes at this location.
for (RouteNote prevNote : notes.toArray(new RouteNote[0])) {
exchange.write(prevNote);
}
// Now add the new note to the list
notes.add(note);
});
exchange.exceptionHandler(err -> {
System.out.println("routeChat cancelled");
});
exchange.endHandler(v -> exchange.end());
}
}).build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
use of io.vertx.core.Promise in project raml-module-builder by folio-org.
the class PostgresClientIT method selectReturnOneRow.
@Test
public void selectReturnOneRow(TestContext context) {
List<String> columns = new LinkedList<>();
columns.add("field");
RowDesc rowDesc = new RowDesc(columns);
List<Row> rows = new LinkedList<>();
Row row = new RowImpl(rowDesc);
row.addString("value");
rows.add(row);
RowSet rowSet = new LocalRowSet(1).withColumns(columns).withRows(rows);
Promise<RowSet<Row>> promise = Promise.promise();
promise.complete(rowSet);
PostgresClient.selectReturn(promise.future(), context.asyncAssertSuccess(res -> context.assertEquals("value", res.getString(0))));
}
use of io.vertx.core.Promise in project raml-module-builder by folio-org.
the class RestVerticle method start.
@Override
public void start(Promise<Void> startPromise) throws Exception {
readInGitProps();
// process cmd line arguments
cmdProcessing(processArgs());
deploymentId = UUID.randomUUID().toString();
log.info("metrics enabled: {}", vertx.isMetricsEnabled());
packageOfImplementations = config().getString("packageOfImplementations", DomainModelConsts.PACKAGE_OF_IMPLEMENTATIONS);
// Create a router object.
Router router = Router.router(vertx);
// single handler for all url calls other then documentation
// which is handled separately
// router.routeWithRegex("^(?!.*apidocs).*$").handler(rc -> route(mappedURLs, urlPaths, regex2Pattern, rc));
// routes requests on “/assets/*” to resources stored in the “assets”
// directory.
router.route("/assets/*").handler(StaticHandler.create("assets"));
// In the following example all requests to paths starting with
// /apidocs/ will get served from the directory resources/apidocs:
// example:
// http://localhost:8181/apidocs/index.html?raml=raml/_patrons.raml
router.route("/apidocs/*").handler(StaticHandler.create("apidocs"));
RestRouting.populateRoutes(router, packageOfImplementations).compose(x -> runHook()).compose(x -> {
HttpServer server = vertx.createHttpServer(httpServerOptions);
String portS = System.getProperty(HTTP_PORT_SETTING);
int port;
if (portS != null) {
port = Integer.parseInt(portS);
config().put(HTTP_PORT_SETTING, port);
} else {
// we are here if port was not passed via cmd line
port = config().getInteger(HTTP_PORT_SETTING, 8081);
}
log.info("Listening port {}", port);
return server.requestHandler(router).listen(port);
}).<Void>compose(ret -> {
try {
// startup periodic impl if exists
runPeriodicHook();
} catch (Exception e) {
log.error(e.getMessage(), e);
return Future.failedFuture(e);
}
// check if mock mode requested and set sys param so that http client factory
// can config itself accordingly
String mockMode = config().getString(HttpClientMock2.MOCK_MODE);
if (mockMode != null) {
System.setProperty(HttpClientMock2.MOCK_MODE, mockMode);
HttpClientFactory.setMockEnabled(true);
}
runPostDeployHook(res2 -> {
if (!res2.succeeded()) {
log.error(res2.cause().getMessage(), res2.cause());
}
});
return Future.succeededFuture();
}).onFailure(cause -> log.error(cause.getMessage(), cause)).onComplete(startPromise);
}
use of io.vertx.core.Promise in project chili-core by codingchili.
the class BenchmarkIT method testBenchmarkBuilders.
@Test
public void testBenchmarkBuilders(TestContext test) {
Async async = test.async();
List<BenchmarkGroup> groups = new ArrayList<>();
BiConsumer<BenchmarkGroup, String> addOneOperation = (group, implementation) -> {
group.implementation(implementation).add("sleep1x", Promise::complete).add("sleep2x", Promise::complete);
};
BiConsumer<String, Integer> addOneGroup = (name, iterations) -> {
BenchmarkGroup group = new BenchmarkGroupBuilder(name, iterations);
addOneOperation.accept(group, "fastImplementation");
addOneOperation.accept(group, "slowImplementation");
groups.add(group);
};
addOneGroup.accept("group_1", ITERATIONS);
addOneGroup.accept("group_2", ITERATIONS);
addOneGroup.accept("group_3", ITERATIONS);
new BenchmarkExecutor(context).start(groups).onComplete(done -> {
new BenchmarkHTMLReport(done.result()).saveTo("wowza.html");
async.complete();
});
}
Aggregations