Search in sources :

Example 1 with JDBCSequentialFileFactory

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory in project activemq-artemis by apache.

the class JDBCJournalStorageManager method init.

@Override
protected synchronized void init(Configuration config, IOCriticalErrorListener criticalErrorListener) {
    try {
        final DatabaseStorageConfiguration dbConf = (DatabaseStorageConfiguration) config.getStoreConfiguration();
        final JDBCJournalImpl bindingsJournal;
        final JDBCJournalImpl messageJournal;
        final JDBCSequentialFileFactory largeMessagesFactory;
        if (dbConf.getDataSource() != null) {
            SQLProvider.Factory sqlProviderFactory = dbConf.getSqlProviderFactory();
            if (sqlProviderFactory == null) {
                sqlProviderFactory = new PropertySQLProvider.Factory(dbConf.getDataSource());
            }
            bindingsJournal = new JDBCJournalImpl(dbConf.getDataSource(), sqlProviderFactory.create(dbConf.getBindingsTableName(), SQLProvider.DatabaseStoreType.BINDINGS_JOURNAL), dbConf.getBindingsTableName(), scheduledExecutorService, executorFactory.getExecutor(), criticalErrorListener, dbConf.getJdbcJournalSyncPeriodMillis());
            messageJournal = new JDBCJournalImpl(dbConf.getDataSource(), sqlProviderFactory.create(dbConf.getMessageTableName(), SQLProvider.DatabaseStoreType.MESSAGE_JOURNAL), dbConf.getMessageTableName(), scheduledExecutorService, executorFactory.getExecutor(), criticalErrorListener, dbConf.getJdbcJournalSyncPeriodMillis());
            largeMessagesFactory = new JDBCSequentialFileFactory(dbConf.getDataSource(), sqlProviderFactory.create(dbConf.getLargeMessageTableName(), SQLProvider.DatabaseStoreType.LARGE_MESSAGE), executorFactory.getExecutor(), criticalErrorListener);
        } else {
            String driverClassName = dbConf.getJdbcDriverClassName();
            bindingsJournal = new JDBCJournalImpl(dbConf.getJdbcConnectionUrl(), driverClassName, JDBCUtils.getSQLProvider(driverClassName, dbConf.getBindingsTableName(), SQLProvider.DatabaseStoreType.BINDINGS_JOURNAL), scheduledExecutorService, executorFactory.getExecutor(), criticalErrorListener, dbConf.getJdbcJournalSyncPeriodMillis());
            messageJournal = new JDBCJournalImpl(dbConf.getJdbcConnectionUrl(), driverClassName, JDBCUtils.getSQLProvider(driverClassName, dbConf.getMessageTableName(), SQLProvider.DatabaseStoreType.MESSAGE_JOURNAL), scheduledExecutorService, executorFactory.getExecutor(), criticalErrorListener, dbConf.getJdbcJournalSyncPeriodMillis());
            largeMessagesFactory = new JDBCSequentialFileFactory(dbConf.getJdbcConnectionUrl(), driverClassName, JDBCUtils.getSQLProvider(driverClassName, dbConf.getLargeMessageTableName(), SQLProvider.DatabaseStoreType.LARGE_MESSAGE), executorFactory.getExecutor(), criticalErrorListener);
        }
        final int networkTimeout = dbConf.getJdbcNetworkTimeout();
        if (networkTimeout >= 0) {
            bindingsJournal.setNetworkTimeout(executorFactory.getExecutor(), networkTimeout);
        }
        if (networkTimeout >= 0) {
            messageJournal.setNetworkTimeout(executorFactory.getExecutor(), networkTimeout);
        }
        if (networkTimeout >= 0) {
            largeMessagesFactory.setNetworkTimeout(executorFactory.getExecutor(), networkTimeout);
        }
        this.bindingsJournal = bindingsJournal;
        this.messageJournal = messageJournal;
        this.largeMessagesFactory = largeMessagesFactory;
        largeMessagesFactory.start();
    } catch (Exception e) {
        criticalErrorListener.onIOException(e, e.getMessage(), null);
    }
}
Also used : DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) JDBCJournalImpl(org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)

Example 2 with JDBCSequentialFileFactory

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreFactoryDatabase method newFileFactory.

private synchronized SequentialFileFactory newFileFactory(final String directoryName, boolean writeToDirectory) throws Exception {
    JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME);
    directoryList.open();
    SimpleString simpleString = SimpleString.toSimpleString(directoryName);
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(simpleString.sizeof());
    buffer.writeSimpleString(simpleString);
    if (writeToDirectory)
        directoryList.write(buffer, true);
    directoryList.close();
    final SQLProvider sqlProvider;
    if (dbConf.getDataSource() != null) {
        final SQLProvider.Factory sqlProviderFactory;
        if (dbConf.getSqlProviderFactory() != null) {
            sqlProviderFactory = dbConf.getSqlProviderFactory();
        } else {
            sqlProviderFactory = new PropertySQLProvider.Factory(dbConf.getDataSource());
        }
        sqlProvider = sqlProviderFactory.create(getTableNameForGUID(directoryName), SQLProvider.DatabaseStoreType.PAGE);
    } else {
        sqlProvider = JDBCUtils.getSQLProvider(dbConf.getJdbcDriverClassName(), getTableNameForGUID(directoryName), SQLProvider.DatabaseStoreType.PAGE);
    }
    final JDBCSequentialFileFactory fileFactory = new JDBCSequentialFileFactory(pagingFactoryFileFactory.getDbDriver().getConnection(), sqlProvider, executorFactory.getExecutor(), criticalErrorListener);
    final int jdbcNetworkTimeout = dbConf.getJdbcNetworkTimeout();
    if (jdbcNetworkTimeout >= 0) {
        fileFactory.setNetworkTimeout(this.executorFactory.getExecutor(), jdbcNetworkTimeout);
    }
    return fileFactory;
}
Also used : PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 3 with JDBCSequentialFileFactory

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreFactoryDatabase method start.

