Search in sources :

Example 1 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException in project activemq-artemis by apache.

the class ServerLocatorImpl method initialise.

private synchronized void initialise() throws ActiveMQException {
    if (state == STATE.INITIALIZED)
        return;
    synchronized (stateGuard) {
        if (state == STATE.CLOSING)
            throw new ActiveMQIllegalStateException();
        try {
            state = STATE.INITIALIZED;
            latch = new CountDownLatch(1);
            setThreadPools();
            instantiateLoadBalancingPolicy();
            if (discoveryGroupConfiguration != null) {
                discoveryGroup = createDiscoveryGroup(nodeID, discoveryGroupConfiguration);
                discoveryGroup.registerListener(this);
                discoveryGroup.start();
            }
        } catch (Exception e) {
            state = null;
            throw ActiveMQClientMessageBundle.BUNDLE.failedToInitialiseSessionFactory(e);
        }
    }
}
Also used : ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ObjectStreamException(java.io.ObjectStreamException)

Example 2 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException in project activemq-artemis by apache.

the class ServerConsumerImpl method acknowledge.

@Override
public synchronized void acknowledge(Transaction tx, final long messageID) throws Exception {
    if (browseOnly) {
        return;
    }
    // Acknowledge acknowledges all refs delivered by the consumer up to and including the one explicitly
    // acknowledged
    // We use a transaction here as if the message is not found, we should rollback anything done
    // This could eventually happen on retries during transactions, and we need to make sure we don't ACK things we are not supposed to acknowledge
    boolean startedTransaction = false;
    if (tx == null) {
        startedTransaction = true;
        tx = new TransactionImpl(storageManager);
    }
    try {
        MessageReference ref;
        do {
            synchronized (lock) {
                ref = deliveringRefs.poll();
            }
            if (logger.isTraceEnabled()) {
                logger.trace("ACKing ref " + ref + " on tx= " + tx + ", consumer=" + this);
            }
            if (ref == null) {
                ActiveMQIllegalStateException ils = ActiveMQMessageBundle.BUNDLE.consumerNoReference(id, messageID, messageQueue.getName());
                tx.markAsRollbackOnly(ils);
                throw ils;
            }
            ref.acknowledge(tx);
            acks++;
        } while (ref.getMessageID() != messageID);
        if (startedTransaction) {
            tx.commit();
        }
    } catch (ActiveMQException e) {
        if (startedTransaction) {
            tx.rollback();
        } else {
            tx.markAsRollbackOnly(e);
        }
        throw e;
    } catch (Throwable e) {
        ActiveMQServerLogger.LOGGER.errorAckingMessage((Exception) e);
        ActiveMQException activeMQIllegalStateException = new ActiveMQIllegalStateException(e.getMessage());
        if (startedTransaction) {
            tx.rollback();
        } else {
            tx.markAsRollbackOnly(activeMQIllegalStateException);
        }
        throw activeMQIllegalStateException;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)

Example 3 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException in project activemq-artemis by apache.

the class SharedNothingLiveActivation method startReplication.

public void startReplication(CoreRemotingConnection rc, final ClusterConnection clusterConnection, final Pair<TransportConfiguration, TransportConfiguration> pair, final boolean isFailBackRequest) throws ActiveMQException {
    if (replicationManager != null) {
        throw new ActiveMQAlreadyReplicatingException();
    }
    if (!activeMQServer.isStarted()) {
        throw new ActiveMQIllegalStateException();
    }
    synchronized (replicationLock) {
        if (replicationManager != null) {
            throw new ActiveMQAlreadyReplicatingException();
        }
        ReplicationFailureListener listener = new ReplicationFailureListener();
        rc.addCloseListener(listener);
        rc.addFailureListener(listener);
        replicationManager = new ReplicationManager(rc, clusterConnection.getCallTimeout(), replicatedPolicy.getInitialReplicationSyncTimeout(), activeMQServer.getExecutorFactory());
        replicationManager.start();
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    activeMQServer.getStorageManager().startReplication(replicationManager, activeMQServer.getPagingManager(), activeMQServer.getNodeID().toString(), isFailBackRequest && replicatedPolicy.isAllowAutoFailBack(), replicatedPolicy.getInitialReplicationSyncTimeout());
                    clusterConnection.nodeAnnounced(System.currentTimeMillis(), activeMQServer.getNodeID().toString(), replicatedPolicy.getGroupName(), replicatedPolicy.getScaleDownGroupName(), pair, true);
                    if (isFailBackRequest && replicatedPolicy.isAllowAutoFailBack()) {
                        BackupTopologyListener listener1 = new BackupTopologyListener(activeMQServer.getNodeID().toString(), clusterConnection.getConnector());
                        clusterConnection.addClusterTopologyListener(listener1);
                        if (listener1.waitForBackup()) {
                            // if we have to many backups kept or are not configured to restart just stop, otherwise restart as a backup
                            activeMQServer.fail(true);
                            ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback();
                            // activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize());
                            activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy());
                            activeMQServer.start();
                        } else {
                            ActiveMQServerLogger.LOGGER.failbackMissedBackupAnnouncement();
                        }
                    }
                } catch (Exception e) {
                    if (activeMQServer.getState() == ActiveMQServerImpl.SERVER_STATE.STARTED) {
                        /*
                   * The reasoning here is that the exception was either caused by (1) the
                   * (interaction with) the backup, or (2) by an IO Error at the storage. If (1), we
                   * can swallow the exception and ignore the replication request. If (2) the live
                   * will crash shortly.
                   */
                        ActiveMQServerLogger.LOGGER.errorStartingReplication(e);
                    }
                    try {
                        ActiveMQServerImpl.stopComponent(replicationManager);
                    } catch (Exception amqe) {
                        ActiveMQServerLogger.LOGGER.errorStoppingReplication(amqe);
                    } finally {
                        synchronized (replicationLock) {
                            replicationManager = null;
                        }
                    }
                }
            }
        });
        t.start();
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQDisconnectedException(org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)

