UnsupportedOperationException, when doing HazelcastInstance.getConfig() from hazelcast client

923 views
Skip to first unread message

Venkat Ratnam

unread,
Mar 10, 2012, 12:40:39 PM3/10/12
to Hazelcast
I Am using a Hazelcast java client(on node1), and creating Hazelcast
maps on the different node(different laptop--node2).

My setup: on node2 - Hazelcast is running. on node1 - Stand -alone
java program which acts like a Hazelcast java client.

ClientConfig config = new ClientConfig();
config.getGroupConfig().setName("dev").setPassword("dev-pass");
config.addAddress("<node2-ip>:5701");
HazelcastInstance inst = HazelcastClient.newHazelcastClient(config);

//Creating a mapconfig
MapConfig mcfg = new MapConfig();
mcfg.setName("democache");

//creating a mapstore config
MapStoreConfig mapStoreCfg = new MapStoreConfig();
mapStoreCfg.setClassName("com.main.MyMapStore").setEnabled(true);
MyMapStore is my implementation of Hazelcast MapStore. This class
resides on

mcfg.setMapStoreConfig(mapStoreCfg);
**inst.getConfig()**.addMapConfig(mcfg);
I am getting "UnsupportedOperationException" when i run this code..
When i do inst.getConfig(), getting this exception.. Can anyone please
let me know what is work around for this!

Stacktrace is: Exception in thread "main"
java.lang.UnsupportedOperationException at
com.hazelcast.client.HazelcastClient.getConfig(HazelcastClient.java:
144) at ClientClass.main(ClientClass.java:34)

Mehmet Dogan

unread,
Mar 11, 2012, 3:30:31 AM3/11/12
to haze...@googlegroups.com

Hazelcast clients can not access cluster nodes' configuration. This operation is unsupported.

Also you should not update/change configuration after cluster is up.

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.

Venkat Teki

unread,
Mar 11, 2012, 3:54:06 AM3/11/12
to haze...@googlegroups.com
My Setup is like this:
Stand alone client, which accesses the cache from a different cache server, and that server is backed up by one more server.

And, there will be quite a few web services on my client, which may request to store their data in different caches.. So, i need to create the cache at runtime with properties provided by each webservice. If I will not be able to change the configuration from remote client, how do i achieve this.
To unsubscribe from this group, send email to hazelcast+unsubscribe@googlegroups.com.

Mehmet Dogan

unread,
Mar 11, 2012, 4:06:35 AM3/11/12
to haze...@googlegroups.com

You should define configuration before nodes start. As I said before, you shouldn't update config after nodes started up. Also your Mapstore classes should be in classpath of your nodes.

You can use wildcard naming too.
http://hazelcast.com/docs/2.0/manual/single_html/#WildcardConfiguration

To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/HT94LgqGF4QJ.

To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.

umesh....@mettl.com

unread,
Oct 22, 2013, 1:57:47 AM10/22/13
to haze...@googlegroups.com
Is there any way I can change configuration of particular map at run time from client. Because my all map are created at run time and i want to give different configuration to different map or I am a heading in wrong direction ?
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.

Peter Veentjer

unread,
Oct 22, 2013, 2:46:56 AM10/22/13
to haze...@googlegroups.com
What you can do is make use of the wildcard option, e.g.

<map name="quickMap*">..</map>
<map name="slowMap*">..</map>

And you can load the map like this:

HazelcastInstance hz = ...
IMap quickMap1 = hz.getMap("quickMap1"):
IMap quickMap2 = hz.getMap("quickMap2"):
IMap slowMapPeter = hz.getMap("slowMapPeter");

This wildcard options is very practical if you know up front which map-types there are. If you don't know it up front, then there is a problem because dynamically creating map-types currently isn't possible. 



To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.

To post to this group, send email to haze...@googlegroups.com.

umesh....@mettl.com

unread,
Oct 22, 2013, 3:57:03 AM10/22/13
to haze...@googlegroups.com
Thanks for quick reply! But for each Map I want different expiry time or set Idle time property. 
like 
1. for quickMap1.expiry time should be 30 min  (created by client 1)
2. for quickMap2.expiry time should be 20 min  (created by client 2)
 or want to define max size differently for this map. 
