Search in sources :

Example 76 with Address

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());
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) IPartition(com.hazelcast.spi.partition.IPartition)

Example 77 with Address

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;
}
Also used : Address(com.hazelcast.nio.Address) CancellationException(java.util.concurrent.CancellationException) MapReduceService(com.hazelcast.mapreduce.impl.MapReduceService) JobSupervisor(com.hazelcast.mapreduce.impl.task.JobSupervisor) CancellationException(java.util.concurrent.CancellationException)

Example 78 with Address

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);
            }
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress)

Example 79 with Address

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;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress)

Example 80 with Address

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;
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) SplitBrainJoinMessage(com.hazelcast.internal.cluster.impl.SplitBrainJoinMessage)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13