Search in sources :

Example 6 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class AbstractSerializationService method readObject.

@Override
public final <T> T readObject(final ObjectDataInput in, Class aClass) {
    try {
        final int typeId = in.readInt();
        final SerializerAdapter serializer = serializerFor(typeId);
        if (serializer == null) {
            if (active) {
                throw newHazelcastSerializationException(typeId);
            }
            throw new HazelcastInstanceNotActiveException();
        }
        Object obj = serializer.read(in, aClass);
        if (managedContext != null) {
            obj = managedContext.initialize(obj);
        }
        return (T) obj;
    } catch (Throwable e) {
        throw handleException(e);
    }
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)

Example 7 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class Invocation method engineActive.

private boolean engineActive() {
    NodeState state = context.node.getState();
    if (state == NodeState.ACTIVE) {
        return true;
    }
    boolean allowed = state == NodeState.PASSIVE && (op instanceof AllowedDuringPassiveState);
    if (!allowed) {
        notifyError(new HazelcastInstanceNotActiveException("State: " + state + " Operation: " + op.getClass()));
        remote = false;
    }
    return allowed;
}
Also used : AllowedDuringPassiveState(com.hazelcast.spi.impl.AllowedDuringPassiveState) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) NodeState(com.hazelcast.instance.NodeState)

Example 8 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class InvocationRegistry method register.

/**
     * Registers an invocation.
     *
     * @param invocation The invocation to register.
     * @return false when InvocationRegistry is not alive and registration is not successful, true otherwise
     */
public boolean register(Invocation invocation) {
    final long callId;
    try {
        boolean force = invocation.op.isUrgent() || invocation.isRetryCandidate();
        callId = callIdSequence.next(force);
    } catch (TimeoutException e) {
        throw new HazelcastOverloadException("Failed to start invocation due to overload: " + invocation, e);
    }
    try {
        // Fails with IllegalStateException if the operation is already active
        setCallId(invocation.op, callId);
    } catch (IllegalStateException e) {
        callIdSequence.complete();
        throw e;
    }
    invocations.put(callId, invocation);
    if (!alive) {
        invocation.notifyError(new HazelcastInstanceNotActiveException());
        return false;
    }
    return true;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) TimeoutException(java.util.concurrent.TimeoutException)

Example 9 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class ReliableMessageListenerRunner method onFailure.

// This method is called from the provided executor.
@Override
public void onFailure(Throwable t) {
    if (cancelled) {
        return;
    }
    if (t instanceof StaleSequenceException) {
        StaleSequenceException staleSequenceException = (StaleSequenceException) t;
        if (listener.isLossTolerant()) {
            if (logger.isFinestEnabled()) {
                logger.finest("MessageListener " + listener + " on topic: " + topicName + " ran into a stale sequence. " + "Jumping from oldSequence: " + sequence + " to sequence: " + staleSequenceException.getHeadSeq());
            }
            sequence = staleSequenceException.getHeadSeq();
            next();
            return;
        }
        logger.warning("Terminating MessageListener:" + listener + " on topic: " + topicName + ". " + "Reason: The listener was too slow or the retention period of the message has been violated. " + "head: " + staleSequenceException.getHeadSeq() + " sequence:" + sequence);
    } else if (t instanceof HazelcastInstanceNotActiveException) {
        if (logger.isFinestEnabled()) {
            logger.finest("Terminating MessageListener " + listener + " on topic: " + topicName + ". " + " Reason: HazelcastInstance is shutting down");
        }
    } else if (t instanceof DistributedObjectDestroyedException) {
        if (logger.isFinestEnabled()) {
            logger.finest("Terminating MessageListener " + listener + " on topic: " + topicName + ". " + "Reason: Topic is destroyed");
        }
    } else {
        logger.warning("Terminating MessageListener " + listener + " on topic: " + topicName + ". " + "Reason: Unhandled exception, message: " + t.getMessage(), t);
    }
    cancel();
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException)

Example 10 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class QueueAdvancedTest method testDeadTaker.

/**
     * Test for issue 730 (Google).
     */
@Test
public void testDeadTaker() throws Exception {
    Config config = new Config();
    final CountDownLatch shutdownLatch = new CountDownLatch(1);
    config.addListenerConfig(new ListenerConfig().setImplementation(new MembershipListener() {

        @Override
        public void memberAdded(MembershipEvent membershipEvent) {
        }

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            shutdownLatch.countDown();
        }

        @Override
        public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
        }
    }));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = factory.newInstances(config);
    final HazelcastInstance h1 = instances[0];
    final HazelcastInstance h2 = instances[1];
    warmUpPartitions(h1, h2);
    final IQueue<String> q1 = h1.getQueue("default");
    final IQueue<String> q2 = h2.getQueue("default");
    final CountDownLatch startLatch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                assertTrue("Expected startLatch.await() to succeed within 10 seconds", startLatch.await(10, SECONDS));
                Thread.sleep(5000);
                h2.getLifecycleService().terminate();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                startLatch.countDown();
                String value = q2.take();
                fail("Should not be able to take value from queue, but got: " + value);
            } catch (HazelcastInstanceNotActiveException e) {
                EmptyStatement.ignore(e);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
    assertTrue("Expected shutdownLatch.await() to succeed within 1 minute", shutdownLatch.await(1, MINUTES));
    q1.offer("item");
    assertEquals(1, q1.size());
    assertEquals("item", q1.poll());
}
Also used : MemberAttributeEvent(com.hazelcast.core.MemberAttributeEvent) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MembershipEvent(com.hazelcast.core.MembershipEvent) CountDownLatch(java.util.concurrent.CountDownLatch) TestThread(com.hazelcast.test.TestThread) ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MembershipListener(com.hazelcast.core.MembershipListener) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)34 HazelcastException (com.hazelcast.core.HazelcastException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 Test (org.junit.Test)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 TransactionException (com.hazelcast.transaction.TransactionException)6 OCallable (com.orientechnologies.common.util.OCallable)6 ExecutionException (java.util.concurrent.ExecutionException)6 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)5 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)5 AssertTask (com.hazelcast.test.AssertTask)5 Callable (java.util.concurrent.Callable)5 TransactionOptions (com.hazelcast.transaction.TransactionOptions)4