public void handleMasterResponse ( Address masterAddress , Address callerAddress ) { clusterServiceLock . lock ( ) ; try { if ( logger . isFineEnabled ( ) ) { logger . fine ( format ( "Handling master response %s from %s" , masterAddress , callerAddress ) ) ; } if ( clusterService . isJoined ( ) ) { if ( logger . isFineEnabled ( ) ) { logger . fine ( format ( "Ignoring master response %s from %s, this node is already joined" , masterAddress , callerAddress ) ) ; } return ; } if ( node . getThisAddress ( ) . equals ( masterAddress ) ) { logger . warning ( "Received my address as master address from " + callerAddress ) ; return ; } Address currentMaster = clusterService . getMasterAddress ( ) ; if ( currentMaster == null || currentMaster . equals ( masterAddress ) ) { setMasterAndJoin ( masterAddress ) ; return ; } if ( currentMaster . equals ( callerAddress ) ) { logger . warning ( format ( "Setting master to %s since %s says it is not master anymore" , masterAddress , currentMaster ) ) ; setMasterAndJoin ( masterAddress ) ; return ; } Connection conn = node . getEndpointManager ( MEMBER ) . getConnection ( currentMaster ) ; if ( conn != null && conn . isAlive ( ) ) { logger . info ( format ( "Ignoring master response %s from %s since this node has an active master %s" , masterAddress , callerAddress , currentMaster ) ) ; sendJoinRequest ( currentMaster , true ) ; } else { logger . warning ( format ( "Ambiguous master response! Received master response %s from %s. " + "This node has a master %s, but does not have an active connection to it. " + "Master field will be unset now." , masterAddress , callerAddress , currentMaster ) ) ; clusterService . setMasterAddress ( null ) ; } } finally { clusterServiceLock . unlock ( ) ; } }
Set master address if required .