public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { AMQMessageStore store = queues.get(destination); if (store == null) { ReferenceStore checkpointStore = referenceStoreAdapter.createQueueReferenceStore(destination); store = new AMQMessageStore(this, checkpointStore, destination); try { store.start(); } catch (Exception e) { throw IOExceptionSupport.create(e); } queues.put(destination, store); } return store; }
public void afterCommit() throws Exception { if (debug) { LOG.debug("Transacted message add commit for: " + id + ", at: " + location); } lock.lock(); try { inFlightTxLocations.remove(location); } finally { lock.unlock(); } addMessage(message, location); }
public boolean iterate() { asyncWrite(); return false; } }, "Checkpoint: " + destination);
public void setBatch(MessageId messageId) { try { flush(); } catch (InterruptedIOException e) { LOG.debug("flush on setBatch resulted in exception", e); } getReferenceStore().setBatch(messageId); }
/** * @return * @throws IOException * @see org.apache.activemq.store.MessageStore#getMessageCount() */ public int getMessageCount() throws IOException { flush(); return referenceStore.getMessageCount(); }
public void add(AMQMessageStore store, MessageAck ack) { operations.add(new AMQTxOperation(AMQTxOperation.REMOVE_OPERATION_TYPE, store.getDestination(), ack, null)); }
public void afterCommit() throws Exception { if (debug) { LOG.debug("Transacted message remove commit for: " + ack.getLastMessageId() + ", at: " + location); } lock.lock(); try { inFlightTxLocations.remove(location); } finally { lock.unlock(); } removeMessage(ack, location); }
/** * @return * @throws IOException */ synchronized void asyncWrite() { try { CountDownLatch countDown; lock.lock(); try { countDown = flushLatch; flushLatch = null; } finally { lock.unlock(); } mark.set(doAsyncWrite()); if (countDown != null) { countDown.countDown(); } } catch (IOException e) { LOG.error("Checkpoint failed: " + e, e); } }
/** * */ public Message getMessage(MessageId identity) throws IOException { Location location = getLocation(identity); if (location != null) { DataStructure rc = peristenceAdapter.readCommand(location); try { return (Message) rc; } catch (ClassCastException e) { throw new IOException("Could not read message " + identity + " at location " + location + ", expected a message, but got: " + rc); } } return null; }
while (queueIterator.hasNext()) { final AMQMessageStore ms = queueIterator.next(); Location mark = ms.getMark(); if (mark != null && (newMark == null || mark.compareTo(newMark) > 0)) { newMark = mark;
/** * @see org.apache.activemq.store.MessageStore#removeAllMessages(ConnectionContext) */ public void removeAllMessages(ConnectionContext context) throws IOException { flush(); referenceStore.removeAllMessages(context); }
public void add(AMQMessageStore store, Message msg, Location location) { operations.add(new AMQTxOperation(AMQTxOperation.ADD_OPERATION_TYPE, store.getDestination(), msg, location)); }
LOG.debug("Journalled message remove for: " + ack.getLastMessageId() + ", at: " + location); removeMessage(ack, location); } else { if (debug) {
public void dispose(ConnectionContext context) { try { flush(); } catch (InterruptedIOException e) { Thread.currentThread().interrupt(); } referenceStore.dispose(context); super.dispose(context); }
addMessage(message, location); } else { if (debug) {
/** * Replays the referenceStore first as those messages are the oldest ones, then messages are replayed from the * transaction log and then the cache is updated. * * @param listener * @throws Exception */ public void recover(final MessageRecoveryListener listener) throws Exception { flush(); referenceStore.recover(new RecoveryListenerAdapter(this, listener)); }
public void stop() throws Exception { flush(); asyncWriteTask.shutdown(); referenceStore.stop(); }
final void removeMessage(final MessageAck ack, final Location location) throws InterruptedIOException { ReferenceData data; lock.lock(); try { lastLocation = location; MessageId id = ack.getLastMessageId(); data = messages.remove(id); if (data == null) { messageAcks.add(new MessageAckWithLocation(ack, location)); } else { // message never got written so datafileReference will still exist AMQMessageStore.this.peristenceAdapter.removeInProgressDataFile(AMQMessageStore.this, data.getFileId()); } } finally { lock.unlock(); } if (messageAcks.size() > this.peristenceAdapter.getMaxCheckpointMessageAddSize()) { flush(); } else if (data == null) { try { asyncWriteTask.wakeup(); } catch (InterruptedException e) { throw new InterruptedIOException(); } } }
public void recoverNextMessages(int maxReturned, MessageRecoveryListener listener) throws Exception { RecoveryListenerAdapter recoveryListener = new RecoveryListenerAdapter(this, listener); referenceStore.recoverNextMessages(maxReturned, recoveryListener); if (recoveryListener.size() == 0 && recoveryListener.hasSpace()) { flush(); referenceStore.recoverNextMessages(maxReturned, recoveryListener); } }
final void addMessage(final Message message, final Location location) throws InterruptedIOException { ReferenceData data = new ReferenceData(); data.setExpiration(message.getExpiration()); data.setFileId(location.getDataFileId()); data.setOffset(location.getOffset()); lock.lock(); try { lastLocation = location; ReferenceData prev = messages.put(message.getMessageId(), data); if (prev != null) { AMQMessageStore.this.peristenceAdapter.removeInProgressDataFile(AMQMessageStore.this, prev.getFileId()); } } finally { lock.unlock(); } if (messages.size() > this.peristenceAdapter.getMaxCheckpointMessageAddSize()) { flush(); } else { try { asyncWriteTask.wakeup(); } catch (InterruptedException e) { throw new InterruptedIOException(); } } }