I want to know what is the best way to leave a group. Is peerGroup.stopApp() an option? Or is there a better way? Thanks!
This is what I use:
// Stop being rdv for the gorup.
RendezVousService oldGroupRendezvousService = oldGroup.getRendezVousService();
// Resign from the group.
MembershipService oldGroupMembershipService = oldGroup.getMembershipService();
// Stop listening to rendezvous events.
// Stop listen to discovery events.
DiscoveryService oldGroupDiscoveryService = oldGroup.getDiscoveryService();
// Close any listening sockets or pipes
// Stop group services and unref used memory
oldGroup = null;
Be careful though because you will not be able to use the PeerGroup instanccce anymore. The code above basically unreferences it and stops all threads that it had started.
To rejoin the same group, create a new PeerGroup instance from the PeerGroupAdvertisement and you will be good to go.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.