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;
}
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;
}
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();
}
}
}
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();
}
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;
}
Aggregations