Search in sources :

Example 1 with OperationContext

use of org.apache.activemq.artemis.core.persistence.OperationContext in project activemq-artemis by apache.

the class JournalStorageManager method stop.

@Override
public synchronized void stop(boolean ioCriticalError, boolean sendFailover) throws Exception {
    if (!started) {
        return;
    }
    if (!ioCriticalError) {
        performCachedLargeMessageDeletes();
        // Must call close to make sure last id is persisted
        if (journalLoaded && idGenerator != null)
            idGenerator.persistCurrentID();
    }
    final CountDownLatch latch = new CountDownLatch(1);
    try {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                latch.countDown();
            }
        });
        latch.await(30, TimeUnit.SECONDS);
    } catch (RejectedExecutionException ignored) {
    // that's ok
    }
    // We cache the variable as the replicator could be changed between here and the time we call stop
    // since sendLiveIsStopping may issue a close back from the channel
    // and we want to ensure a stop here just in case
    ReplicationManager replicatorInUse = replicator;
    if (replicatorInUse != null) {
        if (sendFailover) {
            final OperationContext token = replicator.sendLiveIsStopping(ReplicationLiveIsStoppingMessage.LiveStopping.FAIL_OVER);
            if (token != null) {
                try {
                    token.waitCompletion(5000);
                } catch (Exception e) {
                // ignore it
                }
            }
        }
        replicatorInUse.stop();
    }
    bindingsJournal.stop();
    messageJournal.stop();
    journalLoaded = false;
    started = false;
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) 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)

Example 2 with OperationContext

use of org.apache.activemq.artemis.core.persistence.OperationContext in project activemq-artemis by apache.

the class OperationContextImpl method getContext.

public static OperationContext getContext(final ExecutorFactory executorFactory) {
    OperationContext token = OperationContextImpl.threadLocalContext.get();
    if (token == null) {
        if (executorFactory == null) {
            return null;
        } else {
            token = new OperationContextImpl(executorFactory.getExecutor());
            OperationContextImpl.threadLocalContext.set(token);
        }
    }
    return token;
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext)

Example 3 with OperationContext

use of org.apache.activemq.artemis.core.persistence.OperationContext in project activemq-artemis by apache.

the class PageSyncTimer method tick.

private void tick() {
    OperationContext[] pendingSyncsArray;
    synchronized (this) {
        pendingSync = false;
        pendingSyncsArray = new OperationContext[syncOperations.size()];
        pendingSyncsArray = syncOperations.toArray(pendingSyncsArray);
        syncOperations.clear();
    }
    try {
        if (pendingSyncsArray.length != 0) {
            store.ioSync();
        }
    } catch (Exception e) {
        for (OperationContext ctx : pendingSyncsArray) {
            ctx.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getMessage());
        }
    } finally {
        // to avoid possible locks and the client not getting the exception back
        for (OperationContext ctx : pendingSyncsArray) {
            ctx.pageSyncDone();
        }
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext)

Example 4 with OperationContext

use of org.apache.activemq.artemis.core.persistence.OperationContext in project activemq-artemis by apache.

the class ReplicationManager method replicated.

/**
 * @throws IllegalStateException By default, all replicated packets generate a replicated
 *                               response. If your packets are triggering this exception, it may be because the
 *                               packets were not sent with {@link #sendReplicatePacket(Packet)}.
 */
private void replicated() {
    OperationContext ctx = pendingTokens.poll();
    if (ctx == null) {
        ActiveMQServerLogger.LOGGER.missingReplicationTokenOnQueue();
        return;
    }
    ctx.replicationDone();
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext)

Example 5 with OperationContext

use of org.apache.activemq.artemis.core.persistence.OperationContext in project activemq-artemis by apache.

the class ReplicationManager method sendReplicatePacket.

private OperationContext sendReplicatePacket(final Packet packet, boolean lineUp) {
    if (!enabled) {
        packet.release();
        return null;
    }
    final OperationContext repliToken = OperationContextImpl.getContext(executorFactory);
    if (lineUp) {
        repliToken.replicationLineUp();
    }
    replicationStream.execute(() -> {
        if (enabled) {
            pendingTokens.add(repliToken);
            flowControl(packet.expectedEncodeSize());
            replicatingChannel.send(packet);
        } else {
            packet.release();
            repliToken.replicationDone();
        }
    });
    return repliToken;
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext)

Aggregations

OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)18 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)7 CountDownLatch (java.util.concurrent.CountDownLatch)5 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)5 ArrayList (java.util.ArrayList)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)4 Test (org.junit.Test)4 Configuration (org.apache.activemq.artemis.core.config.Configuration)3 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)3 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)3 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)3 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)3 PagingManager (org.apache.activemq.artemis.core.paging.PagingManager)3 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)3 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)2 ReplicationManager (org.apache.activemq.artemis.core.replication.ReplicationManager)2 ActiveMQServerPlugin (org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin)2 ActiveMQAMQPResourceLimitExceededException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException)2