@Override public Void call() throws Exception {
  MulticastSocket datagramSocket=null;
  ExecutorService service=null;
  try {
    datagramSocket=new MulticastSocket(port);
    datagramSocket.joinGroup(group);
    service=Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory("GangliaListener"));
    final byte[] buffer=new byte[BUFFER_SIZE];
    final DatagramPacket packet=new DatagramPacket(buffer,0,buffer.length);
    listening=true;
    while (true) {
      try {
        datagramSocket.receive(packet);
        if (Thread.interrupted()) {
          break;
        }
        final IGangliaMessage msg=decodeRecord(packet.getData(),packet.getOffset(),packet.getLength());
        if (msg != null) {
          service.submit(new DispatchTask(handler,msg));
        }
      }
 catch (      Throwable t) {
        log.warn(t,t);
      }
    }
    return (Void)null;
  }
  finally {
    if (service != null) {
      service.shutdown();
    }
    if (datagramSocket != null) {
      datagramSocket.close();
    }
    listening=false;
  }
}

@ Override public Void call ( ) throws Exception { MulticastSocket datagramSocket = null ; ExecutorService service = null ; try { datagramSocket = new MulticastSocket ( port ) ; datagramSocket . joinGroup ( group ) ; service = Executors . newSingleThreadScheduledExecutor ( new DaemonThreadFactory ( "GangliaListener" ) ) ; final byte [ ] buffer = new byte [ BUFFER_SIZE ] ; final DatagramPacket packet = new DatagramPacket ( buffer , 0 , buffer . length ) ; listening = true ; while ( true ) { try { datagramSocket . receive ( packet ) ; if ( Thread . interrupted ( ) ) { break ; } final IGangliaMessage msg = decodeRecord ( packet . getData ( ) , packet . getOffset ( ) , packet . getLength ( ) ) ; if ( msg != null ) { service . submit ( new DispatchTask ( handler , msg ) ) ; } } catch ( Throwable t ) { log . warn ( t , t ) ; } } return ( Void ) null ; } finally { if ( service != null ) { service . shutdown ( ) ; } if ( datagramSocket != null ) { datagramSocket . close ( ) ; } listening = false ; } }
listens for ganglia messages . each message is decoded as as it is received . bad packets are dropped . valid messages are dispatched using a second thread to avoid latency in the thread which is listening to the ganglia protocol . < p > note : this method blocks and does not notice an interrupt . this is because jdk 6 does not support multicast nio . todo java 6 does not support non - blocking multicast receive . write a jdk 7 specific version of class class which uses multicast with non - blocking io and hence can be interrupted .
