@Override public void run(){
  logger.finest("LookupDiscovery - Requestor thread started");
  int count;
  try {
    if (delayFlag && (initialMulticastRequestDelayRange > 0) && (multicastRequestMax >= 0)) {
      Thread.sleep((long)(Math.random() * initialMulticastRequestDelayRange));
    }
    for (count=multicastRequestMax; --count >= 0 && !isInterrupted(); ) {
      DatagramPacket[] reqs=encodeMulticastRequest(new MulticastRequest(multicastRequestHost,responsePort,groups,getServiceIDs()));
      sendPacketByNIC(sock,reqs);
      Thread.sleep(count > 0 ? multicastRequestInterval : finalMulticastRequestInterval);
    }
  }
 catch (  InterruptedException e) {
  }
catch (  InterruptedIOException e) {
  }
catch (  Exception e) {
    logger.log(Level.INFO,"exception while marshalling outgoing " + "multicast request",e);
  }
 finally {
synchronized (requestors) {
      requestors.remove(Thread.currentThread());
      if (respondeeThread != null && requestors.isEmpty()) {
        respondeeThread.interrupt();
        respondeeThread=null;
      }
    }
    sock.close();
    logger.finest("LookupDiscovery - Requestor thread completed");
  }
}

@ Override public void run ( ) { logger . finest ( "LookupDiscovery - Requestor thread started" ) ; int count ; try { if ( delayFlag && ( initialMulticastRequestDelayRange > 0 ) && ( multicastRequestMax >= 0 ) ) { Thread . sleep ( ( long ) ( Math . random ( ) * initialMulticastRequestDelayRange ) ) ; } for ( count = multicastRequestMax ; -- count >= 0 && ! isInterrupted ( ) ; ) { DatagramPacket [ ] reqs = encodeMulticastRequest ( new MulticastRequest ( multicastRequestHost , responsePort , groups , getServiceIDs ( ) ) ) ; sendPacketByNIC ( sock , reqs ) ; Thread . sleep ( count > 0 ? multicastRequestInterval : finalMulticastRequestInterval ) ; } } catch ( InterruptedException e ) { } catch ( InterruptedIOException e ) { } catch ( Exception e ) { logger . log ( Level . INFO , "exception while marshalling outgoing " + "multicast request" , e ) ; } finally { synchronized ( requestors ) { requestors . remove ( Thread . currentThread ( ) ) ; if ( respondeeThread != null && requestors . isEmpty ( ) ) { respondeeThread . interrupt ( ) ; respondeeThread = null ; } } sock . close ( ) ; logger . finest ( "LookupDiscovery - Requestor thread completed" ) ; } }
this method sends out n ( for small n ) multicast requests . until the last request is sent out , this method sleeps for 5 seconds after each request is sent . after the last request is sent , this method sleeps for 2 minutes to allow the responselistener time to receive and process any multicast responses sent in reply to the multicast requests . before sending a request , a new multicast request is constructed so that updates can be made to the set of service ids of the lookup services discovered due to previous requests . < p > after all requests have been sent , and the responselistener has been given the appropriate time to receive and process any multicast responses , if there are no more active instances of this thread , this method terminates ( interrupts ) the responselistener . note that although it is more desirable to have the responselistener set a timeout on the server socket ( using setsotimeout ) and then simply exit after a period of time in which both the responselistener has been idle , and there have been no active requestor threads , using setsotimeout in this way can cause random hangs on the solaris ( tm ) operating system .
