synchronized boolean doReConnect ( ) throws IOException { // In case we are still connected, test the connection and see if we can reuse it if ( connectionManager . isConnected ( ) ) { try { final Future < Long > result = channelHandler . executeRequest ( ManagementPingRequest . INSTANCE , null ) . getResult ( ) ; result . get ( 15 , TimeUnit . SECONDS ) ; // Hmm, perhaps 15 is already too much return true ; } catch ( Exception e ) { ServerLogger . AS_ROOT_LOGGER . debugf ( e , "failed to ping the host-controller, going to reconnect" ) ; } // Disconnect - the HC might have closed the connection without us noticing and is asking for a reconnect final Connection connection = connectionManager . getConnection ( ) ; StreamUtils . safeClose ( connection ) ; if ( connection != null ) { try { // Wait for the connection to be closed connection . awaitClosed ( ) ; } catch ( InterruptedException e ) { throw new InterruptedIOException ( ) ; } } } boolean ok = false ; final Connection connection = connectionManager . connect ( ) ; try { // Reconnect to the host-controller final ActiveOperation < Boolean , Void > result = channelHandler . executeRequest ( new ServerReconnectRequest ( ) , null ) ; try { boolean inSync = result . getResult ( ) . get ( ) ; ok = true ; reconnectRunner = null ; return inSync ; } catch ( ExecutionException e ) { throw new IOException ( e ) ; } catch ( InterruptedException e ) { throw new InterruptedIOException ( ) ; } } finally { if ( ! ok ) { StreamUtils . safeClose ( connection ) ; } } }
Reconnect to the HC .