use of com.hazelcast.core.HazelcastInstanceNotActiveException in project orientdb by orientechnologies.
the class ODistributedAbstractPlugin method onOpen.
/**
* Auto register myself as hook.
*/
@Override
public void onOpen(final ODatabaseInternal iDatabase) {
if (!isRelatedToLocalServer(iDatabase))
return;
if (status != NODE_STATUS.ONLINE && status != NODE_STATUS.STARTING)
return;
final ODatabaseDocumentInternal currDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
try {
final String dbName = iDatabase.getName();
final ODistributedConfiguration cfg = getDatabaseConfiguration(dbName);
if (cfg == null)
return;
ODistributedDatabaseImpl distribDatabase = getMessageService().getDatabase(dbName);
if (distribDatabase == null) {
// CHECK TO PUBLISH IT TO THE CLUSTER
distribDatabase = messageService.registerDatabase(dbName, cfg);
distribDatabase.resume();
distribDatabase.setOnline();
}
if (!(iDatabase.getStorage() instanceof ODistributedStorage) || ((ODistributedStorage) iDatabase.getStorage()).getDistributedManager().isOffline()) {
final ODistributedStorage storage = getStorage(dbName);
// INIT IT
storage.wrap((OAbstractPaginatedStorage) iDatabase.getStorage().getUnderlying());
iDatabase.replaceStorage(storage);
if (isNodeOnline(nodeName, dbName))
installDbClustersLocalStrategy(iDatabase);
}
} catch (HazelcastException e) {
throw new OOfflineNodeException("Hazelcast instance is not available");
} catch (HazelcastInstanceNotActiveException e) {
throw new OOfflineNodeException("Hazelcast instance is not available");
} finally {
// RESTORE ORIGINAL DATABASE INSTANCE IN TL
ODatabaseRecordThreadLocal.INSTANCE.set(currDb);
}
}
use of com.hazelcast.core.HazelcastInstanceNotActiveException in project orientdb by orientechnologies.
the class ODistributedStorage method commit.
@Override
public List<ORecordOperation> commit(final OTransaction iTx, final Runnable callback) {
resetLastValidBackup();
if (OScenarioThreadLocal.INSTANCE.isRunModeDistributed()) {
// ALREADY DISTRIBUTED
try {
return wrapped.commit(iTx, callback);
} catch (ORecordDuplicatedException e) {
// CHECK THE RECORD HAS THE SAME KEY IS STILL UNDER DISTRIBUTED TX
final ODistributedDatabase dDatabase = dManager.getMessageService().getDatabase(getName());
if (dDatabase.getRecordIfLocked(e.getRid()) != null) {
throw new OPossibleDuplicatedRecordException(e);
}
}
}
final ODistributedConfiguration dbCfg = distributedConfiguration;
final String localNodeName = dManager.getLocalNodeName();
checkLocalNodeIsAvailable();
checkNodeIsMaster(localNodeName, dbCfg);
checkClusterRebalanceIsNotRunning();
try {
if (!dbCfg.isReplicationActive(null, localNodeName)) {
// DON'T REPLICATE
OScenarioThreadLocal.executeAsDistributed(new Callable() {
@Override
public Object call() throws Exception {
return wrapped.commit(iTx, callback);
}
});
} else
// EXECUTE DISTRIBUTED TX
return txManager.commit((ODatabaseDocumentTx) ODatabaseRecordThreadLocal.INSTANCE.get(), iTx, callback, eventListener);
} catch (OValidationException e) {
throw e;
} catch (HazelcastInstanceNotActiveException e) {
throw new OOfflineNodeException("Hazelcast instance is not available");
} catch (HazelcastException e) {
throw new OOfflineNodeException("Hazelcast instance is not available");
} catch (Exception e) {
handleDistributedException("Cannot route TX operation against distributed node", e);
}
return null;
}
use of com.hazelcast.core.HazelcastInstanceNotActiveException in project Activiti by Activiti.
the class HazelCastDistributedQueueBasedAsyncExecutor method shutdown.
@Override
public void shutdown() {
super.shutdown();
// Shut down local execution service
try {
logger.info("Shutting down local executor service");
executorService.shutdown();
executorService.awaitTermination(secondsToWaitOnShutdown, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.warn("Exception while waiting for executor service shutdown", e);
}
// Shut down hazelcast
try {
LocalQueueStats localQueueStats = jobQueue.getLocalQueueStats();
logger.info("This async job executor has processed " + localQueueStats.getPollOperationCount());
hazelcastInstance.shutdown();
} catch (HazelcastInstanceNotActiveException e) {
// Nothing to do
}
// Shut down listener thread
isActive = false;
try {
logger.info("Shutting down jobQueueListenerThread");
jobQueueListenerThread.interrupt();
jobQueueListenerThread.join();
} catch (InterruptedException e) {
logger.warn("jobQueueListenerThread join was interrupted", e);
}
}
use of com.hazelcast.core.HazelcastInstanceNotActiveException in project Activiti by Activiti.
the class HazelCastDistributedQueueBasedAsyncExecutor method initJobQueueListener.
protected void initJobQueueListener() {
jobQueueListenerThread = new Thread(new Runnable() {
public void run() {
while (isActive) {
JobEntity job = null;
try {
// Blocking
job = jobQueue.take();
} catch (InterruptedException e1) {
logger.info("jobQueueListenerThread interrupted. This is fine if the job executor is shutting down");
// Do nothing, this can happen when shutting down
} catch (HazelcastInstanceNotActiveException notActiveException) {
logger.info("Hazel cast not active exception caught. This is fine if the job executor is shutting down");
}
if (job != null) {
executorService.execute(new ExecuteAsyncRunnable(job, commandExecutor));
}
}
}
});
jobQueueListenerThread.start();
}
Aggregations