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) {
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);
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 MapTransactionTest method testTxnOwnerDies.
@Test
@Category(NightlyTest.class)
public void testTxnOwnerDies() throws TransactionException, InterruptedException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final HazelcastInstance h3 = factory.newHazelcastInstance(config);
final int size = 50;
final AtomicBoolean result = new AtomicBoolean(false);
Runnable runnable = new Runnable() {
public void run() {
try {
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
for (int i = 0; i < size; i++) {
txMap.put(i, i);
sleepSeconds(1);
}
return true;
}
});
result.set(b);
} catch (HazelcastInstanceNotActiveException ignored) {
} catch (TransactionException ignored) {
}
}
};
Thread thread = new Thread(runnable);
thread.start();
sleepSeconds(1);
h1.shutdown();
// wait till thread finishes.
thread.join(30 * 1000);
assertFalse(result.get());
final IMap map2 = h2.getMap("default");
for (int i = 0; i < size; i++) {
assertNull(map2.get(i));
}
}
use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.
the class ClientEndpointImpl method destroy.
public void destroy() throws LoginException {
clearAllListeners();
LoginContext lc = loginContext;
if (lc != null) {
lc.logout();
}
for (TransactionContext context : transactionContextMap.values()) {
if (context instanceof XATransactionContextImpl) {
continue;
}
try {
context.rollbackTransaction();
} catch (HazelcastInstanceNotActiveException e) {
getLogger().finest(e);
} catch (Exception e) {
getLogger().warning(e);
}
}
authenticated = false;
}
use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.
the class OperationRunnerImpl method checkNodeState.
private void checkNodeState(Operation op) {
NodeState state = node.getState();
if (state == NodeState.ACTIVE) {
return;
}
Address localAddress = node.getThisAddress();
if (state == NodeState.SHUT_DOWN) {
throw new HazelcastInstanceNotActiveException("Member " + localAddress + " is shut down! Operation: " + op);
}
if (op instanceof AllowedDuringPassiveState) {
return;
}
// Cluster is in passive state. There is no need to retry.
if (nodeEngine.getClusterService().getClusterState() == ClusterState.PASSIVE) {
throw new IllegalStateException("Cluster is in " + ClusterState.PASSIVE + " state! Operation: " + op);
}
// Operation will fail since node is shutting down or cluster is passive.
if (op.getPartitionId() < 0) {
throw new HazelcastInstanceNotActiveException("Member " + localAddress + " is currently passive! Operation: " + op);
}
// Since operation has a partition id, it must be retried on another node.
throw new RetryableHazelcastException("Member " + localAddress + " is currently shutting down! Operation: " + op);
}
use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.
the class XAResourceImpl method recover.
@Override
public Xid[] recover(int flag) throws XAException {
NodeEngine nodeEngine = getNodeEngine();
XAService xaService = getService();
OperationService operationService = nodeEngine.getOperationService();
ClusterService clusterService = nodeEngine.getClusterService();
Collection<Member> memberList = clusterService.getMembers();
List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
for (Member member : memberList) {
if (member.localMember()) {
continue;
}
CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
Address address = member.getAddress();
InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
futureList.add(future);
}
HashSet<SerializableXID> xids = new HashSet<SerializableXID>();
xids.addAll(xaService.getPreparedXids());
for (Future<SerializableList> future : futureList) {
try {
SerializableList xidSet = future.get();
for (Data xidData : xidSet) {
SerializableXID xid = nodeEngine.toObject(xidData);
xids.add(xid);
}
} catch (InterruptedException e) {
throw new XAException(XAException.XAER_RMERR);
} catch (MemberLeftException e) {
logger.warning("Member left while recovering", e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
logger.warning("Member left while recovering", e);
} else {
throw new XAException(XAException.XAER_RMERR);
}
}
}
return xids.toArray(new SerializableXID[xids.size()]);
}
Aggregations