Skip to main content

How to leave a group

2 replies [Last post]
jtanago
Offline
Joined: 2008-06-18

Hi!

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!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
enygma2002
Offline
Joined: 2008-12-22

This is what I use:

// Stop being rdv for the gorup.
RendezVousService oldGroupRendezvousService = oldGroup.getRendezVousService();
oldGroupRendezvousService.stopRendezVous();

// Resign from the group.
MembershipService oldGroupMembershipService = oldGroup.getMembershipService();
oldGroupMembershipService.resign();

// Stop listening to rendezvous events.
oldGroupRendezvousService.removeListener(this);

// Stop listen to discovery events.
DiscoveryService oldGroupDiscoveryService = oldGroup.getDiscoveryService();
oldGroupDiscoveryService.addDiscoveryListener(this);

// Close any listening sockets or pipes
...

// Stop group services and unref used memory
oldGroup.stopApp();
oldGroup.unref();
oldGroup = null;

// Optional
System.runFinalization();
System.gc();

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.

Good luck!

jtanago
Offline
Joined: 2008-06-18

Thanks!!