Example 4 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException in project activemq-artemis by apache.

the class ServerSessionImpl method findConsumer.

private ServerConsumer findConsumer(long consumerID) throws Exception {
    ServerConsumer consumer = locateConsumer(consumerID);
    if (consumer == null) {
        Transaction currentTX = tx;
        ActiveMQIllegalStateException exception = ActiveMQMessageBundle.BUNDLE.consumerDoesntExist(consumerID);
        if (currentTX != null) {
            currentTX.markAsRollbackOnly(exception);
        }
        throw exception;
    }
    return consumer;
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 5 with ActiveMQIllegalStateException

use of org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException in project activemq-artemis by apache.

the class JournalStorageManager method startReplication.

@Override
public void startReplication(ReplicationManager replicationManager, PagingManager pagingManager, String nodeID, final boolean autoFailBack, long initialReplicationSyncTimeout) throws Exception {
    if (!started) {
        throw new IllegalStateException("JournalStorageManager must be started...");
    }
    assert replicationManager != null;
    if (!(messageJournal instanceof JournalImpl) || !(bindingsJournal instanceof JournalImpl)) {
        throw ActiveMQMessageBundle.BUNDLE.notJournalImpl();
    }
    // We first do a compact without any locks, to avoid copying unnecessary data over the network.
    // We do this without holding the storageManager lock, so the journal stays open while compact is being done
    originalMessageJournal.scheduleCompactAndBlock(-1);
    originalBindingsJournal.scheduleCompactAndBlock(-1);
    JournalFile[] messageFiles = null;
    JournalFile[] bindingsFiles = null;
    // We get a picture of the current sitaution on the large messages
    // and we send the current messages while more state is coming
    Map<Long, Pair<String, Long>> pendingLargeMessages = null;
    try {
        Map<SimpleString, Collection<Integer>> pageFilesToSync;
        storageManagerLock.writeLock().lock();
        try {
            if (isReplicated())
                throw new ActiveMQIllegalStateException("already replicating");
            replicator = replicationManager;
            if (!((JournalImpl) originalMessageJournal).flushAppendExecutor(10, TimeUnit.SECONDS)) {
                throw new Exception("Live message journal is busy");
            }
            if (!((JournalImpl) originalBindingsJournal).flushAppendExecutor(10, TimeUnit.SECONDS)) {
                throw new Exception("Live bindings journal is busy");
            }
            // Establishes lock
            originalMessageJournal.synchronizationLock();
            originalBindingsJournal.synchronizationLock();
            try {
                originalBindingsJournal.replicationSyncPreserveOldFiles();
                originalMessageJournal.replicationSyncPreserveOldFiles();
                pagingManager.lock();
                try {
                    pagingManager.disableCleanup();
                    messageFiles = prepareJournalForCopy(originalMessageJournal, JournalContent.MESSAGES, nodeID, autoFailBack);
                    bindingsFiles = prepareJournalForCopy(originalBindingsJournal, JournalContent.BINDINGS, nodeID, autoFailBack);
                    pageFilesToSync = getPageInformationForSync(pagingManager);
                    pendingLargeMessages = recoverPendingLargeMessages();
                } finally {
                    pagingManager.unlock();
                }
            } finally {
                originalMessageJournal.synchronizationUnlock();
                originalBindingsJournal.synchronizationUnlock();
            }
            bindingsJournal = new ReplicatedJournal(((byte) 0), originalBindingsJournal, replicator);
            messageJournal = new ReplicatedJournal((byte) 1, originalMessageJournal, replicator);
            // We need to send the list while locking otherwise part of the body might get sent too soon
            // it will send a list of IDs that we are allocating
            replicator.sendLargeMessageIdListMessage(pendingLargeMessages);
        } finally {
            storageManagerLock.writeLock().unlock();
        }
        sendJournalFile(messageFiles, JournalContent.MESSAGES);
        sendJournalFile(bindingsFiles, JournalContent.BINDINGS);
        sendLargeMessageFiles(pendingLargeMessages);
        sendPagesToBackup(pageFilesToSync, pagingManager);
        storageManagerLock.writeLock().lock();
        try {
            if (replicator != null) {
                replicator.sendSynchronizationDone(nodeID, initialReplicationSyncTimeout);
                performCachedLargeMessageDeletes();
            }
        } finally {
            storageManagerLock.writeLock().unlock();
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.unableToStartReplication(e);
        stopReplication();
        throw e;
    } finally {
        // Re-enable compact and reclaim of journal files
        originalBindingsJournal.replicationSyncFinished();
        originalMessageJournal.replicationSyncFinished();
        pagingManager.resumeCleanup();
    }
}
Also used : ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) Collection(java.util.Collection) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)2 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 MessageHandler (org.apache.activemq.artemis.api.core.client.MessageHandler)2 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)2 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)2 Test (org.junit.Test)2 ObjectStreamException (java.io.ObjectStreamException)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1