public JDBCAdapter getAdapter() throws IOException { return jdbcPersistenceAdapter.getAdapter(); }
@Override public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { TopicMessageStore rc = (TopicMessageStore) storeCache.get(destination); if (rc == null) { TopicMessageStore store = transactionStore.proxy(new JDBCTopicMessageStore(this, getAdapter(), wireFormat, destination, audit)); rc = (TopicMessageStore) storeCache.putIfAbsent(destination, store); if (rc == null) { rc = store; } } return rc; }
@Override public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException { MessageStore rc = storeCache.get(destination); if (rc == null) { MessageStore store = transactionStore.proxy(new JDBCMessageStore(this, getAdapter(), wireFormat, destination, audit)); rc = storeCache.putIfAbsent(destination, store); if (rc == null) { rc = store; } } return rc; }
public void cleanup() { TransactionContext c = null; try { LOG.debug("Cleaning up old messages."); c = getTransactionContext(); c.getExclusiveConnection(); getAdapter().doDeleteOldMessages(c); } catch (IOException e) { LOG.warn("Old message cleanup failed due to: " + e, e); } catch (SQLException e) { LOG.warn("Old message cleanup failed due to: " + e); JDBCPersistenceAdapter.log("Failure Details: ", e); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } LOG.debug("Cleanup done."); } }
@Override public void deleteAllMessages() throws IOException { TransactionContext c = getTransactionContext(); c.getExclusiveConnection(); try { getAdapter().doDropTables(c); getAdapter().setUseExternalMessageReferences(isUseExternalMessageReferences()); getAdapter().doCreateTables(c); LOG.info("Persistence store purged."); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create(e); } finally { c.close(); } }
public void initSequenceIdGenerator() { TransactionContext c = null; try { c = getTransactionContext(); getAdapter().doMessageIdScan(c, auditRecoveryDepth, new JDBCMessageIdScanListener() { @Override public void messageId(MessageId id) { audit.isDuplicate(id); } }); } catch (Exception e) { LOG.error("Failed to reload store message audit for JDBC persistence adapter", e); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } } }
protected void createMessageAudit() { if (enableAudit && audit == null) { audit = new ActiveMQMessageAudit(maxAuditDepth,maxProducersToAudit); TransactionContext c = null; try { c = getTransactionContext(); getAdapter().doMessageIdScan(c, auditRecoveryDepth, new JDBCMessageIdScanListener() { @Override public void messageId(MessageId id) { audit.isDuplicate(id); } }); } catch (Exception e) { LOG.error("Failed to reload store message audit for JDBC persistence adapter", e); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } } } }
@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(); } }
@Override public void init() throws Exception { getAdapter().setUseExternalMessageReferences(isUseExternalMessageReferences()); if (isCreateTablesOnStartup()) { TransactionContext transactionContext = getTransactionContext(); transactionContext.getExclusiveConnection(); transactionContext.begin(); try { try { getAdapter().doCreateTables(transactionContext); } catch (SQLException e) { LOG.warn("Cannot create tables due to: " + e); JDBCPersistenceAdapter.log("Failure Details: ", e); } } finally { transactionContext.commit(); } } }
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(); } }
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 long getLastMessageBrokerSequenceId() throws IOException { TransactionContext c = getTransactionContext(); try { long seq = getAdapter().doGetLastMessageStoreSequenceId(c); sequenceGenerator.setLastSequenceId(seq); long brokerSeq = 0; if (seq != 0) { byte[] msg = getAdapter().doGetMessageById(c, seq); if (msg != null) { Message last = (Message)wireFormat.unmarshal(new ByteSequence(msg)); brokerSeq = last.getMessageId().getBrokerSequenceId(); } else { LOG.warn("Broker sequence id wasn't recovered properly, possible duplicates!"); } } return brokerSeq; } 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 commitRemove(ConnectionContext context, MessageAck ack) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doRemoveMessage(c, (Long)ack.getLastMessageId().getEntryLocator(), null); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to commit last ack: " + ack + ". Reason: " + e,e); } finally { c.close(); } }
@Override public Set<ActiveMQDestination> getDestinations() { TransactionContext c = null; try { c = getTransactionContext(); return getAdapter().doGetDestinations(c); } catch (IOException e) { return emptyDestinationSet(); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); return emptyDestinationSet(); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } } }
public void rollbackLastAck(ConnectionContext context, JDBCTopicMessageStore store, MessageAck ack, String subName, String clientId) throws IOException { TransactionContext c = getTransactionContext(context); try { byte priority = (byte) store.getCachedStoreSequenceId(c, store.getDestination(), ack.getLastMessageId())[1]; getAdapter().doClearLastAck(c, store.getDestination(), priority, clientId, subName); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to rollback last ack: " + ack + " on " + store.getDestination() + " for " + subName + ":" + clientId + ". Reason: " + e,e); } finally { c.close(); } }
@Override public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException { TopicMessageStore rc = new JDBCTopicMessageStore(this, getAdapter(), wireFormat, destination, audit); if (transactionStore != null) { rc = transactionStore.proxy(rc); } return rc; }
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(); } }