public synchronized void start() throws Exception {
    if (!started) {
        // fix to prevent page table names to be longer than 30 chars (upper limit for Oracle12c identifiers length)
        final String pageStoreTableNamePrefix = dbConf.getPageStoreTableName();
        if (pageStoreTableNamePrefix.length() > 10) {
            throw new IllegalStateException("The maximum name size for the page store table prefix is 10 characters: THE PAGING STORE CAN'T START");
        }
        if (dbConf.getDataSource() != null) {
            SQLProvider.Factory sqlProviderFactory = dbConf.getSqlProviderFactory();
            if (sqlProviderFactory == null) {
                sqlProviderFactory = new PropertySQLProvider.Factory(dbConf.getDataSource());
            }
            pagingFactoryFileFactory = new JDBCSequentialFileFactory(dbConf.getDataSource(), sqlProviderFactory.create(pageStoreTableNamePrefix, SQLProvider.DatabaseStoreType.PAGE), executorFactory.getExecutor(), criticalErrorListener);
        } else {
            String driverClassName = dbConf.getJdbcDriverClassName();
            pagingFactoryFileFactory = new JDBCSequentialFileFactory(dbConf.getJdbcConnectionUrl(), driverClassName, JDBCUtils.getSQLProvider(driverClassName, pageStoreTableNamePrefix, SQLProvider.DatabaseStoreType.PAGE), executorFactory.getExecutor(), criticalErrorListener);
        }
        final int jdbcNetworkTimeout = dbConf.getJdbcNetworkTimeout();
        if (jdbcNetworkTimeout >= 0) {
            pagingFactoryFileFactory.setNetworkTimeout(this.executorFactory.getExecutor(), jdbcNetworkTimeout);
        }
        pagingFactoryFileFactory.start();
        started = true;
    }
}
Also used : PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)

Example 4 with JDBCSequentialFileFactory

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreFactoryDatabase method reloadStores.

@Override
public synchronized List<PagingStore> reloadStores(final HierarchicalRepository<AddressSettings> addressSettingsRepository) throws Exception {
    // We assume the directory list < Integer.MAX_VALUE (this is only a list of addresses).
    JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME);
    directoryList.open();
    int size = ((Long) directoryList.size()).intValue();
    ActiveMQBuffer buffer = readActiveMQBuffer(directoryList, size);
    ArrayList<PagingStore> storesReturn = new ArrayList<>();
    while (buffer.readableBytes() > 0) {
        SimpleString table = buffer.readSimpleString();
        JDBCSequentialFileFactory factory = (JDBCSequentialFileFactory) newFileFactory(table.toString(), false);
        factory.start();
        JDBCSequentialFile addressFile = (JDBCSequentialFile) factory.createSequentialFile(ADDRESS_FILE);
        addressFile.open();
        size = ((Long) addressFile.size()).intValue();
        if (size == 0) {
            continue;
        }
        ActiveMQBuffer addrBuffer = readActiveMQBuffer(addressFile, size);
        SimpleString address = addrBuffer.readSimpleString();
        AddressSettings settings = addressSettingsRepository.getMatch(address.toString());
        PagingStore store = new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, factory, this, address, settings, executorFactory.getExecutor(), syncNonTransactional);
        storesReturn.add(store);
    }
    directoryList.close();
    return storesReturn;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 5 with JDBCSequentialFileFactory

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory in project activemq-artemis by apache.

the class JDBCSequentialFileFactoryTest method setup.

@Before
public void setup() throws Exception {
    executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory());
    String connectionUrl = "jdbc:derby:target/data;create=true";
    String tableName = "FILES";
    factory = new JDBCSequentialFileFactory(connectionUrl, className, JDBCUtils.getSQLProvider(className, tableName, SQLProvider.DatabaseStoreType.PAGE), executor, new IOCriticalErrorListener() {

        @Override
        public void onIOException(Throwable code, String message, SequentialFile file) {
        }
    });
    factory.start();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) Before(org.junit.Before)

Aggregations

JDBCSequentialFileFactory (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)3 PropertySQLProvider (org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider)3 SQLProvider (org.apache.activemq.artemis.jdbc.store.sql.SQLProvider)3 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 ArrayList (java.util.ArrayList)1 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)1 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)1 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)1 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1 JDBCJournalImpl (org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl)1 Before (org.junit.Before)1