Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using a MapLoader for a Hazelcast distributed map within a client

I'm evaluating Hazelcast as a distributed data grid solution for an application I'm working on. Hazelcast is setup on a distributed cluster, and my application uses Spring to define an Hazelcast client in this way:

<hz:client id="hazelcastClient" group-name="dev" group-password="dev-pass">
<hz:member>localhost:5701</hz:member>
</hz:client>

On my Hazelcast node, in the hazelcast.xml file I've setup a map, with all the configuration needed. Let's say this map is called myMap. I can see this map set up properly when using the Hazelcast webapp for monitoring (mancenter).

I have now to configure the map to get injected into my bean, on the application side. If I do something like

<hz:map id="myMap" instance-ref="hazelcastClient" name="myMap" />

And I inject this map into my bean that containst the fetching logic, I've got no problems.

However, I've also written a class that implements MapLoader interface, in order to handle the missing data from the cache. My problem is now that I don't know how to tie this Maploader to the cache I defined. If I try something like

<hz:map id="myMap" instance-ref="hazelcastClient" name="myMap">
    <hz:map-store enabled="true" implementation="myMapLoader"/>
</hz:map>

I'm getting an XML parse error, as it seems that when hz:map is used as a top-level element (and not inside a hz:config, for example), you cannot specify inner elements. This makes me think that you need to define a hz:config element. But it's not very clear from the documentation if you can define a hz:config element for a client. To me it seems that you need to use hz:config if you want your application to be part of the cluster. I'm not sure however if it's logically correct that my app should be part of the cluster - it's basically a client of the data grid.

Do you have any thoughts on how can I configure my app to achieve the behavior I want?

like image 967
manub Avatar asked Dec 10 '22 00:12

manub


1 Answers

You can not configure a map on the client side. You should configure myMap and its MapLoader/MapStore on Hazelcast node. MapStore/MapLoader operations are executed by Hazelcast node that owns the data, not by client.

Hazelcast Node

<hz:config>
    ...
    <hz:map name="myMap" backup-count="1" max-size="0">
        <hz:map-store enabled="true" implementation="myMapLoader" />
    </hz:map>
    ...
</hz:config>

-OR- using hazelcast.xml

<map name="myMap">
    <backup-count>1</backup-count>
    <time-to-live-seconds>0</time-to-live-seconds>
    <max-idle-seconds>0</max-idle-seconds>

    <map-store enabled="true">
        <class-name>foo.bar.MyMapLoader</class-name>
        <write-delay-seconds>0</write-delay-seconds>
    </map-store>
</map>

On client side just instantiate myMap;

<hz:map id="myMap" instance-ref="hazelcastClient" name="myMap" />

When client puts to / gets from that map, the node handles client's request will call MapLoader/MapStore.

like image 195
mdogan Avatar answered Apr 08 '23 04:04

mdogan