@Override public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { String key = key(convert(destination)); MessageStore store = storeCache.get(key(convert(destination))); if (store == null) { final MessageStore queueStore = this.transactionStore.proxy(new KahaDBMessageStore(destination)); store = storeCache.putIfAbsent(key, queueStore); if (store == null) { store = queueStore; } } return store; }
@Override public void aquireLocks() { if (this.locked.compareAndSet(false, true)) { try { globalTopicSemaphore.acquire(); store.acquireLocalAsyncLock(); message.incrementReferenceCount(); } catch (InterruptedException e) { LOG.warn("Failed to aquire lock", e); } } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.store.addMessage(context, message); removeQueueTask(this.store, this.message.getMessageId()); this.future.complete(); } else if (cancelledTaskModMetric > 0 && (++this.store.canceledTasks) % cancelledTaskModMetric == 0) { System.err.println(this.store.dest.getName() + " cancelled: " + (this.store.canceledTasks / this.store.doneTasks) * 100); this.store.canceledTasks = this.store.doneTasks = 0; } } catch (Throwable t) { this.future.setException(t); removeQueueTask(this.store, this.message.getMessageId()); } }
@Override public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException { if (isConcurrentStoreAndDispatchQueues()) { AsyncJobKey key = new AsyncJobKey(ack.getLastMessageId(), getDestination()); StoreQueueTask task = null; synchronized (asyncTaskMap) { LOG.debug("removeAsync: cannot cancel, waiting for add resulted in ex", ignored); removeMessage(context, ack); } else { indexLock.writeLock().lock(); removeMessage(context, ack); removeMessage(context, ack);
@Override public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException { if (isConcurrentStoreAndDispatchQueues()) { AsyncJobKey key = new AsyncJobKey(ack.getLastMessageId(), getDestination()); StoreQueueTask task = null; synchronized (asyncTaskMap) { LOG.debug("removeAsync: cannot cancel, waiting for add resulted in ex", ignored); removeMessage(context, ack); } else { indexLock.writeLock().lock(); removeMessage(context, ack); removeMessage(context, ack);
@Override public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException { if (isConcurrentStoreAndDispatchQueues()) { AsyncJobKey key = new AsyncJobKey(ack.getLastMessageId(), getDestination()); StoreQueueTask task = null; synchronized (asyncTaskMap) { LOG.debug("removeAsync: cannot cancel, waiting for add resulted in ex", ignored); removeMessage(context, ack); } else { indexLock.writeLock().lock(); removeMessage(context, ack); removeMessage(context, ack);
@Override public void addMessage(final ConnectionContext context, final Message message) throws IOException { final KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); command.setTransactionInfo(TransactionIdConversion.convert(transactionIdTransformer.transform(message.getTransactionId()))); command.setPriority(message.getPriority()); command.setPrioritySupported(isPrioritizedMessages()); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(message); command.setMessage(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); store(command, isEnableJournalDiskSyncs() && message.isResponseRequired(), new IndexAware() { // sync add? (for async, future present from getFutureOrSequenceLong) Object possibleFuture = message.getMessageId().getFutureOrSequenceLong(); @Override public void sequenceAssignedWithIndexLocked(final long sequence) { message.getMessageId().setFutureOrSequenceLong(sequence); if (indexListener != null) { if (possibleFuture == null) { trackPendingAdd(dest, sequence); indexListener.onAdd(new IndexListener.MessageContext(context, message, new Runnable() { @Override public void run() { trackPendingAddComplete(dest, sequence); } })); } } } }, null); }
try { MessageStoreStatistics recoveredStatistics; lockAsyncJobQueue(); indexLock.writeLock().lock(); try { getMessageStoreStatistics().getMessageCount().setCount(recoveredStatistics.getMessageCount().getCount()); getMessageStoreStatistics().getMessageSize().setTotalSize(recoveredStatistics.getMessageSize().getTotalSize()); } finally { indexLock.writeLock().unlock(); unlockAsyncJobQueue();
@Override public void addMessage(final ConnectionContext context, final Message message) throws IOException { final KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); command.setTransactionInfo(TransactionIdConversion.convert(transactionIdTransformer.transform(message.getTransactionId()))); command.setPriority(message.getPriority()); command.setPrioritySupported(isPrioritizedMessages()); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(message); command.setMessage(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); store(command, isEnableJournalDiskSyncs() && message.isResponseRequired(), new IndexAware() { // sync add? (for async, future present from getFutureOrSequenceLong) Object possibleFuture = message.getMessageId().getFutureOrSequenceLong(); @Override public void sequenceAssignedWithIndexLocked(final long sequence) { message.getMessageId().setFutureOrSequenceLong(sequence); if (indexListener != null) { if (possibleFuture == null) { trackPendingAdd(dest, sequence); indexListener.onAdd(new IndexListener.MessageContext(context, message, new Runnable() { @Override public void run() { trackPendingAddComplete(dest, sequence); } })); } } } }, null); }
@Override public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException { if (isConcurrentStoreAndDispatchQueues()) { AsyncJobKey key = new AsyncJobKey(ack.getLastMessageId(), getDestination()); StoreQueueTask task = null; synchronized (asyncTaskMap) { task = (StoreQueueTask) asyncTaskMap.get(key); } if (task != null) { if (!task.cancel()) { try { task.future.get(); } catch (InterruptedException e) { throw new InterruptedIOException(e.toString()); } catch (Exception ignored) { LOG.debug("removeAsync: cannot cancel, waiting for add resulted in ex", ignored); } removeMessage(context, ack); } else { synchronized (asyncTaskMap) { asyncTaskMap.remove(key); } } } else { removeMessage(context, ack); } } else { removeMessage(context, ack); } }
public int getMessageCount() throws IOException { try { lockAsyncJobQueue(); indexLock.readLock().lock(); try { return pageFile.tx().execute(new Transaction.CallableClosure<Integer, IOException>() { public Integer execute(Transaction tx) throws IOException { // Iterate through all index entries to get a count // of // messages in the destination. StoredDestination sd = getStoredDestination(dest, tx); int rc = 0; for (Iterator<Entry<Location, Long>> iterator = sd.locationIndex.iterator(tx); iterator .hasNext();) { iterator.next(); rc++; } return rc; } }); }finally { indexLock.readLock().unlock(); } } finally { unlockAsyncJobQueue(); } }
try { MessageStoreStatistics recoveredStatistics; lockAsyncJobQueue(); indexLock.writeLock().lock(); try { getMessageStoreStatistics().getMessageCount().setCount(recoveredStatistics.getMessageCount().getCount()); getMessageStoreStatistics().getMessageSize().setTotalSize(recoveredStatistics.getMessageSize().getTotalSize()); } finally { indexLock.writeLock().unlock(); unlockAsyncJobQueue();
@Override public void addMessage(final ConnectionContext context, final Message message) throws IOException { final KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); command.setTransactionInfo(TransactionIdConversion.convert(transactionIdTransformer.transform(message.getTransactionId()))); command.setPriority(message.getPriority()); command.setPrioritySupported(isPrioritizedMessages()); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(message); command.setMessage(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); store(command, isEnableJournalDiskSyncs() && message.isResponseRequired(), new IndexAware() { // sync add? (for async, future present from getFutureOrSequenceLong) Object possibleFuture = message.getMessageId().getFutureOrSequenceLong(); @Override public void sequenceAssignedWithIndexLocked(final long sequence) { message.getMessageId().setFutureOrSequenceLong(sequence); if (indexListener != null) { if (possibleFuture == null) { trackPendingAdd(dest, sequence); indexListener.onAdd(new IndexListener.MessageContext(context, message, new Runnable() { @Override public void run() { trackPendingAddComplete(dest, sequence); } })); } } } }, null); }
try { MessageStoreStatistics recoveredStatistics; lockAsyncJobQueue(); indexLock.writeLock().lock(); try { getMessageStoreStatistics().getMessageCount().setCount(recoveredStatistics.getMessageCount().getCount()); getMessageStoreStatistics().getMessageSize().setTotalSize(recoveredStatistics.getMessageSize().getTotalSize()); } finally { indexLock.writeLock().unlock(); unlockAsyncJobQueue();
@Override public void setBatch(MessageId identity) throws IOException { try { final String key = identity.toString(); lockAsyncJobQueue(); // Hopefully one day the page file supports concurrent read // operations... but for now we must // externally synchronize... indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); Long location = sd.messageIdIndex.get(tx, key); if (location != null) { sd.orderIndex.setBatch(tx, location); } } }); }finally { indexLock.writeLock().unlock(); } } finally { unlockAsyncJobQueue(); } }
public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.store.addMessage(context, message); removeQueueTask(this.store, this.message.getMessageId()); this.future.complete(); } else if (cancelledTaskModMetric > 0 && this.store.canceledTasks++ % cancelledTaskModMetric == 0) { System.err.println(this.store.dest.getName() + " cancelled: " + (this.store.canceledTasks / this.store.doneTasks) * 100); this.store.canceledTasks = this.store.doneTasks = 0; } } catch (Exception e) { this.future.setException(e); } finally { releaseLocks(); } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.store.addMessage(context, message); removeQueueTask(this.store, this.message.getMessageId()); this.future.complete(); } else if (cancelledTaskModMetric > 0 && (++this.store.canceledTasks) % cancelledTaskModMetric == 0) { System.err.println(this.store.dest.getName() + " cancelled: " + (this.store.canceledTasks / this.store.doneTasks) * 100); this.store.canceledTasks = this.store.doneTasks = 0; } } catch (Throwable t) { this.future.setException(t); removeQueueTask(this.store, this.message.getMessageId()); } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.store.addMessage(context, message); removeQueueTask(this.store, this.message.getMessageId()); this.future.complete(); } else if (cancelledTaskModMetric > 0 && (++this.store.canceledTasks) % cancelledTaskModMetric == 0) { System.err.println(this.store.dest.getName() + " cancelled: " + (this.store.canceledTasks / this.store.doneTasks) * 100); this.store.canceledTasks = this.store.doneTasks = 0; } } catch (Throwable t) { this.future.setException(t); removeQueueTask(this.store, this.message.getMessageId()); } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.store.addMessage(context, message); removeQueueTask(this.store, this.message.getMessageId()); this.future.complete(); } else if (cancelledTaskModMetric > 0 && (++this.store.canceledTasks) % cancelledTaskModMetric == 0) { System.err.println(this.store.dest.getName() + " cancelled: " + (this.store.canceledTasks / this.store.doneTasks) * 100); this.store.canceledTasks = this.store.doneTasks = 0; } } catch (Throwable t) { this.future.setException(t); removeQueueTask(this.store, this.message.getMessageId()); } }
public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { return this.transactionStore.proxy(new KahaDBMessageStore(destination)); }