question: @ 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 ; } }
target:  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.