public KahaDBStore() { this.transactionStore = new KahaDBTransactionStore(this); this.transactionIdTransformer = new TransactionIdTransformer() { @Override public TransactionId transform(TransactionId txid) { return txid; } }; }
@Override public void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { KahaDBTransactionStore.this.acknowledge(context, (TopicMessageStore)getDelegate(), clientId, subscriptionName, messageId, ack); }
@Override public void addMessage(ConnectionContext context, final Message send, boolean canOptimize) throws IOException { KahaDBTransactionStore.this.addMessage(context, getDelegate(), send); }
/** * @throws IOException * @see org.apache.activemq.store.TransactionStore#rollback(TransactionId) */ @Override public void rollback(TransactionId txid) throws IOException { if (txid.isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions() == false) { KahaTransactionInfo info = getTransactionInfo(txid); theStore.store(new KahaRollbackCommand().setTransactionInfo(info), theStore.isEnableJournalDiskSyncs(), null, null); forgetRecoveredAcks(txid, true); } else { inflightTransactions.remove(txid); } }
ListenableFuture<Object> asyncAddQueueMessage(ConnectionContext context, final MessageStore destination, final Message message) throws IOException { if (message.getTransactionId() != null) { if (message.getTransactionId().isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions() == false) { destination.addMessage(context, message); return AbstractMessageStore.FUTURE; } else { Tx tx = getTx(message.getTransactionId()); tx.add(new AddMessageCommand(context) { @Override public Message getMessage() { return message; } @Override public Future<Object> run(ConnectionContext ctx) throws IOException { return destination.asyncAddQueueMessage(ctx, message); } }); return AbstractMessageStore.FUTURE; } } else { return destination.asyncAddQueueMessage(context, message); } }
@Override public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException { KahaDBTransactionStore.this.removeAsyncMessage(context, getDelegate(), ack); } };
@Override public void removeMessage(ConnectionContext context, final MessageAck ack) throws IOException { KahaDBTransactionStore.this.removeMessage(context, getDelegate(), ack); }
@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 ListenableFuture<Object> asyncAddTopicMessage(ConnectionContext context, Message message, boolean canOptimize) throws IOException { return KahaDBTransactionStore.this.asyncAddTopicMessage(context, getDelegate(), message); }
@Override public ListenableFuture<Object> asyncAddQueueMessage(ConnectionContext context, Message message) throws IOException { return KahaDBTransactionStore.this.asyncAddQueueMessage(context, getDelegate(), message); }
/** * @throws IOException * @see org.apache.activemq.store.TransactionStore#prepare(TransactionId) */ @Override public void prepare(TransactionId txid) throws IOException { KahaTransactionInfo info = getTransactionInfo(txid); if (txid.isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions() == false) { theStore.store(new KahaPrepareCommand().setTransactionInfo(info), true, null, null); } else { Tx tx = inflightTransactions.remove(txid); if (tx != null) { theStore.store(new KahaPrepareCommand().setTransactionInfo(info), true, null, null); } } }
KahaTransactionInfo info = getTransactionInfo(txid); theStore.store(new KahaCommitCommand().setTransactionInfo(info), theStore.isEnableJournalDiskSyncs(), null, null); KahaTransactionInfo info = getTransactionInfo(txid); if (preCommit != null) { preCommit.run(); forgetRecoveredAcks(txid, false);
final void acknowledge(ConnectionContext context, final TopicMessageStore destination, final String clientId, final String subscriptionName, final MessageId messageId, final MessageAck ack) throws IOException { if (ack.isInTransaction()) { if (ack.getTransactionId().isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions()== false) { destination.acknowledge(context, clientId, subscriptionName, messageId, ack); } else { Tx tx = getTx(ack.getTransactionId()); tx.add(new RemoveMessageCommand(context) { @Override public MessageAck getMessageAck() { return ack; } @Override public Future<Object> run(ConnectionContext ctx) throws IOException { destination.acknowledge(ctx, clientId, subscriptionName, messageId, ack); return AbstractMessageStore.FUTURE; } }); } } else { destination.acknowledge(context, clientId, subscriptionName, messageId, ack); } }
@Override public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException { KahaDBTransactionStore.this.removeAsyncMessage(context, getDelegate(), ack); }
@Override public void removeMessage(ConnectionContext context, final MessageAck ack) throws IOException { KahaDBTransactionStore.this.removeMessage(context, getDelegate(), ack); }
@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 ListenableFuture<Object> asyncAddTopicMessage(ConnectionContext context, Message message) throws IOException { return KahaDBTransactionStore.this.asyncAddTopicMessage(context, getDelegate(), message); }
@Override public ListenableFuture<Object> asyncAddQueueMessage(ConnectionContext context, Message message, boolean canOptimize) throws IOException { return KahaDBTransactionStore.this.asyncAddQueueMessage(context, getDelegate(), message); }
/** * @throws IOException * @see org.apache.activemq.store.TransactionStore#prepare(TransactionId) */ public void prepare(TransactionId txid) throws IOException { inflightTransactions.remove(txid); KahaTransactionInfo info = getTransactionInfo(txid); theStore.store(new KahaPrepareCommand().setTransactionInfo(info), true, null, null); }
/** * @throws IOException * @see org.apache.activemq.store.TransactionStore#rollback(TransactionId) */ @Override public void rollback(TransactionId txid) throws IOException { if (txid.isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions() == false) { KahaTransactionInfo info = getTransactionInfo(txid); theStore.store(new KahaRollbackCommand().setTransactionInfo(info), theStore.isEnableJournalDiskSyncs(), null, null); forgetRecoveredAcks(txid, true); } else { inflightTransactions.remove(txid); } }