Search in sources :

Example 1 with JDBCJournalImpl

use of org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl 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 JDBCJournalImpl

use of org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl in project activemq-artemis by apache.

the class ShutdownServerTest method testShutdownServer.

@Test
public void testShutdownServer() throws Throwable {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true, false);
    session.createQueue(QUEUE, QUEUE, null, true);
    ClientConsumer consumer = session.createConsumer(QUEUE);
    ClientProducer producer = session.createProducer(QUEUE);
    ClientMessage message = session.createMessage(Message.TEXT_TYPE, true, 0, System.currentTimeMillis(), (byte) 4);
    message.getBodyBuffer().writeString("hi");
    message.putStringProperty("hello", "elo");
    producer.send(message);
    ActiveMQServerImpl impl = (ActiveMQServerImpl) server;
    JournalStorageManager journal = (JournalStorageManager) impl.getStorageManager();
    JDBCJournalImpl journalimpl = (JDBCJournalImpl) journal.getMessageJournal();
    journalimpl.handleException(null, new Exception("failure"));
    Wait.waitFor(() -> !server.isStarted());
    Assert.assertFalse(server.isStarted());
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) JDBCJournalImpl(org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 3 with JDBCJournalImpl

use of org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl in project activemq-artemis by apache.

the class JDBCJournalTest method setup.

@Before
public void setup() throws Exception {
    scheduledExecutorService = new ScheduledThreadPoolExecutor(5);
    executorService = Executors.newSingleThreadExecutor();
    jdbcUrl = "jdbc:derby:target/data;create=true";
    SQLProvider.Factory factory = new PropertySQLProvider.Factory(DERBY);
    journal = new JDBCJournalImpl(jdbcUrl, DRIVER_CLASS, factory.create(JOURNAL_TABLE_NAME, SQLProvider.DatabaseStoreType.MESSAGE_JOURNAL), scheduledExecutorService, executorService, new IOCriticalErrorListener() {

        @Override
        public void onIOException(Throwable code, String message, SequentialFile file) {
        }
    }, 5);
    journal.start();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) 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) Before(org.junit.Before)

Aggregations

JDBCJournalImpl (org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl)3 PropertySQLProvider (org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider)2 SQLProvider (org.apache.activemq.artemis.jdbc.store.sql.SQLProvider)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)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 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)1 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)1 JDBCSequentialFileFactory (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)1 Before (org.junit.Before)1 Test (org.junit.Test)1