简体   繁体   中英

How to get Hazelcast map configuration

I'm trying to create an API to get the Hazelcast map configuration. But when I tried to use

hazelcastInstance.getConfig().getMapConfig("MAP");

I'm getting an error

java.lang.UnsupportedOperationException: Client config object only supports adding new data structure configurations

any workaround to get the configuration?

as a workaround you can use the semi-internal API of Management Center (note: no backward-compatibility is guaranteed) to get the member config of a specific member, then you can parse it and extract the details you need.

Example:

    HazelcastClientInstanceImpl client = ((HazelcastClientProxy) HazelcastClient.newHazelcastClient()).client;
    client.getMap("myMap").put(1, 2);
    Member aMember = client.getCluster().getMembers().iterator().next();
    ClientInvocation invocation = new ClientInvocation(
            client, // of type HazelcastClientInstanceImpl
            MCGetMemberConfigCodec.encodeRequest(),
            null,
            aMember.getUuid()
    );
    String config = new ClientDelegatingFuture<String>(
            invocation.invoke(),
            client.getSerializationService(),
            clientMessage -> MCGetMemberConfigCodec.decodeResponse(clientMessage).configXml
    ).get();
    MapConfig mapConfig = new XmlConfigBuilder(new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8))).build().getMapConfig("myMap");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM