vertx verticle 部署和卸载
所属分类 vertx
浏览量 284
直接上例子代码
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import java.time.LocalDateTime;
public class VerticleDeployAndUndeploy extends AbstractVerticle {
private static volatile String deploymentID = null;
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
VerticleDeployAndUndeploy vertical = new VerticleDeployAndUndeploy();
System.out.println("Verticle deploy start,"+LocalDateTime.now());
// deployVerticle 不阻塞 ,回调方法 获取结果
vertx.deployVerticle(vertical,asyncResult -> {
if (asyncResult.succeeded()) {
deploymentID = asyncResult.result();
System.out.println("verticle deployed ok, deploymentID = " + deploymentID+","+LocalDateTime.now());
} else {
System.out.println("verticle deployed error," + asyncResult.cause()+","+LocalDateTime.now());
}
});
System.out.println("now time,"+LocalDateTime.now());
doSleep(2000);
// 部署完成后卸载
System.out.println("deploymentID="+deploymentID+","+LocalDateTime.now());
vertx.undeploy(deploymentID);
}
@Override
public void start() {
doSleep(1000);
System.out.println("Verticle start done,"+LocalDateTime.now());
}
@Override
public void stop() {
System.out.println("Verticle stop done,"+ LocalDateTime.now());
}
public static void doSleep(long time){
try{
Thread.sleep(time);
}catch(Exception e){
//
}
}
//////
start方法抛出异常 部署失败
private static void startInit(boolean error){
if(error){
throw new RuntimeException("verticle start init error");
}
}
Verticle deploy start,2024-01-12T22:50:43.242
now time,2024-01-12T22:50:43.259
Verticle start done,2024-01-12T22:50:44.261
verticle deployed ok, deploymentID = 44bea012-10aa-43e7-903e-1fbb0e77b947,2024-01-12T22:50:44.280
deploymentID=44bea012-10aa-43e7-903e-1fbb0e77b947,2024-01-12T22:50:45.264
Verticle stop done,2024-01-12T22:50:45.288
上一篇
下一篇
JAVA Void类
vertx promise future
vertx verticle 实例
项目和产品技术栈
java8 JavaScript引擎 Nashorn
javascript 字符串相等判断