Search in sources :

Example 96 with Address

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));
            }
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) CacheException(javax.cache.CacheException) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) List(java.util.List) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 97 with Address

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-&gt;partitions mapping
 * @return address-&gt;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;
}
Also used : Address(com.hazelcast.cluster.Address) CancelledKeyException(java.nio.channels.CancelledKeyException) Member(com.hazelcast.cluster.Member) MembershipManager(com.hazelcast.internal.cluster.impl.MembershipManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) EmptyStatement(com.hazelcast.internal.util.EmptyStatement) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) ArrayList(java.util.ArrayList) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) MembersView(com.hazelcast.internal.cluster.impl.MembersView) LinkedList(java.util.LinkedList) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CoalescingDelayedTrigger(com.hazelcast.internal.util.scheduler.CoalescingDelayedTrigger) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Connection(com.hazelcast.internal.nio.Connection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientAddClusterViewListenerCodec(com.hazelcast.client.impl.protocol.codec.ClientAddClusterViewListenerCodec) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) CLIENT(com.hazelcast.instance.EndpointQualifier.CLIENT) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Example 98 with Address

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));
    }
}
Also used : Address(com.hazelcast.cluster.Address) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException)

Example 99 with Address

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);
    }
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) AddressProvider(com.hazelcast.client.impl.connection.AddressProvider) HazelcastException(com.hazelcast.core.HazelcastException) Address(com.hazelcast.cluster.Address) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) HazelcastException(com.hazelcast.core.HazelcastException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) IOException(java.io.IOException) AuthenticationException(com.hazelcast.client.AuthenticationException) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) EOFException(java.io.EOFException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientNotAllowedInClusterException(com.hazelcast.client.ClientNotAllowedInClusterException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException)

Example 100 with Address

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);
    }
}
Also used : Address(com.hazelcast.cluster.Address) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) IOException(java.io.IOException) AuthenticationException(com.hazelcast.client.AuthenticationException) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) EOFException(java.io.EOFException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientNotAllowedInClusterException(com.hazelcast.client.ClientNotAllowedInClusterException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32