@Override public void recheckRefCount(OperationContext context) { ReferenceCounter refCount = refCountForConsumers; if (refCount != null) { context.executeOnCompletion(new IOCallback() { @Override public void done() { refCount.check(); } @Override public void onError(int errorCode, String errorMessage) { } }); } }
synchronized void addSync(OperationContext ctx) { ctx.pageSyncLineUp(); if (!pendingSync) { pendingSync = true; delay(); } syncOperations.add(ctx); }
/** * @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(); }
OperationContext ctx = OperationContextImpl.getContext(factory); ctx.storeLineUp(); ctx.onError(ActiveMQExceptionType.UNBLOCKED.getCode(), msg); ctx.executeOnCompletion(new IOCallback() { @Override public void onError(final int errorCode, final String errorMessage) { ctx.executeOnCompletion(new IOCallback() { @Override public void onError(final int errorCode, final String errorMessage) { ctx.executeOnCompletion(new IOCallback() { @Override public void onError(final int errorCode, final String errorMessage) {
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 { // In case of failure, The context should propagate an exception to the client // We send an exception to the client even on the case of a failure // to avoid possible locks and the client not getting the exception back for (OperationContext ctx : pendingSyncsArray) { ctx.pageSyncDone(); } } } }
private OperationContext sendReplicatePacket(final Packet packet, boolean lineUp) { if (!enabled) { packet.release(); return null; } final OperationContext repliToken = OperationContextImpl.getContext(ioExecutorFactory); if (lineUp) { repliToken.replicationLineUp(); } replicationStream.execute(() -> { if (enabled) { pendingTokens.add(repliToken); flowControl(packet.expectedEncodeSize()); replicatingChannel.send(packet); } else { packet.release(); repliToken.replicationDone(); } }); return repliToken; }
@Override public final boolean waitOnOperations(final long timeout) throws Exception { if (!started) { ActiveMQServerLogger.LOGGER.serverIsStopped(); throw new IllegalStateException("Server is stopped"); } return getContext().waitCompletion(timeout); }
@Override public void lineUpContext(IOCompletion callback) { ((OperationContext) callback).replicationLineUp(); localJournal.lineUpContext(callback); }
@Override public void commit(final long txID, final boolean lineUpContext) throws Exception { readLock(); try { messageJournal.appendCommitRecord(txID, syncTransactional, getContext(syncTransactional), lineUpContext); if (!lineUpContext && !syncTransactional) { if (logger.isTraceEnabled()) { logger.trace("calling getContext(true).done() for txID=" + txID + ",lineupContext=" + lineUpContext + " syncTransactional=" + syncTransactional + "... forcing call on getContext(true).done"); } /** * If {@code lineUpContext == false}, it means that we have previously lined up a * context somewhere else (specifically see @{link TransactionImpl#asyncAppendCommit}), * hence we need to mark it as done even if {@code syncTransactional = false} as in this * case {@code getContext(syncTransactional=false)} would pass a dummy context to the * {@code messageJournal.appendCommitRecord(...)} call above. */ getContext(true).done(); } } finally { readUnLock(); } }
if (token != null) { try { token.waitCompletion(5000); } catch (Exception e) {
@Override public void close(final boolean failed) { if (closed) return; context.executeOnCompletion(new IOCallback() { @Override public void onError(int errorCode, String errorMessage) { } @Override public void done() { try { doClose(failed); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorClosingSession(e); } } }); }
/** * Completes any pending operations. * <p> * This can be necessary in case the live loses connection to the backup (network failure, or * backup crashing). */ public void clearReplicationTokens() { logger.trace("clearReplicationTokens initiating"); while (!pendingTokens.isEmpty()) { OperationContext ctx = pendingTokens.poll(); logger.trace("Calling ctx.replicationDone()"); try { ctx.replicationDone(); } catch (Throwable e) { ActiveMQServerLogger.LOGGER.errorCompletingCallbackOnReplicationManager(e); } } logger.trace("clearReplicationTokens finished"); }
/** It will send the response through the operation context, as soon as everything is confirmed on disk */ private void sendAsyncResponse(final int commandId, final Response response) throws Exception { if (response != null) { operationContext.executeOnCompletion(new IOCallback() { @Override public void done() { if (!protocolManager.isStopping()) { try { response.setCorrelationId(commandId); dispatchSync(response); } catch (Exception e) { sendException(e); } } } @Override public void onError(int errorCode, String errorMessage) { sendException(new IOException(errorCode + "-" + errorMessage)); } }); } }
@Override public void afterStoreOperations(IOCallback run) { getContext().executeOnCompletion(run, true); }
@Override public void afterCompleteOperations(final IOCallback run) { getContext().executeOnCompletion(run); }
ctx.executeOnCompletion(new IOCallback() {
OperationContextImpl.getContext().executeOnCompletion(new IOCallback() { @Override public void done() {