ClusterMasterExecutorImpl implements ClusterMasterExecutor { protected String getMasterClusterNodeId(boolean notify) { boolean master = false; String masterClusterNodeId = null; while (true) { ClusterChannel clusterChannel = _clusterExecutorImpl.getClusterChannel(); ClusterReceiver clusterReceiver = clusterChannel.getClusterReceiver(); Address coordinatorAddress = clusterReceiver.getCoordinatorAddress(); master = coordinatorAddress.equals( clusterChannel.getLocalAddress()); if (master) { masterClusterNodeId = _localClusterNodeId; } else { masterClusterNodeId = _clusterExecutorImpl.getClusterNodeId( coordinatorAddress); } if (Validator.isNotNull(masterClusterNodeId)) { break; } if (_log.isInfoEnabled()) { _log.info( StringBundler.concat( "Unable to get cluster node information for ", "coordinator address ", coordinatorAddress, ". Trying again.")); } } if (master == _master) { return masterClusterNodeId; } _master = master; if (notify) { notifyMasterTokenTransitionListeners(master); } return masterClusterNodeId; }  @Override void addClusterMasterTokenTransitionListener(
		ClusterMasterTokenTransitionListener
			clusterMasterTokenTransitionListener); @Override NoticeableFuture<T> executeOnMaster(
		MethodHandler methodHandler); @Override boolean isEnabled(); @Override boolean isMaster(); @Override void removeClusterMasterTokenTransitionListener(
		ClusterMasterTokenTransitionListener
			clusterMasterTokenTransitionListener);  }
@Test public void testGetMasterClusterNodeId() throws Exception { ClusterMasterExecutorImpl clusterMasterExecutorImpl = new ClusterMasterExecutorImpl(); MockClusterExecutor mockClusterExecutor = new MockClusterExecutor(true); clusterMasterExecutorImpl.setClusterExecutorImpl(mockClusterExecutor); clusterMasterExecutorImpl.activate(); Assert.assertEquals( mockClusterExecutor.getLocalClusterNodeId(), clusterMasterExecutorImpl.getMasterClusterNodeId(true)); Assert.assertTrue(clusterMasterExecutorImpl.isMaster()); mockClusterExecutor.addClusterNode( _TEST_ADDRESS, new ClusterNode(_TEST_CLUSTER_NODE_ID, InetAddress.getLocalHost())); MockClusterMasterTokenTransitionListener mockClusterMasterTokenTransitionListener = new MockClusterMasterTokenTransitionListener(); clusterMasterExecutorImpl.addClusterMasterTokenTransitionListener( mockClusterMasterTokenTransitionListener); Address oldCoordinatorAddress = mockClusterExecutor.getCoordinatorAddress(); mockClusterExecutor.setCoordinatorAddress(_TEST_ADDRESS); Assert.assertEquals( _TEST_CLUSTER_NODE_ID, clusterMasterExecutorImpl.getMasterClusterNodeId(true)); Assert.assertFalse(clusterMasterExecutorImpl.isMaster()); Assert.assertTrue( mockClusterMasterTokenTransitionListener. isMasterTokenReleasedNotified()); mockClusterExecutor.setCoordinatorAddress(oldCoordinatorAddress); Assert.assertEquals( mockClusterExecutor.getLocalClusterNodeId(), clusterMasterExecutorImpl.getMasterClusterNodeId(true)); Assert.assertTrue(clusterMasterExecutorImpl.isMaster()); Assert.assertTrue( mockClusterMasterTokenTransitionListener. isMasterTokenAcquiredNotified()); }