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; } }
@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(); }
private Map<Address, Address> parseResponse(InputStream is) throws IOException { JsonValue jsonValue = Json.parse(readInputStream(is)); List<JsonValue> response = jsonValue.asArray().values(); Map<Address, Address> privateToPublicAddresses = new HashMap<Address, Address>(); for (JsonValue value : response) { String privateAddress = value.asObject().get(PRIVATE_ADDRESS_PROPERTY).asString(); String publicAddress = value.asObject().get(PUBLIC_ADDRESS_PROPERTY).asString(); Address publicAddr = createAddress(publicAddress); privateToPublicAddresses.put(new Address(privateAddress, publicAddr.getPort()), publicAddr); } return privateToPublicAddresses; }
private static int[] arrangeLocalPartitions(Address[] partitionOwners, Address thisAddress) { return IntStream.range(0, partitionOwners.length) .filter(partitionId -> thisAddress.equals(partitionOwners[partitionId])) .toArray(); }
public MockIOService(Address thisAddress, LoggingService loggingService) throws Exception { this.thisAddress = thisAddress; this.loggingService = loggingService; serverSocketChannel = ServerSocketChannel.open(); ServerSocket serverSocket = serverSocketChannel.socket(); serverSocket.setReuseAddress(true); serverSocket.setSoTimeout(1000); serverSocket.bind(new InetSocketAddress("0.0.0.0", thisAddress.getPort())); this.serializationService = new DefaultSerializationServiceBuilder().build(); }
protected AbstractMember(Address address, MemberVersion version, String uuid, Map<String, Object> attributes, boolean liteMember) { assert address != null : "Address is required!"; this.address = address; this.version = version; this.uuid = uuid != null ? uuid : "<" + address.toString() + ">"; if (attributes != null) { this.attributes.putAll(attributes); } this.liteMember = liteMember; }
public InetSocketAddress getInetSocketAddress() throws UnknownHostException { return new InetSocketAddress(getInetAddress(), port); }
private MemberImpl createMember(MemberInfo memberInfo, Map<String, Object> attributes) { Address address = memberInfo.getAddress(); Address thisAddress = node.getThisAddress(); String ipV6ScopeId = thisAddress.getScopeId(); address.setScopeId(ipV6ScopeId); boolean localMember = thisAddress.equals(address); return new MemberImpl(address, memberInfo.getVersion(), localMember, memberInfo.getUuid(), attributes, memberInfo.isLiteMember(), memberInfo.getMemberListJoinVersion(), node.hazelcastInstance); }
private Map<Address, Address> parseResponse(InputStream is) throws IOException { JsonValue jsonValue = Json.parse(readInputStream(is)); List<JsonValue> response = jsonValue.asArray().values(); Map<Address, Address> privateToPublicAddresses = new HashMap<Address, Address>(); for (JsonValue value : response) { String privateAddress = value.asObject().get(PRIVATE_ADDRESS_PROPERTY).asString(); String publicAddress = value.asObject().get(PUBLIC_ADDRESS_PROPERTY).asString(); Address publicAddr = createAddress(publicAddress); privateToPublicAddresses.put(new Address(privateAddress, publicAddr.getPort()), publicAddr); } return privateToPublicAddresses; }
@Override public boolean isOwnerOrBackup(Address address) { if (address == null) { return false; } for (int i = 0; i < MAX_REPLICA_COUNT; i++) { if (address.equals(getAddress(replicas[i]))) { return true; } } return false; }
private static void printMemberPort(HazelcastInstance hz) throws Exception { String printPort = System.getProperty("print.port"); if (printPort != null) { PrintWriter printWriter = null; try { printWriter = new PrintWriter("ports" + File.separator + printPort, "UTF-8"); printWriter.println(hz.getCluster().getLocalMember().getAddress().getPort()); } finally { closeResource(printWriter); } } } }
protected AbstractMember(Address address, MemberVersion version, String uuid, Map<String, Object> attributes, boolean liteMember) { assert address != null : "Address is required!"; this.address = address; this.version = version; this.uuid = uuid != null ? uuid : "<" + address.toString() + ">"; if (attributes != null) { this.attributes.putAll(attributes); } this.liteMember = liteMember; }
public InetSocketAddress getInetSocketAddress() throws UnknownHostException { return new InetSocketAddress(getInetAddress(), port); }