Using <hz:client> config element

636 views
Skip to first unread message

anucekay

unread,
Apr 24, 2012, 7:46:09 PM4/24/12
to Hazelcast
Here is my use case:

I have a hazel cluster that is spawn and running.

I want to have the client side configuration for this cluster.

<hz:client id="myHazelcast" group-name="${hazelcast.group}" group-
password="mypassword" >
<hz:member>${hazelcast.vip}</hz:member>
</hz:client>

within the java code, i want to get this client instance and create
maps/add entries etc.


hcmap =
Hazelcast.getHazelcastInstanceByName("myHazelcast").getMap(name);

Does not seem to work. I get NPE
Hazelcast.getHazelcastInstanceByName("myHazelcast");

My question is what is the best way to get at the hazelcast instance
that was created by the hz:client spring
configration.

Thanks
Anu

Mehmet Dogan

unread,
Apr 25, 2012, 2:33:38 AM4/25/12
to haze...@googlegroups.com
'Hazelcast.getHazelcastInstanceByName' returns actual Hazelcast instances not clients (although they implement the same interface; HazelcastInstance). The best way to get a Hazelcast instance (or client) that was created with Spring is to make Spring inject that bean into place we need. (That is Spring built for, isn't it?)

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


anucekay

unread,
Apr 25, 2012, 5:25:55 PM4/25/12
to Hazelcast
My old code which used the hazelcast intance would look it up from the
Hazelcast class and i expected the same code to work when
i moved to using the client. Was able to work around it.

When i was using the actual hazelcast instances, i was able to
redirect the logs to our specific log files by specifying
hazelcast.logging.type as shown below and then specifying
the appropriate logger for com.hazelcast in logback.xml

I wanted to redirect the logs from the client, i tried the
same but does not seem to work. Any pointers?

<hz:hazelcast id="MyInstance">
<hz:config>
<hz:instance-name>MyInstance</hz:instance-name>
<hz:properties>
<hz:property name="hazelcast.logging.type">slf4j</
hz:property>
</hz:properties>
<hz:network port="5702" port-auto-increment="true">
......
</hz:network>

Mehmet Dogan

unread,
Apr 26, 2012, 1:20:35 AM4/26/12
to haze...@googlegroups.com
You should set 'hazelcast.logging.type' as system property. (This works for both Hazelcast server and client.)

-Dhazelcast.logging.type=slf4j


@mmdogan
Reply all
Reply to author
Forward
0 new messages