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

x33g5p2x  于2022-01-25 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(108)

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

Member.getStringAttribute介绍

[英]Returns the value of the specified key for this member or null if value is undefined.
[中]返回此成员的指定键的值,如果值未定义,则返回null。

代码示例

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

public void propagateExceptions() {
  if (!failedMembers.isEmpty()) {
   String failedMemberNames = failedMembers.keySet().stream()
    .map(m -> m.getStringAttribute(NODE_NAME.getKey()))
    .collect(Collectors.joining(", "));
   throw new IllegalStateException("Distributed cluster action in cluster nodes " + failedMemberNames + " (other nodes may have timed out)",
    failedMembers.values().iterator().next());
  }

  if (!timedOutMembers.isEmpty()) {
   String timedOutMemberNames = timedOutMembers.stream()
    .map(m -> m.getStringAttribute(NODE_NAME.getKey()))
    .collect(Collectors.joining(", "));
   throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames);
  }
 }
}

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

public static MemberSelector selectorForProcessIds(ProcessId... processIds) {
  List<ProcessId> processIdList = asList(processIds);
  return member -> {
   ProcessId memberProcessId = fromKey(member.getStringAttribute(PROCESS_KEY.getKey()));
   return processIdList.contains(memberProcessId);
  };
 }
}

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

private static Member newMember(String uuid) {
  Member member = mock(Member.class);
  when(member.getUuid()).thenReturn(uuid);
  when(member.getStringAttribute(NODE_NAME.getKey())).thenReturn(uuid);
  return member;
 }
}

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

private Member newMember(String name) {
  Member member = mock(Member.class, Mockito.RETURNS_MOCKS);
  when(member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME.getKey())).thenReturn(name);
  when(member.getAddress()).thenReturn(new Address(AN_ADDRESS, 6789));
  return member;
 }
}

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

@Test
public void selecting_ce_nodes() {
 Member member = mock(Member.class);
 MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE);
 when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
 assertThat(underTest.select(member)).isTrue();
 when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
 assertThat(underTest.select(member)).isFalse();
 when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
 assertThat(underTest.select(member)).isFalse();
}

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

public Collection<NodeInfo> load() throws InterruptedException {
 Map<String, NodeInfo> nodesByName = new HashMap<>();
 MemberSelector memberSelector = HazelcastMemberSelectors.selectorForProcessIds(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE);
 DistributedAnswer<ProtobufSystemInfo.SystemInfo> distributedAnswer = hzMember.call(ProcessInfoProvider::provide, memberSelector, DISTRIBUTED_TIMEOUT_MS);
 for (Member member : distributedAnswer.getMembers()) {
  String nodeName = member.getStringAttribute(NODE_NAME.getKey());
  NodeInfo nodeInfo = nodesByName.computeIfAbsent(nodeName, name -> {
   NodeInfo info = new NodeInfo(name);
   info.setHost(member.getAddress().getHost());
   return info;
  });
  completeNodeInfo(distributedAnswer, member, nodeInfo);
 }
 return nodesByName.values();
}

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

@Test
 public void selecting_web_and_app_nodes() {
  Member member = mock(Member.class);
  MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP);

  when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
  assertThat(underTest.select(member)).isFalse();

  when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
  assertThat(underTest.select(member)).isTrue();

  when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
  assertThat(underTest.select(member)).isTrue();
 }
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
  public boolean select(Member member) {
    return !"admin".equalsIgnoreCase(member.getStringAttribute(pn_cluster_node_role));
  }
});

代码示例来源:origin: dsukhoroslov/bagri

