private void tryConnecting ( ) { LOG . debug ( "Trying to connect" ) ; // Get a server with which to try to connect. final Optional < T > optionalServerIdToTry = getServerIdToTry ( ) ; // It is possible that we are unable to find a server. In this case, // fall back to the last resort server. final OptionalVisitor < Void , T > serverToTryVisitor = new OptionalVisitor < Void , T > ( ) { public Void visitNone ( final None < T > none ) { LOG . debug ( "No connections to try..." ) ; // We could not find a server. Handle this case appropriately. // We only need this if we start running a naked server // somewhere to support our network. Otherwise, any running // servers should be found by the candidate provider. // handleNoServerIdToTry (); return null ; } public Void visitSome ( final Some < T > some ) { // We found a server. Establish a connection with it. LOG . debug ( "Establishing connection..." ) ; establish ( some . object ( ) ) ; return null ; } } ; optionalServerIdToTry . accept ( serverToTryVisitor ) ; }
Tries connecting to a server . This method is called when we need to try to establish a connection to a server .