com.hazelcast.core.Cluster.getMembers()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中com.hazelcast.core.Cluster.getMembers()方法的一些代码示例,展示了Cluster.getMembers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.getMembers()方法的具体详情如下:
包路径:com.hazelcast.core.Cluster
类名称:Cluster
方法名:getMembers

Cluster.getMembers介绍

[英]Set of the current members in the cluster. The returned set is an immutable set; it can't be modified.

The returned set is backed by an ordered set. Every member in the cluster returns the 'members' in the same order. To obtain the oldest member (the master) in the cluster, you can retrieve the first item in the set using 'getMembers().iterator().next()'.
[中]

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Override
public Set<String> getMemberUuids() {
 return hzInstance.getCluster().getMembers().stream().map(Member::getUuid).collect(Collectors.toSet());
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public Optional<String> getLeaderHostName() {
 String leaderId = (String) hzMember.getAtomicReference(LEADER).get();
 if (leaderId != null) {
  Optional<Member> leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst();
  if (leader.isPresent()) {
   return Optional.of(leader.get().getAddress().getHost());
  }
 }
 return Optional.empty();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void build_member() {
 HazelcastMember member = underTest
  .setProcessId(ProcessId.COMPUTE_ENGINE)
  .setNodeName("bar")
  .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
  .setNetworkInterface(loopback.getHostAddress())
  .build();
 assertThat(member.getUuid()).isNotEmpty();
 assertThat(member.getClusterTime()).isGreaterThan(0);
 assertThat(member.getCluster().getMembers()).hasSize(1);
 assertThat(member.getMemberUuids()).containsOnlyOnce(member.getUuid());
 assertThat(member.getAtomicReference("baz")).isNotNull();
 assertThat(member.getLock("baz")).isNotNull();
 assertThat(member.getReplicatedMap("baz")).isNotNull();
 member.close();
}

代码示例来源:origin: apache/usergrid

@Test
public void doTest() {
  logger.info( "do test" );
  Hazelcast.addInstanceListener( this );
  ITopic<Object> topic = Hazelcast.getTopic( "default" );
  topic.addMessageListener( this );
  topic.publish( "my-message-object" );
  Collection<Instance> instances = Hazelcast.getInstances();
  for ( Instance instance : instances ) {
    logger.info( "ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" );
  }
  Set<Member> setMembers = Hazelcast.getCluster().getMembers();
  for ( Member member : setMembers ) {
    logger.info( "isLocalMember " + member.localMember() );
    logger.info( "member.inetsocketaddress " + member.getInetSocketAddress() );
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet

private void setMembersRef() {
  Set<Member> memberSet = clusterRef.getMembers();
  Member[] members = memberSet.toArray(new Member[0]);
  membersRef.set(members);
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void setMembersRef() {
  Set<Member> memberSet = clusterRef.getMembers();
  Member[] members = memberSet.toArray(new Member[0]);
  membersRef.set(members);
}

代码示例来源:origin: hazelcast/hazelcast-jet

private static Address masterAddress(Cluster cluster) {
    return cluster.getMembers().stream().findFirst()
           .orElseThrow(() -> new IllegalStateException("No members found in cluster"))
           .getAddress();
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet

@ManagedAnnotation("memberCount")
@ManagedDescription("size of the cluster")
public int getMemberCount() {
  return cluster.getMembers().size();
}

代码示例来源:origin: hazelcast/hazelcast-jet

@ManagedAnnotation("Members")
@ManagedDescription("List of Members")
public List<String> getMembers() {
  Set<Member> members = cluster.getMembers();
  List<String> list = new ArrayList<String>(members.size());
  for (Member member : members) {
    list.add(member.getSocketAddress().toString());
  }
  return list;
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
protected Address masterAddress() {
  Optional<Member> first = container().getCluster().getMembers().stream().findFirst();
  return first.orElseThrow(() -> new IllegalStateException("No members found in cluster")).getAddress();
}

代码示例来源:origin: com.hazelcast/hazelcast-all

@ManagedAnnotation("memberCount")
@ManagedDescription("size of the cluster")
public int getMemberCount() {
  return cluster.getMembers().size();
}

代码示例来源:origin: org.geoserver.community/gs-hz-cluster

@Override
  protected List<Member> load() {
    HazelcastInstance hz = getHazelcast();
    Cluster c = hz.getCluster();
    List<Member> members = new ArrayList<Member>(c.getMembers());
    return members;
  }
}

代码示例来源:origin: org.wso2.carbon.business-process/org.wso2.carbon.bpel

@Override
public String getLeader() {
  HazelcastInstance hazelcastInstance = BPELServiceComponent.getHazelcastInstance();
  Member leader = hazelcastInstance.getCluster().getMembers().iterator().next();
  String leaderNodeId =
      (String) hazelcastInstance.getMap(BPELConstants.BPS_CLUSTER_NODE_MAP).get(getHazelCastNodeID(leader));
  if (log.isDebugEnabled()) {
    log.debug("ODEClusterImpl#getLeader: Hazelcast cluster leader member : " + leader +
        " , NodeId : " + leaderNodeId);
  }
  return leaderNodeId;
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-main

@Override
public Optional<String> getLeaderHostName() {
 String leaderId = (String) hzMember.getAtomicReference(LEADER).get();
 if (leaderId != null) {
  Optional<Member> leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst();
  if (leader.isPresent()) {
   return Optional.of(leader.get().getAddress().getHost());
  }
 }
 return Optional.empty();
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

public static void main(String[] args) {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();

    System.out.println("Instance-1 members: " + instance1.getCluster().getMembers());
    System.out.println("Instance-2 members: " + instance2.getCluster().getMembers());

    // shutdown cluster
    instance2.getCluster().shutdown();

    System.out.println("Instance-1: Is running?: " + instance1.getLifecycleService().isRunning());
    System.out.println("Instance-2: Is running?: " + instance2.getLifecycleService().isRunning());
  }
}

代码示例来源:origin: com.hazelcast.simulator/tests-hz35

public static void waitClusterSize(ILogger logger, HazelcastInstance hz, int clusterSize) {
  for (; ; ) {
    if (hz.getCluster().getMembers().size() >= clusterSize) {
      return;
    }
    logger.info("waiting cluster == " + clusterSize);
    sleepSeconds(1);
  }
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IExecutorService executorService = hz.getExecutorService("executor");

    for (Member member : hz.getCluster().getMembers()) {
      EchoTask task = new EchoTask(member.getSocketAddress().toString());
      executorService.executeOnMember(task, member);
    }
  }
}

代码示例来源:origin: com.hazelcast.simulator/tests-common

private void assertMapMaxSize() {
    if (isMemberNode(targetInstance)) {
      int mapSize = map.size();
      int clusterSize = targetInstance.getCluster().getMembers().size();
      assertTrue(format("Size of map %s should be <= %d * %d, but was %d", name, clusterSize, maxSizePerNode, mapSize),
          mapSize <= clusterSize * maxSizePerNode);
    }
  }
}

代码示例来源:origin: com.hazelcast.simulator/tests-hz310

@Prepare
public void prepare() {
  Set<Member> memberSet = targetInstance.getCluster().getMembers();
  memberAddresses = new Address[memberSet.size()];
  int i = 0;
  for (Member member : memberSet) {
    memberAddresses[i++] = new Address(member.getSocketAddress());
  }
}

代码示例来源:origin: com.hazelcast.simulator/tests-hz35

@Prepare
public void prepare() {
  Set<Member> memberSet = targetInstance.getCluster().getMembers();
  memberAddresses = new Address[memberSet.size()];
  int i = 0;
  for (Member member : memberSet) {
    memberAddresses[i++] = new Address(member.getSocketAddress());
  }
}

相关文章