public KahaDBMessageStore(ActiveMQDestination destination) { super(destination); this.dest = convert( destination ); }
@Override public void deleteSubscription(String clientId, String subscriptionName) throws IOException { KahaSubscriptionCommand command = new KahaSubscriptionCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey(clientId, subscriptionName)); process(command); }
@Override public void addMessage(ConnectionContext context, Message message) throws IOException { KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); processAdd(command, message.getTransactionId(), wireFormat.marshal(message)); }
@Override public void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey(clientId, subscriptionName)); command.setMessageId(messageId.toProducerKey()); // We are not passed a transaction info.. so we can't participate in a transaction. // Looks like a design issue with the TopicMessageStore interface. Also we can't recover the original ack // to pass back to the XA recover method. // command.setTransactionInfo(); processRemove(command, null); }
@Override public void resetBatching(String clientId, String subscriptionName) { try { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<IOException>(){ @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); sd.subscriptionCursors.remove(subscriptionKey); } }); } } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public void commit(TransactionId txid, boolean wasPrepared, Runnable preCommit,Runnable postCommit) throws IOException { if (preCommit != null) { preCommit.run(); } processCommit(txid); if (postCommit != null) { postCommit.run(); } } @Override
@Override public void rollback(TransactionId txid) throws IOException { processRollback(txid); } @Override
@Override public void removeAllMessages(ConnectionContext context) throws IOException { KahaRemoveDestinationCommand command = new KahaRemoveDestinationCommand(); command.setDestination(dest); process(command); }
@Override public void prepare(TransactionId txid) throws IOException { processPrepare(txid); } @Override
@Override public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setMessageId(ack.getLastMessageId().toProducerKey()); processRemove(command, ack.getTransactionId()); }
@Override public SubscriptionInfo lookupSubscription(String clientId, String subscriptionName) throws IOException { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); synchronized(indexMutex) { return pageFile.tx().execute(new Transaction.CallableClosure<SubscriptionInfo, IOException>(){ @Override public SubscriptionInfo execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); KahaSubscriptionCommand command = sd.subscriptions.get(tx, subscriptionKey); if( command ==null ) { return null; } return (SubscriptionInfo)wireFormat.unmarshal( new DataInputStream(command.getSubscriptionInfo().newInput()) ); } }); } }
public void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey(clientId, subscriptionName)); command.setMessageId(messageId.toString()); // We are not passed a transaction info.. so we can't participate in a transaction. // Looks like a design issue with the TopicMessageStore interface. Also we can't recover the original ack // to pass back to the XA recover method. // command.setTransactionInfo(); processRemove(command, null); }
@Override public void commit(TransactionId txid, boolean wasPrepared, Runnable preCommit,Runnable postCommit) throws IOException { if (preCommit != null) { preCommit.run(); } processCommit(txid); if (postCommit != null) { postCommit.run(); } } @Override
@Override public void rollback(TransactionId txid) throws IOException { processRollback(txid); } @Override
@Override public void removeAllMessages(ConnectionContext context) throws IOException { KahaRemoveDestinationCommand command = new KahaRemoveDestinationCommand(); command.setDestination(dest); process(command); }
@Override public void prepare(TransactionId txid) throws IOException { processPrepare(txid); } @Override
@Override public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setMessageId(ack.getLastMessageId().toProducerKey()); processRemove(command, ack.getTransactionId()); }
@Override public void addSubscription(SubscriptionInfo subscriptionInfo, boolean retroactive) throws IOException { String subscriptionKey = subscriptionKey(subscriptionInfo.getClientId(), subscriptionInfo.getSubscriptionName()); KahaSubscriptionCommand command = new KahaSubscriptionCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey); command.setRetroactive(retroactive); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(subscriptionInfo); command.setSubscriptionInfo(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); process(command); }
@Override public void recoverSubscription(String clientId, String subscriptionName, final MessageRecoveryListener listener) throws Exception { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<Exception>(){ @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); Long cursorPos = sd.subscriptionAcks.get(tx, subscriptionKey); cursorPos += 1; for (Iterator<Entry<Long, MessageRecord>> iterator = sd.orderIndex.iterator(tx, cursorPos); iterator.hasNext();) { Entry<Long, MessageRecord> entry = iterator.next(); listener.recoverMessage( (Message) wireFormat.unmarshal(entry.getValue().data ) ); } } }); } }
@Override public void acknowledge(ConnectionContext context, String clientId, String subscriptionName, MessageId messageId, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey(clientId, subscriptionName)); command.setMessageId(messageId.toProducerKey()); // We are not passed a transaction info.. so we can't participate in a transaction. // Looks like a design issue with the TopicMessageStore interface. Also we can't recover the original ack // to pass back to the XA recover method. // command.setTransactionInfo(); processRemove(command, null); }