use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class GetPartitionsMessageTask method call.
protected Object call() {
InternalPartitionService service = getService(InternalPartitionService.SERVICE_NAME);
service.firstArrangement();
Map<Address, List<Integer>> partitionsMap = new HashMap<Address, List<Integer>>();
for (IPartition partition : service.getPartitions()) {
Address owner = partition.getOwnerOrNull();
if (owner == null) {
partitionsMap.clear();
return ClientGetPartitionsCodec.encodeResponse(partitionsMap.entrySet());
}
List<Integer> indexes = partitionsMap.get(owner);
if (indexes == null) {
indexes = new LinkedList<Integer>();
partitionsMap.put(owner, indexes);
}
indexes.add(partition.getPartitionId());
}
return ClientGetPartitionsCodec.encodeResponse(partitionsMap.entrySet());
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class MapReduceCancelMessageTask method call.
@Override
protected Object call() throws Exception {
MapReduceService mapReduceService = getService(MapReduceService.SERVICE_NAME);
Address jobOwner = mapReduceService.getLocalAddress();
mapReduceService.registerJobSupervisorCancellation(parameters.name, parameters.jobId, jobOwner);
JobSupervisor supervisor = mapReduceService.getJobSupervisor(parameters.name, parameters.jobId);
if (supervisor != null && supervisor.isOwnerNode()) {
Exception exception = new CancellationException("Operation was cancelled by the user");
supervisor.cancelAndNotify(exception);
}
return true;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method lookForMaster.
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
private void lookForMaster(Collection<Address> possibleAddresses) throws InterruptedException {
int tryCount = 0;
while (node.getMasterAddress() == null && tryCount++ < LOOK_FOR_MASTER_MAX_TRY_COUNT) {
sendMasterQuestion(possibleAddresses);
//noinspection BusyWait
Thread.sleep(JOIN_RETRY_WAIT_TIME);
if (isAllBlacklisted(possibleAddresses)) {
break;
}
}
if (node.joined()) {
return;
}
if (isAllBlacklisted(possibleAddresses) && node.getMasterAddress() == null) {
if (logger.isFineEnabled()) {
logger.fine("Setting myself as master! No possible addresses remaining to connect...");
}
clusterJoinManager.setAsMaster();
return;
}
long maxMasterJoinTime = getMaxJoinTimeToMasterNode();
long start = Clock.currentTimeMillis();
while (shouldRetry() && Clock.currentTimeMillis() - start < maxMasterJoinTime) {
Address master = node.getMasterAddress();
if (master != null) {
if (logger.isFineEnabled()) {
logger.fine("Joining to master " + master);
}
clusterJoinManager.sendJoinRequest(master, true);
} else {
break;
}
//noinspection BusyWait
Thread.sleep(JOIN_RETRY_WAIT_TIME);
}
if (!node.joined()) {
Address master = node.getMasterAddress();
if (master != null) {
logger.warning("Couldn't join to the master : " + master);
} else {
if (logger.isFineEnabled()) {
logger.fine("Couldn't find a master! But there was connections available: " + possibleAddresses);
}
}
}
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method isLocalAddress.
private boolean isLocalAddress(final Address address) throws UnknownHostException {
final Address thisAddress = node.getThisAddress();
final boolean local = thisAddress.getInetSocketAddress().equals(address.getInetSocketAddress());
if (logger.isFineEnabled()) {
logger.fine(address + " is local? " + local);
}
return local;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method searchForOtherClusters.
@Override
public void searchForOtherClusters() {
final Collection<Address> possibleAddresses;
try {
possibleAddresses = getPossibleAddresses();
} catch (Throwable e) {
logger.severe(e);
return;
}
possibleAddresses.remove(node.getThisAddress());
possibleAddresses.removeAll(node.getClusterService().getMemberAddresses());
if (possibleAddresses.isEmpty()) {
return;
}
for (Address address : possibleAddresses) {
SplitBrainJoinMessage response = sendSplitBrainJoinMessage(address);
if (shouldMerge(response)) {
logger.warning(node.getThisAddress() + " is merging [tcp/ip] to " + address);
setTargetAddress(address);
startClusterMerge(address);
return;
}
}
}
Aggregations