use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method tryJoinAddresses.
private void tryJoinAddresses(Collection<Address> addresses) throws InterruptedException {
long connectionTimeoutMillis = TimeUnit.SECONDS.toMillis(getConnTimeoutSeconds());
long start = Clock.currentTimeMillis();
while (!clusterService.isJoined() && Clock.currentTimeMillis() - start < connectionTimeoutMillis) {
Address masterAddress = clusterService.getMasterAddress();
if (isAllBlacklisted(addresses) && masterAddress == null) {
return;
}
if (masterAddress != null) {
if (logger.isFineEnabled()) {
logger.fine("Sending join request to " + masterAddress);
}
clusterJoinManager.sendJoinRequest(masterAddress);
} else {
sendMasterQuestion(addresses);
}
if (!clusterService.isJoined()) {
clusterService.blockOnJoin(JOIN_RETRY_WAIT_TIME);
}
addresses.removeIf(address -> {
try {
return isLocalAddress(address);
} catch (UnknownHostException e) {
if (logger.isFineEnabled()) {
logger.fine("Error during resolving possible target address!", e);
}
ignore(e);
return false;
}
});
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method getRequiredMemberAddress.
private Address getRequiredMemberAddress() {
TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
String host = tcpIpConfig.getRequiredMember();
try {
AddressHolder addressHolder = AddressUtil.getAddressHolder(host, getActiveMemberNetworkConfig(config).getPort());
if (AddressUtil.isIpAddress(addressHolder.getAddress())) {
return new Address(addressHolder.getAddress(), addressHolder.getPort());
}
InterfacesConfig interfaces = getActiveMemberNetworkConfig(config).getInterfaces();
if (interfaces.isEnabled()) {
InetAddress[] inetAddresses = InetAddress.getAllByName(addressHolder.getAddress());
if (inetAddresses.length > 1) {
for (InetAddress inetAddress : inetAddresses) {
if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
return new Address(inetAddress, addressHolder.getPort());
}
}
} else if (AddressUtil.matchAnyInterface(inetAddresses[0].getHostAddress(), interfaces.getInterfaces())) {
return new Address(addressHolder.getAddress(), addressHolder.getPort());
}
} else {
return new Address(addressHolder.getAddress(), addressHolder.getPort());
}
} catch (final Exception e) {
logger.warning(e);
}
return null;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ClusterHeartbeatManager method onInvalidHeartbeat.
private void onInvalidHeartbeat(MembersViewMetadata senderMembersViewMetadata) {
Address senderAddress = senderMembersViewMetadata.getMemberAddress();
if (clusterService.isMaster()) {
if (!clusterService.getClusterJoinManager().isMastershipClaimInProgress()) {
logger.fine("Sending explicit suspicion to " + senderAddress + " for heartbeat " + senderMembersViewMetadata + ", because it is not a member of this cluster" + " or its heartbeat cannot be validated!");
clusterService.sendExplicitSuspicion(senderMembersViewMetadata);
}
} else {
MemberImpl master = clusterService.getMember(clusterService.getMasterAddress());
if (clusterService.getMembershipManager().isMemberSuspected(master)) {
logger.fine("Not sending heartbeat complaint for " + senderMembersViewMetadata + " to suspected master: " + master.getAddress());
return;
}
logger.fine("Sending heartbeat complaint to master " + master.getAddress() + " for heartbeat " + senderMembersViewMetadata + ", because it is not a member of this cluster" + " or its heartbeat cannot be validated!");
sendHeartbeatComplaintToMaster(senderMembersViewMetadata);
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ClusterStateManager method lockClusterStateOnAllMembers.
private void lockClusterStateOnAllMembers(ClusterStateChange stateChange, NodeEngineImpl nodeEngine, long leaseTime, UUID txnId, Collection<MemberImpl> members, int memberListVersion, long partitionStateStamp) {
Collection<Future> futures = new ArrayList<>(members.size());
final Address thisAddress = node.getThisAddress();
for (Member member : members) {
Operation op = new LockClusterStateOp(stateChange, thisAddress, txnId, leaseTime, memberListVersion, partitionStateStamp);
Future future = nodeEngine.getOperationService().invokeOnTarget(SERVICE_NAME, op, member.getAddress());
futures.add(future);
}
StateManagerExceptionHandler exceptionHandler = new StateManagerExceptionHandler(logger);
waitWithDeadline(futures, leaseTime, TimeUnit.MILLISECONDS, exceptionHandler);
exceptionHandler.rethrowIfFailed();
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MemberMap method createNew.
/**
* Creates a new {@code MemberMap} including given members.
*
* @param version version
* @param members members
* @return a new {@code MemberMap}
*/
static MemberMap createNew(int version, MemberImpl... members) {
Map<Address, MemberImpl> addressMap = createLinkedHashMap(members.length);
Map<UUID, MemberImpl> uuidMap = createLinkedHashMap(members.length);
for (MemberImpl member : members) {
putMember(addressMap, uuidMap, member);
}
return new MemberMap(version, addressMap, uuidMap);
}
Aggregations