public static String[] getMemberSchemas(Member member) {
  String schemas = member.getStringAttribute(pn_cluster_node_schemas);
  if (schemas != null && schemas.trim().length() > 0) {
    return schemas.split(" ");
  }
  return new String[0];
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public int compare(Member m1, Member m2) {
  String role1 = m1.getStringAttribute(pn_cluster_node_role);
  String role2 = m2.getStringAttribute(pn_cluster_node_role);
  if (role1.equals(role2)) {
    return m1.getUuid().compareTo(m2.getUuid());
  }
  return "admin".equals(role1) ? +1 : -1; 
}

代码示例来源:origin: dsukhoroslov/bagri

@ManagedAttribute(description="Returns active Node configuration name")
public String getName() {
  return member.getStringAttribute(pn_cluster_node_name);
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast

public HazelcastNode(Member member) {
  InetSocketAddress address = member.getSocketAddress();
  this.host = getHostString(address);
  this.port = address.getPort();
  StringBuilder builder = new StringBuilder();
  this.id = builder.append(host).append(":").append(port).toString();
  this.alias = member.getStringAttribute("alias");
}

代码示例来源:origin: apache/karaf-cellar

public HazelcastNode(Member member) {
  InetSocketAddress address = member.getSocketAddress();
  this.host = getHostString(address);
  this.port = address.getPort();
  StringBuilder builder = new StringBuilder();
  this.id = builder.append(host).append(":").append(port).toString();
  this.alias = member.getStringAttribute("alias");
}

代码示例来源:origin: dsukhoroslov/bagri

private List<Member> getMembers(String name) {
  List<Member> members = new ArrayList<Member>();
  for (Member member: hzInstance.getCluster().getMembers()) {
    if (name.equals(member.getStringAttribute(pn_cluster_node_name))) {
      members.add(member);
    }
  }
  return members;
}

代码示例来源:origin: org.neo4j/neo4j-core-edge

static Pair<MemberId,CoreAddresses> extractMemberAttributes( Member member )
  {
    MemberId memberId = new MemberId( UUID.fromString( member.getStringAttribute( MEMBER_UUID ) ) );

    return Pair.of( memberId, new CoreAddresses(
        socketAddress( member.getStringAttribute( RAFT_SERVER ), AdvertisedSocketAddress::new ),
        socketAddress( member.getStringAttribute( TRANSACTION_SERVER ), AdvertisedSocketAddress::new ),
        ClientConnectorAddresses.fromString( member.getStringAttribute( CLIENT_CONNECTOR_ADDRESSES ) )
    ) );
  }
}

代码示例来源:origin: org.neo4j/neo4j-causal-clustering

private static boolean canBeBootstrapped( HazelcastInstance hazelcastInstance, Config config )
{
  Set<Member> members = hazelcastInstance.getCluster().getMembers();
  String dbName = config.get( CausalClusteringSettings.database );
  Predicate<Member> acceptsToBeLeader = m -> !m.getBooleanAttribute( REFUSE_TO_BE_LEADER_KEY );
  Predicate<Member> hostsMyDb = m -> dbName.equals( m.getStringAttribute( MEMBER_DB_NAME ) );
  Stream<Member> membersWhoCanLeadForMyDb = members.stream().filter( acceptsToBeLeader ).filter( hostsMyDb );
  Optional<Member> firstAppropriateMember = membersWhoCanLeadForMyDb.findFirst();
  return firstAppropriateMember.map( Member::localMember ).orElse( false );
}

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

private boolean isAppNode(Member member) {
 return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(NODE_TYPE.getKey()));
}

代码示例来源:origin: dsukhoroslov/bagri

private static Set<Member> getAdmins(HazelcastInstance hzInstance) {
  Set<Member> admins = new HashSet<>();
  Set<Member> members = hzInstance.getCluster().getMembers();
  for (Member member: members) {
    if (isAdminRole(member.getStringAttribute(pn_cluster_node_role))) {
      admins.add(member);
    }
  }
  return admins;
}

代码示例来源:origin: dsukhoroslov/bagri

protected String getCurrentUser() {
  return JMXUtils.getCurrentUser(((Member) hzInstance.getLocalEndpoint()).getStringAttribute(pn_cluster_login));
}

代码示例来源:origin: dsukhoroslov/bagri

public static HazelcastInstance findSchemaInstance(String schemaName) {
  // do we need synchronize this block?
  if (node_instance == null) {
    HazelcastInstance hzInstance = findSystemInstance();
    node_instance = ((Member) hzInstance.getLocalEndpoint()).getStringAttribute(pn_node_instance);
  }
  return Hazelcast.getHazelcastInstanceByName(schemaName + "-" + node_instance);
}

相关文章