Hazelcast: How to change MapConfig when using HazelcastClient

Created on 4 Jul 2017  路  7Comments  路  Source: hazelcast/hazelcast

Hi,
We are using Hazelcast v3.9.
As part of our project, we have a need to change/set the the TTL of a specific IMap during run time.
We have a cluster size of 5 machines and 4 clients. The jdk version is 1.8(131).
So now when i access the getConfig() from the client i get the following:

java.lang.UnsupportedOperationException: Client cannot access cluster config!
at com.hazelcast.client.impl.HazelcastClientInstanceImpl.getConfig(HazelcastClientInstanceImpl.java:424) ~[hazelcast-client-3.8.jar:3.8]
at com.hazelcast.client.impl.HazelcastClientProxy.getConfig(HazelcastClientProxy.java:78) ~[hazelcast-client-3.8.jar:3.8]

And the ClientConfig which i obtained using :

if (hazelcastInstance instanceof HazelcastClientInstanceImpl){
        HazelcastClientInstanceImpl hazelcastClientInstance = (HazelcastClientInstanceImpl) hazelcastInstance;
        hazelcastClientInstance.getClientConfig()
  }

Does not have the getMapConfig(mapName) method while it has other config methods like getNearCacheConfig().
So now, how do i go about setting the TTL and other settings in the MapConfig as a client?

Config IMap Community Core Enhancement

Most helpful comment

@jerrinot, what do you mean by "once the cluster is up and running"?
I'm joining as a client so of course, the cluster is up and running.
Do you mean to say that you do not support changing the MapConfig as a client?
If so can you put that somewhere in your documentation so that others don't waste their time on this.

All 7 comments

hi @rajavikram,

you can't change a map configuration once a cluster is up and running. You can either per-entry TTL tho.

In Hazelcast 3.9 it's possible to create new map configuration in a running cluster, but it's still not possible to change an existing map configuration.

@rajavikram if it fits your case, an alternative approach can be using management centre. Some properties of an existing MapConfig(including TTL) can be updated from there.

@jerrinot, what do you mean by "once the cluster is up and running"?
I'm joining as a client so of course, the cluster is up and running.
Do you mean to say that you do not support changing the MapConfig as a client?
If so can you put that somewhere in your documentation so that others don't waste their time on this.

@ahmetmircik, thanks for the tip.
We might just have to go with this approach - have a node in the cluster for this purpose.
using put(K key, V value, long ttl, TimeUnit timeunit); will be a pain as we will have to set the value for each key/value.

+1 This should be documented

@davidkarlsen https://docs.hazelcast.org/docs/latest/manual/html-single/#dynamically-adding-data-structure-configuration-on-a-cluster

Was this page helpful?
0 / 5 - 0 ratings