Vert.x对部署的Verticle有任何开销吗?有没有理由在不需要之后取消部署它们?
请查看MyVerticle
- 它的唯一目的是在应用程序启动时执行load
,在加载此Verticle之后不需要。 拨打consumer.unregister()
是否足够?是否有任何理由要取消部署MyVerticle
?
public class MyVerticle extends AbstractVerticle {
private MessageConsummer consumer;
@Override
public void start() {
consumer = vertx.eventBus().consumer(AppConstants.SOME_ADDRESS, this::load);
}
@Override
public void load(Message message) {
LocalMap<Short, String> map = vertx.sharedData().getLocalMap(AppConstants.MAP_NAME);
try (
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(AppConstants.INDEX_PATH)))
) {
while (true) {
map.put(
in.readShort(),
in.readUTF()
);
}
} catch(EOFException eof) {
message.reply(AppConstants.SUCCESS);
} catch (IOException ioe) {
message.fail(100, "Fail to load index in memory");
throw new RuntimeException("There are no recovery policy", ioe);
} finally {
//is this sufficient or I need to undeploy them programmatically?
consumer.unregister();
}
}
}
答案 0 :(得分:2)
Verticle可以看作是在Vert.x上运行的应用程序,如果您正在执行high availability or failover,则部署/取消部署只会产生很小的开销。在这种情况下,Vert.x将需要跟踪已部署的实例,监视故障并在其他节点上重新生成Verticle等...
取消部署还允许您通过调用stop()
方法执行任何清理(尽管您未在示例中使用它)。
当没有以HA
运行时,取消部署只允许您恢复由Verticle分配的任何内存但不再引用(加上与保持部署Verticle的内部跟踪相关的内存,应该是作为单个对象引用可以忽略不计。)