Unable to start up multiple vertx instances of EventBusBridge
Hi,
We are currently experiencing some issues with a WebServer Vertical we have implemented.
Our WebServer basically sets up an EventBusBridge. However, our EventBusBridge implementation is a subclass of org.vertx.java.core.sockjs.EventBusBridge. The main difference is that we have provided some JMX functionality to provide statistics on how many users are connected, how many addresses they have registered handlers on etc.
When running a single vertx instance there is no problem, everything works as it should.
However, when running multiple vertx instances, we get a javax.management.InstanceAlreadyExistsException when subsequent instances try to register their MBeans.
Following this, we tried the following technique:
- The first instance that starts creates the MBean, registers it with the MBean server, and stores a reference to it in a map in vertx.sharedData.
- The second instance checks the map in vertx.sharedData to see if it already exists. If so, it tries to obtain a reference to this, and use it within its vertical (so we can reuse the same MBean instance for statistics).
However, when executing the second stage, we get a ClassCastException, despite the fact that the class we are casting to is identical:
e.g. java.lang.ClassCastException: com.mycom.EventBusBridgeStatistics cannot be cast to com.mycom.EventBusBridgeStatistics.
I suspect that this is due to the EventBusBridgeStatistics class being on different classloaders. Does anyone know of any workarounds to this problem?
Thanks
I amended the eventbusbridge example to start two instances of the HttpServer and SockJSServer and they start fine without any exceptions.
I would need to see a code example which demonstrates the problem to investigate any further.
Using Vert.x 2.0
I suspect this doesn't work in Vertx 1.3.1 due to the difference in classloaders.
I'll wait until Vertx 2.0 is released and try again.
Thanks.