How can in acheive this? or it is not possible

Peter Veentjer

unread,
Oct 22, 2013, 4:12:42 AM10/22/13
to haze...@googlegroups.com
If you don't know up front how many map types there are, you have a problem since this is functionality not provided by Hazelcast.

I have been working on a branch that allows for dynamic configuration of maps (and other datastructures) because I also think it would be very useful functionality to have, but currently it isn't available.

I would really have a close look if you can determine up front how many different types of maps you need. 

umesh....@mettl.com

unread,
Oct 23, 2013, 3:19:38 AM10/23/13
to haze...@googlegroups.com
Hi peter
I am pretty new in hazel cast, and replacing  from one of existing cache  in our project to hazel cast, so trying to relate things.
Just a small dobut if client ask for any new map which is still not in cluster , will a new Imap will be created? 
and if client A put something in this new map, will it be available to cluster ?
on version 3.0, if it matters in responding.
thanks

umesh....@mettl.com

unread,
Oct 23, 2013, 3:21:05 AM10/23/13
to haze...@googlegroups.com
I was going through Documnetation , HzlcastInstance.getMap() , does not clear about this thing.

Peter Veentjer

unread,
Oct 23, 2013, 3:43:07 AM10/23/13
to haze...@googlegroups.com

Answers inline.

On Wed, Oct 23, 2013 at 9:19 AM, <umesh....@mettl.com> wrote:
Hi peter
I am pretty new in hazel cast, and replacing  from one of existing cache  in our project to hazel cast, so trying to relate things.
Just a small dobut if client ask for any new map which is still not in cluster , will a new Imap will be created? 

Yes.

and if client A put something in this new map, will it be available to cluster ?

Yes.
 
If you have any other questions, feel free to ask :)

umesh....@mettl.com

unread,
Oct 23, 2013, 4:10:32 AM10/23/13
to haze...@googlegroups.com
Do i need to take  lock before putting some value in key like
 serverInstance.getMap(mapName).lock(key);
is it necessary? , i think it should be handle by hazcst Server to which client is connected. 
If it is so , then in what circumstance i need to do this ?

Peter Veentjer

unread,
Oct 23, 2013, 4:20:19 AM10/23/13
to haze...@googlegroups.com
On Wed, Oct 23, 2013 at 10:10 AM, <umesh....@mettl.com> wrote:
Do i need to take  lock before putting some value in key like
 serverInstance.getMap(mapName).lock(key);
is it necessary? , i think it should be handle by hazcst Server to which client is connected. 

It depends on the situation.

The IMap is thread safe, so it can be used perfectly without acquiring locks.

But.. if you would do the following:

BankAccount account = accountsMap.get(1);
account.add(10)
accountsMap.put(1,account)

Then you could run into a lost update if another thread is updating the same bank account. In such a case you need to acquire a lock or use a non blocking approach using the replace(key,old,new) method.
 
If it is so , then in what circumstance i need to do this ?

See previous comment.

umesh....@mettl.com

unread,
Oct 23, 2013, 8:20:28 AM10/23/13
to haze...@googlegroups.com
Ahh So, its meant for logical lock rather than thread lock..
thanks Peter , your patience are  highly appreciated. 

Peter Veentjer

unread,
Oct 23, 2013, 8:29:10 AM10/23/13
to haze...@googlegroups.com
No problem.

PS: There is also another solution: the EntryProcessor.

In the previous example the data is pulled to the function; the BankAccount is send to the machine that wants to do the logic.

Often it is better to send the function to the machine that owns the partition of the BankAccount. This is a lot better scalable, since functions often are a lot smaller than the data it operates on. Hazelcast has something called the EntryProcessor that follows this principle. Another cool thing about the EntryProcessor is that due to its architecture, no locking is needed. So the bank account example could be implemented:

 static class AddEntryProcessor extends AbstractEntryProcessor<String, Employee> {
        @Override
        public Object process(Map.Entry< String, BankAccount> entry) {
            entry.getValue().add(10);
            return null;
        }
    }

