Search in sources :

Example 31 with HazelcastInstanceNotActiveException

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);
    }
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastException(com.hazelcast.core.HazelcastException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException)

Example 32 with HazelcastInstanceNotActiveException

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;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCallable(com.orientechnologies.common.util.OCallable) Callable(java.util.concurrent.Callable) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) OException(com.orientechnologies.common.exception.OException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) HazelcastException(com.hazelcast.core.HazelcastException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OIOException(com.orientechnologies.common.io.OIOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException)

Example 33 with HazelcastInstanceNotActiveException

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);
    }
}
Also used : LocalQueueStats(com.hazelcast.monitor.LocalQueueStats) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException)

Example 34 with HazelcastInstanceNotActiveException

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();
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) ExecuteAsyncRunnable(org.activiti.engine.impl.asyncexecutor.ExecuteAsyncRunnable) ExecuteAsyncRunnable(org.activiti.engine.impl.asyncexecutor.ExecuteAsyncRunnable)

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