Reputation: 1182
I have been searching for a means to record some data in a Hazelcast map and then have that data removed when the node goes away. The idea is that this data is something like an address book to certain processes and I only want the addresses of processes running on live nodes so I can avoid pushing data to dead node processes. Is there any way this can easily be done in hazelcast or would i need some sort of custom solution such as a Member listener?
Thanks in advance.
Upvotes: 2
Views: 73
Reputation: 26858
A MembershipListener would be the way to do it. For example:
public class Test
{
public static void main( String[] args )
{
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IMap<Object, Object> bookkeeping = hazelcastInstance.getMap( "bookkeeping" );
hazelcastInstance.getCluster().addMembershipListener( new MembershipListener()
{
@Override
public void memberAdded( MembershipEvent membershipEvent )
{
bookkeeping.put( membershipEvent.getMember().getUuid(), true );
}
@Override
public void memberRemoved( MembershipEvent membershipEvent )
{
bookkeeping.put( membershipEvent.getMember().getUuid(), false );
}
@Override
public void memberAttributeChanged( MemberAttributeEvent memberAttributeEvent )
{
}
} );
}
}
Upvotes: 1