use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class CacheProxyLoadAllTask method run.
@Override
public void run() {
try {
completionListener = injectDependencies(completionListener);
OperationService operationService = nodeEngine.getOperationService();
OperationFactory operationFactory;
IPartitionService partitionService = nodeEngine.getPartitionService();
Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
int partitionCount = partitionService.getPartitionCount();
Map<Integer, Object> results = createHashMap(partitionCount);
for (Map.Entry<Address, List<Integer>> memberPartitions : memberPartitionsMap.entrySet()) {
Set<Integer> partitions = new PartitionIdSet(partitionCount, memberPartitions.getValue());
Set<Data> ownerKeys = filterOwnerKeys(partitionService, partitions);
operationFactory = operationProvider.createLoadAllOperationFactory(ownerKeys, replaceExistingValues);
Map<Integer, Object> memberResults;
memberResults = operationService.invokeOnPartitions(serviceName, operationFactory, partitions);
results.putAll(memberResults);
}
validateResults(results);
if (completionListener != null) {
completionListener.onCompletion();
}
} catch (Exception e) {
if (completionListener != null) {
completionListener.onException(e);
}
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
throw rethrow(t);
} else {
if (completionListener != null) {
completionListener.onException(new CacheException(t));
}
}
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ClusterViewListenerService method getPartitions.
/**
* If any partition does not have an owner, this method returns empty collection
*
* @param partitionTableView will be converted to address->partitions mapping
* @return address->partitions mapping, where address is the client address of the member
*/
public Map<UUID, List<Integer>> getPartitions(PartitionTableView partitionTableView) {
Map<UUID, List<Integer>> partitionsMap = new HashMap<>();
int partitionCount = partitionTableView.length();
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
PartitionReplica owner = partitionTableView.getReplica(partitionId, 0);
if (owner == null || owner.uuid() == null) {
partitionsMap.clear();
return partitionsMap;
}
partitionsMap.computeIfAbsent(owner.uuid(), k -> new LinkedList<>()).add(partitionId);
}
return partitionsMap;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ClientICMPManager method ping.
private static void ping(ILogger logger, PingFailureDetector<Connection> failureDetector, Connection connection, int icmpTtl, int icmpTimeoutMillis) {
Address address = connection.getRemoteAddress();
logger.fine(format("will ping %s", address));
if (isReachable(logger, icmpTtl, icmpTimeoutMillis, address)) {
failureDetector.heartbeat(connection);
return;
}
failureDetector.logAttempt(connection);
logger.warning(format("Could not ping %s", address));
if (!failureDetector.isAlive(connection)) {
connection.close("ICMP ping time out", new TargetDisconnectedException("ICMP ping time out to connection " + connection));
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpClientConnectionManager method translate.
private Address translate(Address target) {
CandidateClusterContext currentContext = clusterDiscoveryService.current();
AddressProvider addressProvider = currentContext.getAddressProvider();
try {
Address translatedAddress = addressProvider.translate(target);
if (translatedAddress == null) {
throw new HazelcastException("Address Provider " + addressProvider.getClass() + " could not translate address " + target);
}
return translatedAddress;
} catch (Exception e) {
logger.warning("Failed to translate address " + target + " via address provider " + e.getMessage());
throw rethrow(e);
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpClientConnectionManager method authenticateOnCluster.
private ClientAuthenticationCodec.ResponseParameters authenticateOnCluster(TcpClientConnection connection) {
Address memberAddress = connection.getInitAddress();
ClientMessage request = encodeAuthenticationRequest(memberAddress);
ClientInvocationFuture future = new ClientInvocation(client, request, null, connection).invokeUrgent();
try {
return ClientAuthenticationCodec.decodeResponse(future.get(authenticationTimeout, MILLISECONDS));
} catch (Exception e) {
connection.close("Failed to authenticate connection", e);
throw rethrow(e);
}
}
Aggregations