public class MyVerticle extends AbstractVerticle {
private HttpServeer server;
public void start(Future<Void> startFuture) {
server = vertx.createHttpServer().requestHandler(req -> {
req.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
});
// Server的listen方法本身是一个异步动作,绑定了一个异步回调
server.listen(8080, res -> {
if (res.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(res.cause());
}
});
}
}
public class MyVerticle extends AbstractVerticle {
private HttpServeer server;
public void start() {
server = vertx.createHttpServer().requestHandler(req -> {
req.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
});
// Now bind the server:
server.listen(8080, res -> {
if (res.succeeded()) {
System.out.println("Successed");
} else {
System.out.println("Failure");
}
});
}
}
/**
* Undeploy a verticle deployment.
* <p>
* The actual undeployment happens asynchronously and may not complete
* until after the method has returned.
*
* @param deploymentID the deployment ID
*/
void undeploy(String deploymentID);
/**
* Like {@link #undeploy(String) } but the completionHandler will be notified
* when the undeployment is complete.
*
* @param deploymentID the deployment ID
* @param completionHandler a handler which will be notified when the undeployment is complete
*/
void undeploy(String deploymentID, Handler<AsyncResult<Void>> completionHandler);