OperationContext getContext(final boolean sync) { if (sync) { return getContext(); } else { return DummyOperationContext.getInstance(); } }
@Override public void afterCompleteOperations(final IOCallback run) { getContext().executeOnCompletion(run); }
@Override public void afterStoreOperations(IOCallback run) { getContext().executeOnCompletion(run, true); }
@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 deleteDuplicateID(final long recordID) throws Exception { readLock(); try { messageJournal.appendDeleteRecord(recordID, syncNonTransactional, getContext(syncNonTransactional)); } finally { readUnLock(); } }
@Override public void deleteHeuristicCompletion(final long id) throws Exception { readLock(); try { messageJournal.appendDeleteRecord(id, true, getContext(true)); } finally { readUnLock(); } }
@Override public void lineUpContext() { readLock(); try { messageJournal.lineUpContext(getContext()); } finally { readUnLock(); } }
/** * We don't need messageID now but we are likely to need it we ever decide to support a database */ @Override public void confirmPendingLargeMessage(long recordID) throws Exception { readLock(); try { messageJournal.appendDeleteRecord(recordID, true, getContext()); } finally { readUnLock(); } }
@Override public void rollback(final long txID) throws Exception { readLock(); try { messageJournal.appendRollbackRecord(txID, syncTransactional, getContext(syncTransactional)); } finally { readUnLock(); } }
@Override public void deleteMessage(final long messageID) throws Exception { readLock(); try { // Messages are deleted on postACK, one after another. // If these deletes are synchronized, we would build up messages on the Executor // increasing chances of losing deletes. // The StorageManager should verify messages without references messageJournal.appendDeleteRecord(messageID, false, getContext(false)); } finally { readUnLock(); } }
@Override public void storeDuplicateID(final SimpleString address, final byte[] duplID, final long recordID) throws Exception { readLock(); try { DuplicateIDEncoding encoding = new DuplicateIDEncoding(address, duplID); messageJournal.appendAddRecord(recordID, JournalRecordIds.DUPLICATE_ID, encoding, syncNonTransactional, getContext(syncNonTransactional)); } finally { readUnLock(); } }
@Override public void prepare(final long txID, final Xid xid) throws Exception { readLock(); try { messageJournal.appendPrepareRecord(txID, new XidEncoding(xid), syncTransactional, getContext(syncTransactional)); } finally { readUnLock(); } }
@Override public void storeAcknowledge(final long queueID, final long messageID) throws Exception { readLock(); try { messageJournal.appendUpdateRecord(messageID, JournalRecordIds.ACKNOWLEDGE_REF, new RefEncoding(queueID), syncNonTransactional, getContext(syncNonTransactional)); } finally { readUnLock(); } }
@Override public void storeReference(final long queueID, final long messageID, final boolean last) throws Exception { readLock(); try { messageJournal.appendUpdateRecord(messageID, JournalRecordIds.ADD_REF, new RefEncoding(queueID), last && syncNonTransactional, getContext(last && syncNonTransactional)); } finally { readUnLock(); } }
@Override public long storePageCounterInc(long queueID, int value, long persistentSize) throws Exception { readLock(); try { final long recordID = idGenerator.generateID(); messageJournal.appendAddRecord(recordID, JournalRecordIds.PAGE_CURSOR_COUNTER_INC, new PageCountRecordInc(queueID, value, persistentSize), true, getContext()); return recordID; } finally { readUnLock(); } }
@Override public long storeHeuristicCompletion(final Xid xid, final boolean isCommit) throws Exception { readLock(); try { long id = generateID(); messageJournal.appendAddRecord(id, JournalRecordIds.HEURISTIC_COMPLETION, new HeuristicCompletionEncoding(xid, isCommit), true, getContext(true)); return id; } finally { readUnLock(); } }
@Override public void storeCursorAcknowledge(long queueID, PagePosition position) throws Exception { readLock(); try { long ackID = idGenerator.generateID(); position.setRecordID(ackID); messageJournal.appendAddRecord(ackID, JournalRecordIds.ACKNOWLEDGE_CURSOR, new CursorAckRecordEncoding(queueID, position), syncNonTransactional, getContext(syncNonTransactional)); } finally { readUnLock(); } }
@Override public void storeMessage(final Message message) throws Exception { if (message.getMessageID() <= 0) { // Sanity check only... this shouldn't happen unless there is a bug throw ActiveMQMessageBundle.BUNDLE.messageIdNotAssigned(); } readLock(); try { // Note that we don't sync, the add reference that comes immediately after will sync if // appropriate if (message.isLargeMessage()) { messageJournal.appendAddRecord(message.getMessageID(), JournalRecordIds.ADD_LARGE_MESSAGE, LargeMessagePersister.getInstance(), message, false, getContext(false)); } else { messageJournal.appendAddRecord(message.getMessageID(), JournalRecordIds.ADD_MESSAGE_PROTOCOL, message.getPersister(), message, false, getContext(false)); } } finally { readUnLock(); } }
@Override public void updateScheduledDeliveryTime(final MessageReference ref) throws Exception { ScheduledDeliveryEncoding encoding = new ScheduledDeliveryEncoding(ref.getScheduledDeliveryTime(), ref.getQueue().getID()); readLock(); try { messageJournal.appendUpdateRecord(ref.getMessage().getMessageID(), JournalRecordIds.SET_SCHEDULED_DELIVERY_TIME, encoding, syncNonTransactional, getContext(syncNonTransactional)); } finally { readUnLock(); } }
@Override public void updateDeliveryCount(final MessageReference ref) throws Exception { // no need to store if it's the same value // otherwise the journal will get OME in case of lots of redeliveries if (ref.getDeliveryCount() == ref.getPersistedCount()) { return; } ref.setPersistedCount(ref.getDeliveryCount()); DeliveryCountUpdateEncoding updateInfo = new DeliveryCountUpdateEncoding(ref.getQueue().getID(), ref.getDeliveryCount()); readLock(); try { messageJournal.appendUpdateRecord(ref.getMessage().getMessageID(), JournalRecordIds.UPDATE_DELIVERY_COUNT, updateInfo, syncNonTransactional, getContext(syncNonTransactional)); } finally { readUnLock(); } }