how to use clustered map

1,006 views
Skip to first unread message

Mumuney Abdlquadri

unread,
Feb 23, 2015, 9:49:57 AM2/23/15
to ve...@googlegroups.com
Hi all,

Please I am trying to retrieve a like below but none of the System.out.println() is being called.

Is there a particular section I need to put code.


SharedData sharedData = vertx.sharedData();
sharedData.getClusterWideMap("ng.pending", (AsyncResult<AsyncMap<String, String>> e) -> {

           if (e.succeeded()) {
                pendingAuthMaps = e.result();
                
                System.out.println("cluseter wide map gotten");
            } else {
                System.out.println("cluseter wide map NOT gotten");
              
            }
        });

Regards.

mathias

unread,
Feb 24, 2015, 3:39:44 PM2/24/15
to ve...@googlegroups.com
https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-website/ws/target/site/docs/vertx-core/java/index.html
I read the docs above but I couldn't get it working either :-(

My setup for a cluster currently consists of three steps:
1. Add dependency to vertx-hazlecast (version 3.0.0-milestone2) in pom.xml
2. Set the system property right at the beginning of my main method:
    System.setProperty("vertx.cluster.managerClass", HazelcastClusterManager.class.getName())
3. Start vertx in cluster mode:
        VertxOptions options = new VertxOptions();
        options
.setHAEnabled(true);
       
Vertx.clusteredVertx(options, vertxRes -> {
           
if (vertxRes.succeeded()) {
               
Vertx vertx = vertxRes.result();
                startup
(vertx);
           
} else {
                logger
.error("Failed: " + vertxRes.cause());
           
}
       
});

But these steps seem to be missing something, because I get the following exception when accessing the clustered map as described above by Mumuney:
java.lang.IllegalStateException: Can't get cluster wide map if not clustered
    at io.vertx.core.shareddata.impl.SharedDataImpl.getClusterWideMap(SharedDataImpl.java:60)

How to solve this exception?

Mumuney Abdlquadri

unread,
Feb 25, 2015, 2:13:28 AM2/25/15
to ve...@googlegroups.com
Apparently you have to wait for the Clustered Vertx instance to be up. before trying to get the shared data..


VertxOptions vertxOptions = new VertxOptions().setClustered(true);

        Vertx.clusteredVertx(vertxOptions, (AsyncResult<Vertx> result) -> {
            if (result.succeeded()) {
                clusteredVertx = result.result();

                setUpEventBusMessageHandlers(clusteredVertx.eventBus());
                System.out.println("Event Bus clustered : " + clusteredVertx.eventBus());


                                                                                             /* delibrate indentation*/ getSharedData(); // this is what solved my issue
            } else {
                System.out.println("Event Bus Clustering Failed: " + result.cause());
            }
        });


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mumuney Abdlquadri

unread,
Feb 25, 2015, 2:14:55 AM2/25/15
to ve...@googlegroups.com
also make sure you are using the exact same clusteredVertx instance.

Tim Fox

unread,
Feb 25, 2015, 2:37:07 AM2/25/15
to ve...@googlegroups.com
Just as a general note - when in doubt about how to use this things it's often useful to look at the test suite where we have working examples:

https://github.com/eclipse/vert.x/blob/master/src/test/java/io/vertx/test/core/VertxTestBase.java#L113

You need to set clustered to true.

Mumuney Abdlquadri

unread,
Feb 25, 2015, 2:59:51 AM2/25/15
to ve...@googlegroups.com
Thanks Tim,

In addition I have learnt to always start a new project and try to recreate the issue, I almost always find a solution.

But Tim like I said in another thread if a user is calling Vertx.clusteredVertx(), they expect to get a clustered vertx instance. so setting clustered true sounds redundant. I understand that is the API and probably there was a reason for it.

Regards.

Marco Ellwanger

unread,
Jun 15, 2015, 7:07:50 PM6/15/15
to ve...@googlegroups.com
Hi Tim,

Any reason there are no iterator functions provided within the vertx AsyncMap interface although the Hazelcast IMap interface does provide them? We are keeping track of all verticle deployments within a cluster with some additional info (vertx.deploymentIDs() only returns the local vertx instance deployments IIRC) and while deploymentIDs make good map keys, there's currently no clean way to iterate over a (detached) snasphot of an asyncMap (aside from reflection plus casting to the underlying hazelcast IMap).
cheers
Reply all
Reply to author
Forward
0 new messages