@Override public SubscriptionInfo[] getAllSubscriptions() throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { return adapter.doGetAllSubscriptions(c, destination); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to lookup subscriptions. Reason: " + e, e); } finally { c.close(); } }
public void close() throws IOException { if (!inTx) { try { // can be null for topic ops that bypass the store via existing cursor state if (connection != null) { final boolean needsCommit = !connection.getAutoCommit(); executeBatch(); if (needsCommit) { connection.commit(); } } } catch (SQLException e) { JDBCPersistenceAdapter.log("Error while closing connection: ", e); IOException ioe = IOExceptionSupport.create(e); persistenceAdapter.getBrokerService().handleIOException(ioe); throw ioe; } finally { silentClose(); for (Runnable completion: completions) { completion.run(); } completions.clear(); } } }
long[] getStoreSequenceIdForMessageId(ConnectionContext context, MessageId messageId, ActiveMQDestination destination) throws IOException { long[] result = new long[]{-1, Byte.MAX_VALUE -1}; TransactionContext c = getTransactionContext(context); try { result = adapter.getStoreSequenceId(c, destination, messageId); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get store sequenceId for messageId: " + messageId +", on: " + destination + ". Reason: " + e, e); } finally { c.close(); } return result; }
public void commit() throws IOException { if (!inTx) { throw new IOException("Not started."); } try { final boolean needsCommit = !connection.getAutoCommit(); executeBatch(); if (needsCommit) { connection.commit(); } } catch (SQLException e) { JDBCPersistenceAdapter.log("Commit failed: ", e); try { doRollback(); } catch (Exception ignored) {} IOException ioe = IOExceptionSupport.create(e); persistenceAdapter.getBrokerService().handleIOException(ioe); throw ioe; } finally { inTx = false; close(); } }
@Override public int getMessageCount() throws IOException { int result = 0; TransactionContext c = persistenceAdapter.getTransactionContext(); try { result = adapter.doGetMessageCount(c, destination); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get Message Count: " + destination + ". Reason: " + e, e); } finally { c.close(); } return result; }
/** * @see org.apache.activemq.store.TopicMessageStore#lookupSubscription(String, * String) */ @Override public SubscriptionInfo lookupSubscription(String clientId, String subscriptionName) throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { return adapter.doGetSubscriberEntry(c, destination, clientId, subscriptionName); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to lookup subscription for: " + clientId + ". Reason: " + e, e); } finally { c.close(); } }
/** * @see org.apache.activemq.store.MessageStore#removeAllMessages(ConnectionContext) */ @Override public void removeAllMessages(ConnectionContext context) throws IOException { // Get a connection and remove the message from the DB TransactionContext c = persistenceAdapter.getTransactionContext(context); try { adapter.doRemoveAllMessages(c, destination); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker remove all messages: " + e, e); } finally { c.close(); } }
public String getMessageReference(MessageId messageId) throws IOException { long id = messageId.getBrokerSequenceId(); // Get a connection and pull the message out of the DB TransactionContext c = persistenceAdapter.getTransactionContext(); try { return adapter.doGetMessageReference(c, id); } catch (IOException e) { throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } finally { c.close(); } }
@Override public long getLastProducerSequenceId(ProducerId id) throws IOException { TransactionContext c = getTransactionContext(); try { return getAdapter().doGetLastProducerSequenceId(c, id); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get last broker message id: " + e, e); } finally { c.close(); } }
public void commitLastAck(ConnectionContext context, long xidLastAck, long priority, ActiveMQDestination destination, String subName, String clientId) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doSetLastAck(c, destination, null, clientId, subName, xidLastAck, priority); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to commit last ack with priority: " + priority + " on " + destination + " for " + subName + ":" + clientId + ". Reason: " + e,e); } finally { c.close(); } }
public void recover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore) throws IOException { TransactionContext c = getTransactionContext(); try { getAdapter().doRecoverPreparedOps(c, jdbcMemoryTransactionStore); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to recover from: " + jdbcMemoryTransactionStore + ". Reason: " + e,e); } finally { c.close(); } }
public void commitAdd(ConnectionContext context, final MessageId messageId, final long preparedSequenceId, final long newSequence) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doCommitAddOp(c, preparedSequenceId, newSequence); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to commit add: " + messageId + ". Reason: " + e, e); } finally { c.close(); } }
public void rollbackLastAck(ConnectionContext context, byte priority, ActiveMQDestination destination, String subName, String clientId) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doClearLastAck(c, destination, priority, clientId, subName); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to rollback last ack with priority: " + priority + " on " + destination + " for " + subName + ":" + clientId + ". Reason: " + e, e); } finally { c.close(); } }
public void addMessageReference(ConnectionContext context, MessageId messageId, long expirationTime, String messageRef) throws IOException { // Get a connection and insert the message into the DB. TransactionContext c = persistenceAdapter.getTransactionContext(context); try { adapter.doAddMessageReference(c, persistenceAdapter.getNextSequenceId(), messageId, destination, expirationTime, messageRef); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } finally { c.close(); } }
@Override public void deleteSubscription(String clientId, String subscriptionName) throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { adapter.doDeleteSubscription(c, destination, clientId, subscriptionName); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to remove subscription for: " + clientId + ". Reason: " + e, e); } finally { c.close(); resetBatching(clientId, subscriptionName); } }
@Override public void addSubscription(SubscriptionInfo subscriptionInfo, boolean retroactive) throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { c = persistenceAdapter.getTransactionContext(); adapter.doSetSubscriberEntry(c, subscriptionInfo, retroactive, isPrioritizedMessages()); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to lookup subscription for info: " + subscriptionInfo.getClientId() + ". Reason: " + e, e); } finally { c.close(); } }
private void removeConsumerDestination(ActiveMQQueue destination) throws IOException { TransactionContext c = getTransactionContext(); try { String id = destination.getQualifiedName(); getAdapter().doDeleteSubscription(c, destination, id, id); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to remove consumer destination: " + destination, e); } finally { c.close(); } }
@Override public int getMessageCount(String clientId, String subscriberName) throws IOException { //Duration duration = new Duration("getMessageCount"); int result = 0; TransactionContext c = persistenceAdapter.getTransactionContext(); try { result = adapter.doGetDurableSubscriberMessageCount(c, destination, clientId, subscriberName, isPrioritizedMessages()); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get Message Count: " + clientId + ". Reason: " + e, e); } finally { c.close(); } if (LOG.isTraceEnabled()) { LOG.trace(clientId + ":" + subscriberName + ", messageCount: " + result); } //duration.end(); return result; }