Detecting connection closure

36 views
Skip to first unread message

albertolongo100

unread,
Oct 30, 2020, 5:42:14 PM10/30/20
to Hazelcast
Hi,

I'm new to hazelcast, so my question may be trivial, but so far I haven't been able to find the answer in the documentation. Actually, I'm using Vertx with an hazelcast cluster manager, but I think my issue is mostly related to my understanding of hazelcast.
I am in the following situation: it may happen, particularly in development, that a node (out of two, so far) of a cluster crashes (or I click the "Terminate" button in eclipse). The other node detects the disconnection, in fact I see in the console an exception printed out ("java.io.IOException: An existing connection was forcibly closed by the remote host"), and the crashed node is no more in the member list. However, I need to do some cleanup in my code after the disconnection, so I should detect this event. I have tried to add a cluster listener (hazelcastInstance.getCluster().addMembershipListener()), a lifecycle listener (hazelcastInstance.getLifecycleService().addLifecycleListener()), and a membership listener (hazelcastInstance.getCluster().addMembershipListener()), but none of them seems to fire that specific event. Is there a way to detect this kind of disconnection?

Thanks
Al

Josef Cacek

unread,
Nov 2, 2020, 3:19:22 AM11/2/20
to haze...@googlegroups.com
Hi Al,

the MembershipListener should work in your case. Each of your members
should add it. You can play with it using standalone Hazelcast
members. E.g.:

public static void main(String[] args) {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
hz.getCluster().addMembershipListener(new MembershipListener() {

@Override
public void memberRemoved(MembershipEvent membershipEvent) {
System.out.println("Member removed " + membershipEvent);
}

@Override
public void memberAdded(MembershipEvent membershipEvent) {
System.out.println("Member added " + membershipEvent);
}
});
}

Regards,
-- Josef
> --
> You received this message because you are subscribed to the Google Groups "Hazelcast" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/d917dfe7-514b-4c8d-a359-00f604b09260n%40googlegroups.com.

--
This message contains confidential information and is intended only for the
individuals named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system. E-mail transmission cannot be
guaranteed to be secure or error-free as information could be intercepted,
corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.
The sender therefore does not accept liability for any errors or omissions
in the contents of this message, which arise as a result of e-mail
transmission. If verification is required, please request a hard-copy
version. -Hazelcast
Reply all
Reply to author
Forward
0 new messages