Reputation: 55
I've two verticles say "A" and "B". Both are running in different JVM instances. Now, A send a message to B "Operation successful. You can undeploy yourself". When B gets this message , it should undeploy itself.
I tried two options : 1. vertx.close(); (a) If Verticle B is opened in different command prompt. (b) If Verticle B is not opened in different command prompt. 2. vertx.undeploy(deploymentID(),); with Verticle B opened as different cmd prompt as well as in the same cmd prompt(A verticle cmd prompt...runs in background)
In 1->(a), Verticle B is closed but cmd prompt is still open. In 1->(b), Verticle B is not closed and JVM is also running. In the second case, i got below error message :
java.lang.IllegalStateException: Unknown deployment
at io.vertx.core.impl.DeploymentManager.undeployVerticle(DeploymentManager.java:203)
at io.vertx.core.impl.VertxImpl.undeploy(VertxImpl.java:587)
at x.y.z.AVerticle.lambda$null$1(AVerticle.java:118)
at io.vertx.core.eventbus.impl.EventBusImpl.lambda$convertHandler$1(EventBusImpl.java:334)
at io.vertx.core.eventbus.impl.HandlerRegistration.deliver(HandlerRegistration.java:213)
at io.vertx.core.eventbus.impl.HandlerRegistration.handle(HandlerRegistration.java:192)
at io.vertx.core.eventbus.impl.EventBusImpl.lambda$deliverToHandler$3(EventBusImpl.java:503)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:359)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:393)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at java.lang.Thread.run(Unknown Source)
Anyone knows how to do this? Thank you :)
Upvotes: 1
Views: 1400
Reputation: 2792
I made an example for a similar case, where the requirement was to undeploy and then terminate the jvm.
https://github.com/floriankammermann/vertx-examples/tree/master/self-terminating
You can use this code too. You just have to remove the System.exit(0);
in https://github.com/floriankammermann/vertx-examples/blob/master/self-terminating/src/main/java/org/swisspush/vertx/examples/SelfTerminated.java
A restriction here is, that you have too deploy your verticle programmatically.
In your case the verticle A and B have to be connected (can send messages to each other) over a distributed eventbus. The verticle doSomething.js is the verticle B in your case. It doesn't matter where the verticle A is deployed. The only thing that verticle A has to do, is to send/publish a message to the address "finished". This will undeploy verticle B.
Upvotes: 2