@Override public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { String key = key(convert(destination)); MessageStore store = storeCache.get(key(convert(destination))); if (store == null) { final TopicMessageStore topicStore = this.transactionStore.proxy(new KahaDBTopicMessageStore(destination)); store = storeCache.putIfAbsent(key, topicStore); if (store == null) { store = topicStore; } } return (TopicMessageStore) store; }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.topicStore.addMessage(context, message); // apply any acks we have synchronized (this.subscriptionKeys) { for (String key : this.subscriptionKeys) { this.topicStore.doAcknowledge(context, key, this.message.getMessageId(), null); } } removeTopicTask(this.topicStore, 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); removeTopicTask(this.topicStore, this.message.getMessageId()); } } }
public KahaDBTopicMessageStore(ActiveMQTopic destination) throws IOException { super(destination); this.subscriptionCount.set(getAllSubscriptions().length); if (isConcurrentStoreAndDispatchTopics()) { asyncTopicMaps.add(asyncTaskMap); } }
final String subscriptionKey = subscriptionKey(clientId, subscriptionName); @SuppressWarnings("unused") final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try {
final String subscriptionKey = subscriptionKey(clientId, subscriptionName); @SuppressWarnings("unused") final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try {
final String subscriptionKey = subscriptionKey(clientId, subscriptionName); @SuppressWarnings("unused") final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try {
public void recoverNextMessages(String clientId, String subscriptionName, final int maxReturned, final MessageRecoveryListener listener) throws Exception { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try {
@Override public void recoverSubscription(String clientId, String subscriptionName, final MessageRecoveryListener listener) throws Exception { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); @SuppressWarnings("unused") final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<Exception>() { @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); LastAck cursorPos = getLastAck(tx, sd, subscriptionKey); sd.orderIndex.setBatch(tx, cursorPos); recoverRolledBackAcks(sd, tx, Integer.MAX_VALUE, listener); for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx); iterator .hasNext();) { Entry<Long, MessageKeys> entry = iterator.next(); if (ackedAndPrepared.contains(entry.getValue().messageId)) { continue; } listener.recoverMessage(loadMessage(entry.getValue().location)); } sd.orderIndex.resetCursorPosition(); } }); } finally { indexLock.writeLock().unlock(); } }
@Override public void recoverSubscription(String clientId, String subscriptionName, final MessageRecoveryListener listener) throws Exception { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); @SuppressWarnings("unused") final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<Exception>() { @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); LastAck cursorPos = getLastAck(tx, sd, subscriptionKey); sd.orderIndex.setBatch(tx, cursorPos); recoverRolledBackAcks(sd, tx, Integer.MAX_VALUE, listener); for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx); iterator .hasNext();) { Entry<Long, MessageKeys> entry = iterator.next(); if (ackedAndPrepared.contains(entry.getValue().messageId)) { continue; } listener.recoverMessage(loadMessage(entry.getValue().location)); } sd.orderIndex.resetCursorPosition(); } }); } finally { indexLock.writeLock().unlock(); } }
@Override public void recoverSubscription(String clientId, String subscriptionName, final MessageRecoveryListener listener) throws Exception { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); @SuppressWarnings("unused") final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<Exception>() { @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); LastAck cursorPos = getLastAck(tx, sd, subscriptionKey); sd.orderIndex.setBatch(tx, cursorPos); recoverRolledBackAcks(sd, tx, Integer.MAX_VALUE, listener); for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx); iterator .hasNext();) { Entry<Long, MessageKeys> entry = iterator.next(); if (ackedAndPrepared.contains(entry.getValue().messageId)) { continue; } listener.recoverMessage(loadMessage(entry.getValue().location)); } sd.orderIndex.resetCursorPosition(); } }); } finally { indexLock.writeLock().unlock(); } }
protected void recoverMessageStoreSubMetrics() throws IOException { if (isEnableSubscriptionStatistics()) { final MessageStoreSubscriptionStatistics statistics = getMessageStoreSubStatistics(); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<String, KahaSubscriptionCommand>> iterator = sd.subscriptions .iterator(tx); iterator.hasNext();) { Entry<String, KahaSubscriptionCommand> entry = iterator.next(); String subscriptionKey = entry.getKey(); LastAck cursorPos = getLastAck(tx, sd, subscriptionKey); if (cursorPos != null) { long size = getStoredMessageSize(tx, sd, subscriptionKey); statistics.getMessageCount(subscriptionKey) .setCount(getStoredMessageCount(tx, sd, subscriptionKey)); statistics.getMessageSize(subscriptionKey).addSize(size > 0 ? size : 0); } } } }); } finally { indexLock.writeLock().unlock(); } } }
protected void recoverMessageStoreSubMetrics() throws IOException { if (isEnableSubscriptionStatistics()) { final MessageStoreSubscriptionStatistics statistics = getMessageStoreSubStatistics(); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<String, KahaSubscriptionCommand>> iterator = sd.subscriptions .iterator(tx); iterator.hasNext();) { Entry<String, KahaSubscriptionCommand> entry = iterator.next(); String subscriptionKey = entry.getKey(); LastAck cursorPos = getLastAck(tx, sd, subscriptionKey); if (cursorPos != null) { long size = getStoredMessageSize(tx, sd, subscriptionKey); statistics.getMessageCount(subscriptionKey) .setCount(getStoredMessageCount(tx, sd, subscriptionKey)); statistics.getMessageSize(subscriptionKey).addSize(size > 0 ? size : 0); } } } }); } finally { indexLock.writeLock().unlock(); } } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.topicStore.addMessage(context, message); // apply any acks we have synchronized (this.subscriptionKeys) { for (String key : this.subscriptionKeys) { this.topicStore.doAcknowledge(context, key, this.message.getMessageId(), null); } } removeTopicTask(this.topicStore, 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 acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { String subscriptionKey = subscriptionKey(clientId, subscriptionName).toString(); if (isConcurrentStoreAndDispatchTopics()) { AsyncJobKey key = new AsyncJobKey(messageId, getDestination()); StoreTopicTask task = null; synchronized (asyncTaskMap) { task = (StoreTopicTask) asyncTaskMap.get(key); } if (task != null) { if (task.addSubscriptionKey(subscriptionKey)) { removeTopicTask(this, messageId); if (task.cancel()) { synchronized (asyncTaskMap) { asyncTaskMap.remove(key); } } } } else { doAcknowledge(context, subscriptionKey, messageId, ack); } } else { doAcknowledge(context, subscriptionKey, messageId, ack); } }
protected void recoverMessageStoreSubMetrics() throws IOException { if (isEnableSubscriptionStatistics()) { final MessageStoreSubscriptionStatistics statistics = getMessageStoreSubStatistics(); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<String, KahaSubscriptionCommand>> iterator = sd.subscriptions .iterator(tx); iterator.hasNext();) { Entry<String, KahaSubscriptionCommand> entry = iterator.next(); String subscriptionKey = entry.getKey(); LastAck cursorPos = getLastAck(tx, sd, subscriptionKey); if (cursorPos != null) { long size = getStoredMessageSize(tx, sd, subscriptionKey); statistics.getMessageCount(subscriptionKey) .setCount(getStoredMessageCount(tx, sd, subscriptionKey)); statistics.getMessageSize(subscriptionKey).addSize(size > 0 ? size : 0); } } } }); } finally { indexLock.writeLock().unlock(); } } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.topicStore.addMessage(context, message); // apply any acks we have synchronized (this.subscriptionKeys) { for (String key : this.subscriptionKeys) { this.topicStore.doAcknowledge(context, key, this.message.getMessageId(), null); } } removeTopicTask(this.topicStore, 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); removeTopicTask(this.topicStore, this.message.getMessageId()); } } }
@Override public void run() { this.store.doneTasks++; try { if (this.done.compareAndSet(false, true)) { this.topicStore.addMessage(context, message); // apply any acks we have synchronized (this.subscriptionKeys) { for (String key : this.subscriptionKeys) { this.topicStore.doAcknowledge(context, key, this.message.getMessageId(), null); } } removeTopicTask(this.topicStore, 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); removeTopicTask(this.topicStore, this.message.getMessageId()); } } }
public void recoverSubscription(String clientId, String subscriptionName, final MessageRecoveryListener listener) throws Exception { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); final SubscriptionInfo info = lookupSubscription(clientId, subscriptionName); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<Exception>() { public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); LastAck cursorPos = sd.subscriptionAcks.get(tx, subscriptionKey); sd.orderIndex.setBatch(tx, cursorPos); for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx); iterator .hasNext();) { Entry<Long, MessageKeys> entry = iterator.next(); listener.recoverMessage(loadMessage(entry.getValue().location)); } sd.orderIndex.resetCursorPosition(); } }); }finally { indexLock.writeLock().unlock(); } }
@Override public void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { String subscriptionKey = subscriptionKey(clientId, subscriptionName).toString(); if (isConcurrentStoreAndDispatchTopics()) { AsyncJobKey key = new AsyncJobKey(messageId, getDestination()); StoreTopicTask task = null; synchronized (asyncTaskMap) { task = (StoreTopicTask) asyncTaskMap.get(key); } if (task != null) { if (task.addSubscriptionKey(subscriptionKey)) { removeTopicTask(this, messageId); if (task.cancel()) { synchronized (asyncTaskMap) { asyncTaskMap.remove(key); } } } } else { doAcknowledge(context, subscriptionKey, messageId, ack); } } else { doAcknowledge(context, subscriptionKey, messageId, ack); } }
public void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { String subscriptionKey = subscriptionKey(clientId, subscriptionName); if (isConcurrentStoreAndDispatchTopics()) { AsyncJobKey key = new AsyncJobKey(messageId, getDestination()); StoreTopicTask task = null; synchronized (asyncTaskMap) { task = (StoreTopicTask) asyncTaskMap.get(key); } if (task != null) { if (task.addSubscriptionKey(subscriptionKey)) { removeTopicTask(this, messageId); if (task.cancel()) { synchronized (asyncTaskMap) { asyncTaskMap.remove(key); } } } } else { doAcknowledge(context, subscriptionKey, messageId, ack); } } else { doAcknowledge(context, subscriptionKey, messageId, ack); } }