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);
}
}
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;
}
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;
}
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();
}
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());
}
Aggregations