using a MapLoader for a Hazelcast distributed map within a client

1,171 views
Skip to first unread message

manub

unread,
May 15, 2012, 10:59:42 AM5/15/12
to Hazelcast
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
behaviour I want?

Thanks!

Mehmet Dogan

unread,
May 16, 2012, 1:34:36 AM5/16/12
to haze...@googlegroups.com

You can not configure a map on the client side. You should configure myMap and itsMapLoader/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.


ps: just copied the answer here that I have posted to your stackoverflow question.
http://stackoverflow.com/questions/10603254/using-a-maploader-for-a-hazelcast-distributed-map-within-a-client/

@mmdogan





--
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.


Reply all
Reply to author
Forward
0 new messages