And send execute it using:
accountsMap.executeOnKey("1", new AddEntryProcessor());


umesh....@mettl.com

unread,
Oct 24, 2013, 4:41:51 AM10/24/13
to haze...@googlegroups.com
Hi peter,
Thanks for the knowledge. I have one more doubt.. I have one HZserver and 3 HZclient pointing to same HZServer. Every thing is up and running fine, Now after a while I have added new HZserver on different machine, now both server are up and running. but all clients are still pointing to old HZserver. So, how can i distribute load equally? or it doesn't matter at all ?
Thanks 
umesh

Peter Veentjer

unread,
Oct 24, 2013, 4:51:26 AM10/24/13
to haze...@googlegroups.com
The client will automatically get updated with the new members. 

Are you sure that the servers can find each other? 

You should see something like:

Members [2] {
    Member [192.168.1.100]:5701
    Member [192.168.1.100]:5702 this
}

Ahmet Mircik

unread,
Oct 24, 2013, 7:21:46 AM10/24/13
to haze...@googlegroups.com
and if you use smart client, key based operations will be routed to data owner.

Peter Veentjer

unread,
Oct 24, 2013, 7:25:10 AM10/24/13
to haze...@googlegroups.com
Ahmet is correct.

This option 'smartRouting' is enabled by default. So you don't need to set it.

umesh....@mettl.com

unread,
Oct 28, 2013, 2:19:42 AM10/28/13
to haze...@googlegroups.com
Hi Peter ,
Can we define the maxsize for particular Imap ? I want to restrict the cache entries to 100 for a particular map. 

Peter Veentjer

unread,
Oct 28, 2013, 2:44:06 AM10/28/13
to haze...@googlegroups.com
Hi Umesh,

you can do:

   <map name="persons">
        <eviction-policy>LRU</eviction-policy>
        <max-size>20</max-size>
    </map>

In this case the total number of persons for this persons-map on a particular node, never exceeds 20. You can  set a maxSizePolicy on the maxSizeConfig:

 public enum MaxSizePolicy {
        PER_NODE, PER_PARTITION, USED_HEAP_PERCENTAGE, USED_HEAP_SIZE
    }

There is no option to have a limited to a total cluster size, since that would require a lot of communication and often you want to be able to scale you cache by adding more nodes.

umesh....@mettl.com

unread,
Oct 28, 2013, 3:53:40 AM10/28/13
to haze...@googlegroups.com
Thanks peter,
Now I am trying to connect my HZserver to mancenter, so I enable that in property file by writing
 <management-center enabled="true">http://localhost:13080/mancenter</management-center>  
and my tomcat application is also up .. 
when i open mancneter in tomcat it asked for user name and password for cluster, I haven't set any password.
If I bypass that login screen, it doesn't show any member.
do it is necessary to give password to cluster for using mancenter ?

Peter Veentjer

unread,
Oct 28, 2013, 4:04:32 AM10/28/13
to haze...@googlegroups.com
Hi Umesh,

admin/admin are the default credentials.

Once you have logged in, you can change the credentials if you want.

It isn't needed to set the password (although in production you probably want for security purposes)

The question is why you can't see your cluster in the mancenter. 

Do you have exactly the same version for the mancenter as for your hazelcast jars? Because the versions need to match exactly. 

And you are able to access http://localhost:13080/mancenter from your browser, correct?

umesh....@mettl.com

unread,
Oct 28, 2013, 4:43:31 AM10/28/13
to haze...@googlegroups.com
Thanks peter , I am able to see my members now.
Version was different , now everything is on 3.0.2 
Its working fine now.

Peter Veentjer

unread,
Oct 28, 2013, 4:45:14 AM10/28/13
to haze...@googlegroups.com
Good

We are thinking about a solution to decouple the versioning of the mancenter and hazelcast. 

Peter.

umesh....@mettl.com

