public InetSocketAddress remoteLookup ( final Identifier id ) throws Exception { // the lookup is not thread-safe, because concurrent replies may // be read by the wrong thread. // TODO: better fix uses a map of id's after REEF-198 synchronized ( this ) { LOG . log ( Level . INFO , "Looking up {0} on NameServer {1}" , new Object [ ] { id , serverSocketAddr } ) ; final List < Identifier > ids = Arrays . asList ( id ) ; final Link < NamingMessage > link = transport . open ( serverSocketAddr , codec , new LoggingLinkListener < NamingMessage > ( ) ) ; link . write ( new NamingLookupRequest ( ids ) ) ; final NamingLookupResponse resp ; for ( ; ; ) { try { resp = replyQueue . poll ( timeout , TimeUnit . MILLISECONDS ) ; break ; } catch ( final InterruptedException e ) { LOG . log ( Level . INFO , "Lookup interrupted" , e ) ; throw new NamingException ( e ) ; } } final List < NameAssignment > list = resp == null ? Collections . < NameAssignment > emptyList ( ) : resp . getNameAssignments ( ) ; if ( list . isEmpty ( ) ) { throw new NamingException ( "Cannot find " + id + " from the name server" ) ; } else { return list . get ( 0 ) . getAddress ( ) ; } } }
Retrieves an address for an identifier remotely .