Search in sources :

Example 61 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MapCombineTask method requestAssignment.

private static void requestAssignment(Set<Object> keys, JobSupervisor supervisor) {
    try {
        MapReduceService mapReduceService = supervisor.getMapReduceService();
        String name = supervisor.getConfiguration().getName();
        String jobId = supervisor.getConfiguration().getJobId();
        KeysAssignmentResult assignmentResult = mapReduceService.processRequest(supervisor.getJobOwner(), new KeysAssignmentOperation(name, jobId, keys));
        if (assignmentResult.getResultState() == SUCCESSFUL) {
            Map<Object, Address> assignment = assignmentResult.getAssignment();
            for (Map.Entry<Object, Address> entry : assignment.entrySet()) {
                // Cache the keys for later mappings
                if (!supervisor.assignKeyReducerAddress(entry.getKey(), entry.getValue())) {
                    throw new IllegalStateException("Key reducer assignment in illegal state");
                }
            }
        }
    } catch (Exception e) {
        // Just announce it to higher levels
        throw new RuntimeException(e);
    }
}
Also used : KeysAssignmentOperation(com.hazelcast.mapreduce.impl.operation.KeysAssignmentOperation) Address(com.hazelcast.nio.Address) KeysAssignmentResult(com.hazelcast.mapreduce.impl.operation.KeysAssignmentResult) MapReduceService(com.hazelcast.mapreduce.impl.MapReduceService) HashMap(java.util.HashMap) Map(java.util.Map) MapReduceUtil.notifyRemoteException(com.hazelcast.mapreduce.impl.MapReduceUtil.notifyRemoteException) TimeoutException(java.util.concurrent.TimeoutException)

Example 62 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class TrackableJobFuture method shouldCancel.

@Override
protected boolean shouldCancel(boolean mayInterruptIfRunning) {
    Address jobOwner = mapReduceService.getLocalAddress();
    if (!mapReduceService.registerJobSupervisorCancellation(name, jobId, jobOwner)) {
        return false;
    }
    JobSupervisor supervisor = mapReduceService.getJobSupervisor(name, jobId);
    if (supervisor == null || !supervisor.isOwnerNode()) {
        return false;
    }
    Exception exception = new CancellationException("Operation was cancelled by the user");
    return supervisor.cancelAndNotify(exception);
}
Also used : Address(com.hazelcast.nio.Address) CancellationException(java.util.concurrent.CancellationException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException)

Example 63 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class TcpIpConnectionManager method onClose.

/**
     * Deals with cleaning up a closed connection. This method should only be called once by the
     * {@link TcpIpConnection#close(String, Throwable)} method where it is protected against multiple closes.
     */
void onClose(Connection connection) {
    closedCount.inc();
    if (activeConnections.remove(connection)) {
        // this should not be needed; but some tests are using DroppingConnection which is not a TcpIpConnection.
        if (connection instanceof TcpIpConnection) {
            ioThreadingModel.onConnectionRemoved((TcpIpConnection) connection);
        }
        metricsRegistry.discardMetrics(connection);
    }
    Address endPoint = connection.getEndPoint();
    if (endPoint != null) {
        connectionsInProgress.remove(endPoint);
        connectionsMap.remove(endPoint, connection);
        fireConnectionRemovedEvent(connection, endPoint);
    }
}
Also used : Address(com.hazelcast.nio.Address)

Example 64 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class HostAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Map<String, MemberGroup> groups = new HashMap<String, MemberGroup>();
    for (Member member : allMembers) {
        Address address = ((MemberImpl) member).getAddress();
        MemberGroup group = groups.get(address.getHost());
        if (group == null) {
            group = new DefaultMemberGroup();
            groups.put(address.getHost(), group);
        }
        group.addMember(member);
    }
    return new HashSet<MemberGroup>(groups.values());
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet)

Example 65 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ReplicatedMapService method triggerAntiEntropy.

/** Send an operation to all replicas to check their replica versions for all partitions for which this node is the owner */
public void triggerAntiEntropy() {
    if (clusterService.getSize(DATA_MEMBER_SELECTOR) == 1) {
        return;
    }
    Collection<Address> addresses = new ArrayList<Address>(getMemberAddresses(DATA_MEMBER_SELECTOR));
    addresses.remove(nodeEngine.getThisAddress());
    for (int i = 0; i < partitionContainers.length; i++) {
        Address thisAddress = nodeEngine.getThisAddress();
        InternalPartition partition = partitionService.getPartition(i, false);
        Address ownerAddress = partition.getOwnerOrNull();
        if (!thisAddress.equals(ownerAddress)) {
            continue;
        }
        PartitionContainer partitionContainer = partitionContainers[i];
        if (partitionContainer.isEmpty()) {
            continue;
        }
        for (Address address : addresses) {
            CheckReplicaVersionOperation checkReplicaVersionOperation = new CheckReplicaVersionOperation(partitionContainer);
            checkReplicaVersionOperation.setPartitionId(i);
            checkReplicaVersionOperation.setValidateTarget(false);
            operationService.createInvocationBuilder(SERVICE_NAME, checkReplicaVersionOperation, address).setTryCount(INVOCATION_TRY_COUNT).invoke();
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) CheckReplicaVersionOperation(com.hazelcast.replicatedmap.impl.operation.CheckReplicaVersionOperation) ArrayList(java.util.ArrayList) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

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