unread,
Oct 28, 2013, 6:43:04 AM10/28/13
to haze...@googlegroups.com
That will be nice to see, so that administrator panel can be updated regardless of running hazel cast server version.
I have one scenario now. 
I started HZserver node at machine A, and my HzClient (component which is using that node) is on machine B.
Machine A goes down,  client got exception 
"java.lang.IllegalStateException: Unable to connect to any address in the config!" ,
client try for 2 attempts..
after that it declare that server Instances shut down or unreachable.
after some time , machine A comes up. but client still not able to find it..
So what would be good approach for this. ? Should I write a wrapper thread that got activate after HZ server shutdown 
and continuously test for ping, if server node comes up , then update the HZ instance in client implementation.
or do we have any inbuilt mechanism.

Peter Veentjer

unread,
Oct 28, 2013, 7:53:57 AM10/28/13
to haze...@googlegroups.com
Hi Umesh,

I just verified, thanks Ali, there are 2 properties on the clientconfig:

   private int connectionAttemptLimit = 2;
    private int connectionAttemptPeriod = 3000;

These are also used for reconnecting. In your case you might want to set a higher value.

umesh....@mettl.com

unread,
Oct 28, 2013, 8:15:37 AM10/28/13
to haze...@googlegroups.com
Hi , 
I tested those properties you mentioned , its good to have.. but i was looking for something like if machine comes up then client instantly came to know .. 
i used membership listener also.. but i think as my cluster have only one node and if it goes down , cluster destroyed , and when it comes up a new cluster is formed which dont have any listener , thats why I am not getting notification for that .
Is it so ??
can you suggest any solution for this..

Peter Veentjer

unread,
Oct 28, 2013, 8:20:29 AM10/28/13
to haze...@googlegroups.com
Which listeners are you talking about?

umesh....@mettl.com

unread,
Oct 28, 2013, 8:31:07 AM10/28/13
to haze...@googlegroups.com
I am using following code

 serverInstance.getCluster().addMembershipListener(new MembershipListener(){
            public void memberAdded(MembershipEvent membersipEvent) {
              // Do something 
            }

            public void memberRemoved(MembershipEvent membersipEvent) {
                // - do something else
            
            }
        });


or if i can increase no of attempt property to infinite , it will solve our purpose ... is there is something like this exists.

Ali Gürbüz

unread,
Oct 28, 2013, 8:44:50 AM10/28/13
to haze...@googlegroups.com
you can set Integer.MAX_VALUE. 

clientConfig.setConnectionAttemptLimit(Integer.MAX_VALUE);

This will make it almost infinite (200 years)

umesh....@mettl.com

unread,
Oct 28, 2013, 8:47:49 AM10/28/13
to haze...@googlegroups.com

:) thanks alot... I think it should be enough for my application :D :D 

r.vsat...@gmail.com

unread,
Nov 29, 2013, 1:52:11 AM11/29/13
to haze...@googlegroups.com
Hi All,

I trying to replace the old cache mechanism with HZCache in my application for cluster environment.

I have followed below steps for deployment, please correct me if any thing wrong.

We using two jboss servers, so placed the hazelcast-all-2.5.jar in server/lib folder and loaded the hazel-config.xml from directory in both server.

tcp-ip configuration in hazel-config.xml file.

"<join>
             <multicast enabled="false">
                <multicast-group>224.2.2.31</multicast-group>
                <multicast-port>54327</multicast-port>
            </multicast>
             <tcp-ip enabled="true">                
                <hostname>server1</hostname>
                <hostname>server2</hostname>
                <interface>17.1.8.126:5701</interface>
                <interface>17.1.11.96:5702</interface>    
            </tcp-ip>
        </join>"
and I hve attached the "hazel-config.xml" file to mail also.

Sample Code:
"TestConfig testConfig = new TestConfig("D:jboss/hazel-config.xml");
            HazelcastInstance hz = com.hazelcast.core.Hazelcast.newHazelcastInstance();"
    hz.getMap(cacheRegionName).put(cacheKey, cacheValue);
 hz.getMap(cacheRegionName).get(cacheKey);"

if any Object set in map of one servers, is not reflecting in another server.

When i was tring to monitor cluster using mancenter, only server is displaying in mancenter.

Please correct, if any thing wrong and clarify what is difference between the HZserver and HZclient? is it deployment is different from above?

Thanks,
satish





hazel-config.xml
Reply all
Reply to author
Forward
0 new messages