@ Override public long addClientAndConnect ( String host , int port ) throws TTransportException , IOException { long clientId = getNewClientId ( ) ; LOG . info ( "Adding client with id=" + clientId + " host=" + host + " port=" + port + " and connecting ..." ) ; ClientHandler . Client clientHandler ; try { clientHandler = getClientConnection ( host , port ) ; LOG . info ( "Succesfully connected to client " + clientId ) ; } catch ( IOException e1 ) { LOG . error ( "Failed to connect to client " + clientId , e1 ) ; throw e1 ; } catch ( TTransportException e2 ) { LOG . error ( "Failed to connect to client " + clientId , e2 ) ; throw e2 ; } // Save the client to the internal structures ClientData clientData = new ClientData ( clientId , clientHandler , host , port ) ; addClient ( clientData ) ; LOG . info ( "Successfully added client " + clientId + " and connected." ) ; return clientId ; }
Adds the client to the internal data structures and connects to it . If the method throws an exception then it is guaranteed it will also be removed from the internal structures before throwing the exception .