Tuesday, September 25, 2007

Coherence Contd. Listening the cluster

I am assuming my other blogs related to Coherence has been read. The nodes in a cluster are also called Members. Like Cache events, cluster also generates events when a Member joins, leaving or left. Say, if we need to clear some of the resources if a Member leaves or dynamically increase the pool size of a resource when additional members join in (I don't know, I am just making the requirements up!). Here is a sample code showing where and how to do it:


NamedCache nCache = CacheFactory.getCache ("Cache");
nCache.getCacheService ().addMemberListener (new MemberListener () {
final Member local = nCache.getCacheService ().getCluster ().getLocalMember ();
public void memberJoined (MemberEvent evt) {
// -- The Member which the event is associated to
Member eM = evt.getMember ();
// -- Do the fancy stuff
}

public void memberLeaving (MemberEvent evt) {
}

public void memberLeft (MemberEvent evt) {
}
});


And thats it again!

2 comments:

Linda said...

That's what I was thinking. ;-)

ashish said...

Actually, for sun.com this is very good fit. You can take the read-mostly infrastructure to a high transactional system and that too without Appserver migration. Get the folks look at it.