Search in sources :

Example 91 with Address

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

the class OperationRunnerImpl method run.

@Override
public boolean run(Packet packet) throws Exception {
    long startNanos = System.nanoTime();
    boolean publishCurrentTask = publishCurrentTask();
    if (publishCurrentTask) {
        currentTask = packet;
    }
    ServerConnection connection = packet.getConn();
    Address caller = connection.getRemoteAddress();
    UUID callerUuid = connection.getRemoteUuid();
    Operation op = null;
    try {
        Object object = nodeEngine.toObject(packet);
        op = (Operation) object;
        op.setNodeEngine(nodeEngine);
        setCallerAddress(op, caller);
        setConnection(op, connection);
        setCallerUuidIfNotSet(op, callerUuid);
        setOperationResponseHandler(op);
        if (!ensureValidMember(op)) {
            return false;
        }
        if (publishCurrentTask) {
            currentTask = null;
        }
        return run(op, startNanos);
    } catch (Throwable throwable) {
        // If exception happens we need to extract the callId from the bytes directly!
        long callId = extractOperationCallId(packet);
        outboundResponseHandler.send(connection.getConnectionManager(), caller, new ErrorResponse(throwable, callId, packet.isUrgent()));
        logOperationDeserializationException(throwable, callId);
        throw ExceptionUtil.rethrow(throwable);
    } finally {
        if (op != null) {
            op.clearThreadContext();
        }
        if (publishCurrentTask) {
            currentTask = null;
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operations.isJoinOperation(com.hazelcast.spi.impl.operationservice.Operations.isJoinOperation) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) BlockingOperation(com.hazelcast.spi.impl.operationservice.BlockingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) Operations.isMigrationOperation(com.hazelcast.spi.impl.operationservice.Operations.isMigrationOperation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operations.isWanReplicationOperation(com.hazelcast.spi.impl.operationservice.Operations.isWanReplicationOperation) UUID(java.util.UUID) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 92 with Address

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

the class InboundResponseHandler method accept.

@Override
public void accept(Packet packet) {
    checkNotNull(packet, "packet can't be null");
    checkTrue(packet.getPacketType() == OPERATION, "Packet type is not OPERATION");
    checkTrue(packet.isFlagRaised(FLAG_OP_RESPONSE), "FLAG_OP_RESPONSE is not set");
    byte[] bytes = packet.toByteArray();
    int typeId = Bits.readInt(bytes, OFFSET_TYPE_ID, useBigEndian);
    long callId = Bits.readLong(bytes, OFFSET_CALL_ID, useBigEndian);
    Address sender = packet.getConn().getRemoteAddress();
    try {
        switch(typeId) {
            case NORMAL_RESPONSE:
                byte backupAcks = bytes[OFFSET_BACKUP_ACKS];
                notifyNormalResponse(callId, packet, backupAcks, sender);
                break;
            case BACKUP_ACK_RESPONSE:
                notifyBackupComplete(callId);
                break;
            case CALL_TIMEOUT_RESPONSE:
                notifyCallTimeout(callId, sender);
                break;
            case ERROR_RESPONSE:
                ErrorResponse errorResponse = serializationService.toObject(packet);
                notifyErrorResponse(callId, errorResponse.getCause(), sender);
                break;
            default:
                logger.severe("Unrecognized type: " + typeId + " packet:" + packet);
        }
    } catch (Throwable e) {
        logger.severe("While processing response...", e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 93 with Address

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

the class InvokeOnPartitions method invokeOnAllPartitions.

private void invokeOnAllPartitions() {
    if (memberPartitions.isEmpty()) {
        future.complete(Collections.EMPTY_MAP);
        return;
    }
    for (final Map.Entry<Address, List<Integer>> mp : memberPartitions.entrySet()) {
        final Address address = mp.getKey();
        List<Integer> partitions = mp.getValue();
        PartitionIteratingOperation op = new PartitionIteratingOperation(operationFactory, toIntArray(partitions));
        operationService.createInvocationBuilder(serviceName, op, address).setTryCount(TRY_COUNT).setTryPauseMillis(TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(new FirstAttemptExecutionCallback(partitions));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Address(com.hazelcast.cluster.Address) List(java.util.List) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map)

Example 94 with Address

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

the class CacheSerializationTest method testCachePartitionEventData.

@Test
public void testCachePartitionEventData() throws UnknownHostException {
    Address address = new Address("127.0.0.1", 5701);
    Member member = new MemberImpl(address, MemberVersion.UNKNOWN, true);
    CachePartitionEventData cachePartitionEventData = new CachePartitionEventData("test", 1, member);
    CachePartitionEventData deserialized = service.toObject(cachePartitionEventData);
    assertEquals(cachePartitionEventData, deserialized);
}
Also used : CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 95 with Address

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

the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.

@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(2);
    HazelcastInstance survivingInstance = instances.get(0);
    HazelcastInstance terminatingInstance = instances.get(1);
    HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(survivingInstance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
    ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
    iCache.addPartitionLostListener(listener);
    final Set<Integer> survivingPartitionIds = new HashSet<Integer>();
    Node survivingNode = getNode(survivingInstance);
    Address survivingAddress = survivingNode.getThisAddress();
    for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
        if (survivingAddress.equals(partition.getReplicaAddress(0))) {
            survivingPartitionIds.add(partition.getPartitionId());
        }
    }
    terminatingInstance.getLifecycleService().terminate();
    waitAllForSafeState(survivingInstance);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final List<CachePartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
            for (CachePartitionLostEvent event : events) {
                assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
            }
        }
    });
    cacheManager.destroyCache(getIthCacheName(0));
    cacheManager.close();
    cachingProvider.close();
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) IPartition(com.hazelcast.internal.partition.IPartition) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

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