/** * Sends a leave message to the multicast group and leaves it. The <CODE>DiscoveryResponder</CODE> * leaves its multicast group. This method has no effect if the <CODE>DiscoveryResponder</CODE> is * <CODE>OFFLINE</CODE> or <CODE>STOPPING</CODE> or <CODE>STARTING</CODE>. */ public void stop() { if (state == ONLINE) { changeState(STOPPING); // ------------------------ // Stop corresponding thread // ------------------------ responder.stopRequested = true; synchronized (responder.interrupted) { if (!responder.interrupted.booleanValue()) { responderThread.interrupt(); } } // Fix for cases when the interrupt does not work (Windows NT) try { MulticastSocket ms = new MulticastSocket(multicastPort); // NPCTE fix for bugId 4499338, esc 0, 04 Sept 2001 if (usrInet != null) { ms.setInterface(usrInet); if (logger.finerOn()) { logger.finer("stop ", "use the interface " + usrInet); } } // end of NPCTE fix for bugId 4499338 InetAddress group = InetAddress.getByName(multicastGroup); ms.joinGroup(group); ms.send(new DatagramPacket(new byte[1], 1, group, multicastPort)); ms.leaveGroup(group); } catch (Exception e) { if (logger.finerOn()) { logger.finer( "stop ", "Unexpected exception occurred trying to send empty message " + e.getMessage()); } } // ------------------------ // free 'remained' allocated resource // ------------------------ responder = null; System.runFinalization(); // ---------------- // Update state // ---------------- // changeState(OFFLINE) ; } else { if (logger.finerOn()) { logger.finer("stop ", "Responder is not ONLINE"); } } }
// To be called exactly twice by the child process public static void rendezvousChild() { try { for (int i = 0; i < 100; i++) { System.gc(); System.runFinalization(); Thread.sleep(50); } System.out.write((byte) '\n'); System.out.flush(); System.in.read(); } catch (Throwable t) { throw new Error(t); } }