DefaultMetaCache implements MetaCache { @Override public Set<HostPort> getAllKeepers(){ XpipeMeta xpipeMeta = getXpipeMeta(); if (allKeepers == null) { synchronized (this) { if (allKeepers == null) { Set<HostPort> localKeepers = Sets.newHashSetWithExpectedSize(allKeeperSize); xpipeMeta.getDcs().forEach((dcName, dcMeta) -> { dcMeta.getClusters().forEach((clusterName, clusterMeta) -> { clusterMeta.getShards().forEach((shardName, shardMeta) -> { shardMeta.getKeepers().forEach(keeperMeta -> { localKeepers.add(new HostPort(keeperMeta.getIp(), keeperMeta.getPort())); }); }); }); }); allKeepers = localKeepers; } } } return allKeepers; } DefaultMetaCache(); @PostConstruct void postConstruct(); @PreDestroy void shutdown(); @Override XpipeMeta getXpipeMeta(); @Override boolean inBackupDc(HostPort hostPort); @Override HostPort findMasterInSameShard(HostPort hostPort); @Override Pair<String, String> findClusterShard(HostPort hostPort); @Override String getActiveDc(HostPort hostPort); @Override long getLastUpdateTime(); @Override RouteMeta getRouteIfPossible(HostPort hostPort); @Override boolean isCrossRegion(String activeDc, String backupDc); @Override List<HostPort> getAllActiveRedisOfDc(String activeDc, String dcId); @Override Set<HostPort> getAllKeepers(); @Override String getSentinelMonitorName(String clusterId, String shardId); @Override Set<HostPort> getActiveDcSentinels(String clusterId, String shardId); @Override HostPort findMaster(String clusterId, String shardId); @Override String getDc(HostPort hostPort); @Override Pair<String, String> findClusterShardBySentinelMonitor(String monitor); @Override String getActiveDc(String clusterId, String shardId); @Override ClusterType getClusterType(String clusterId);  }
@Test public void testGetAllKeepers() { Set<HostPort> allKeepers = metaCache.getAllKeepers(); Assert.assertEquals(6, allKeepers.size()); Assert.assertEquals(Sets.newHashSet(new HostPort("127.0.0.1", 6000), new HostPort("127.0.0.1", 6001), new HostPort("127.0.0.1", 6100), new HostPort("127.0.0.1", 6101), new HostPort("127.0.0.2", 6100), new HostPort("127.0.0.2", 6101)), allKeepers); }