private static List < Future < List < DiscoveryIncomingMessage > > > sendDiscoveryRequests ( DiscoveryOutgoingMessage pOutMsg , int pTimeout , LogHandler pLogHandler ) throws SocketException , UnknownHostException { // Note for Ipv6 support: If there are two local addresses, one with IpV6 and one with IpV4 then two discovery request // should be sent, on each interface respectively. Currently, only IpV4 is supported. List < InetAddress > addresses = getMulticastAddresses ( ) ; ExecutorService executor = Executors . newFixedThreadPool ( addresses . size ( ) ) ; final List < Future < List < DiscoveryIncomingMessage > > > futures = new ArrayList < Future < List < DiscoveryIncomingMessage > > > ( addresses . size ( ) ) ; for ( InetAddress address : addresses ) { // Discover UDP packet send to multicast address DatagramPacket out = pOutMsg . createDatagramPacket ( InetAddress . getByName ( JOLOKIA_MULTICAST_GROUP ) , JOLOKIA_MULTICAST_PORT ) ; Callable < List < DiscoveryIncomingMessage > > findAgentsCallable = new FindAgentsCallable ( address , out , pTimeout , pLogHandler ) ; futures . add ( executor . submit ( findAgentsCallable ) ) ; } executor . shutdownNow ( ) ; return futures ; }
Send requests in parallel threads return the futures for getting the result