/** * Sets whether or not an exclusive database lock should be used to enable * JDBC Master/Slave. Enabled by default. */ public void setUseDatabaseLock(boolean useDatabaseLock) { jdbcPersistenceAdapter.setUseLock(useDatabaseLock); }
@Override public void run() { cleanup(); } }, 0, cleanupPeriod, TimeUnit.MILLISECONDS);
public JDBCAdapter getAdapter() throws IOException { if (adapter == null) { setAdapter(createAdapter()); } return adapter; }
@Override public synchronized void doStop(ServiceStopper stopper) throws Exception { if (cleanupTicket != null) { cleanupTicket.cancel(true); cleanupTicket = null; } closeDataSource(getDataSource()); }
@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 start() throws Exception { getAdapter().setUseExternalMessageReferences(isUseExternalMessageReferences()); if (isCreateTablesOnStartup()) { TransactionContext transactionContext = getTransactionContext(); transactionContext.begin(); try { try { getAdapter().doCreateTables(transactionContext); } catch (SQLException e) { LOG.warn("Cannot create tables due to: " + e); JDBCPersistenceAdapter.log("Failure Details: ", e); if (isUseDatabaseLock()) { DatabaseLocker service = getDatabaseLocker(); if (service == null) { LOG.warn("No databaseLocker configured for the JDBC Persistence Adapter"); service.start(); if (lockKeepAlivePeriod > 0) { keepAliveTicket = getScheduledThreadPoolExecutor().scheduleAtFixedRate(new Runnable() { public void run() { databaseLockKeepAlive(); cleanup(); cleanupTicket = getScheduledThreadPoolExecutor().scheduleWithFixedDelay(new Runnable() { public void run() { cleanup();
@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(); } }
@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(); } }
final JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter(); adapter.setUseLock(Boolean.parseBoolean(properties.getProperty("usedatabaselock", "true"))); adapter.setDataSource(dataSource); broker.setPersistent(true); broker.setPersistenceAdapter(adapter);
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(); } } }
try { connection = dataSource.getConnection(); if (persistenceAdapter.isChangeAutoCommitAllowed()) { boolean autoCommit = !inTx; if (connection.getAutoCommit() != autoCommit) { JDBCPersistenceAdapter.log("Could not get JDBC connection: ", e); inTx = false; try { if (persistenceAdapter.getBrokerService() != null) { persistenceAdapter.getBrokerService().handleIOException(ioe);
@Override public void doStart() throws Exception { if( brokerService!=null ) { wireFormat.setVersion(brokerService.getStoreOpenWireVersion()); } // Cleanup the db periodically. if (cleanupPeriod > 0) { cleanupTicket = getScheduledThreadPoolExecutor().scheduleWithFixedDelay(new Runnable() { @Override public void run() { cleanup(); } }, 0, cleanupPeriod, TimeUnit.MILLISECONDS); } createMessageAudit(); }
public PersistenceAdapter createPersistenceAdapter() throws IOException { jdbcPersistenceAdapter.setDataSource(getDataSource()); if (!useJournal) { return jdbcPersistenceAdapter; } JournalPersistenceAdapter result = new JournalPersistenceAdapter(getJournal(), jdbcPersistenceAdapter, getTaskRunnerFactory()); result.setDirectory(getDataDirectoryFile()); result.setCheckpointInterval(getCheckpointInterval()); return result; }
public TransactionContext(JDBCPersistenceAdapter persistenceAdapter) throws IOException { this.persistenceAdapter = persistenceAdapter; this.dataSource = persistenceAdapter.getDataSource(); }
/** * Cleanup method to remove any state associated with the given destination * @param destination Destination to forget */ @Override public void removeQueueMessageStore(ActiveMQQueue destination) { if (destination.isQueue() && getBrokerService().shouldRecordVirtualDestination(destination)) { try { removeConsumerDestination(destination); } catch (IOException ioe) { LOG.error("Failed to remove consumer destination: " + destination, ioe); } } storeCache.remove(destination); }
JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter(); persistenceAdapter.setDataSource(dataSource); broker.setPersistenceAdapter(persistenceAdapter); } else {
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) { } } } }
public JDBCMessageStore(JDBCPersistenceAdapter persistenceAdapter, JDBCAdapter adapter, WireFormat wireFormat, ActiveMQDestination destination, ActiveMQMessageAudit audit) throws IOException { super(destination); this.persistenceAdapter = persistenceAdapter; this.adapter = adapter; this.wireFormat = wireFormat; this.audit = audit; if (destination.isQueue() && persistenceAdapter.getBrokerService().shouldRecordVirtualDestination(destination)) { recordDestinationCreation(destination); } resetBatching(); }
public JDBCAdapter getAdapter() throws IOException { return jdbcPersistenceAdapter.getAdapter(); }
/** * Initialize. * * @throws Exception * the exception */ public void initialize() throws Exception { synchronized (SchedulerManager.class) { if (broker == null) { broker = new BrokerService(); Configuration.load("/dirigible-messaging.properties"); if (Boolean.parseBoolean(Configuration.get("DIRIGIBLE_MESSAGING_USE_DEFAULT_DATABASE", "true"))) { PersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter(dataSource, new OpenWireFormat()); broker.setPersistenceAdapter(persistenceAdapter); } broker.setPersistent(true); broker.setUseJmx(false); // broker.setUseShutdownHook(false); PListStore pListStore = new PListStoreImpl(); pListStore.setDirectory(new File(LOCATION_TEMP_STORE)); broker.setTempDataStore(pListStore); broker.addConnector(CONNECTOR_URL); broker.start(); } } }