Search in sources :

Example 1 with JDBCSequentialFile

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile 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 2 with JDBCSequentialFile

use of org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile 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 3 with JDBCSequentialFile

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

the class JDBCSequentialFileFactoryTest method testCopyFile.

@Test
public void testCopyFile() throws Exception {
    JDBCSequentialFile file = (JDBCSequentialFile) factory.createSequentialFile("test.txt");
    file.open();
    // Create buffer and fill with test data
    int bufferSize = 1024;
    ActiveMQBuffer src = ActiveMQBuffers.fixedBuffer(bufferSize);
    for (int i = 0; i < bufferSize; i++) {
        src.writeByte((byte) 5);
    }
    IOCallbackCountdown callback = new IOCallbackCountdown(1);
    file.internalWrite(src, callback);
    JDBCSequentialFile copy = (JDBCSequentialFile) factory.createSequentialFile("copy.txt");
    file.copyTo(copy);
    checkData(file, src);
    checkData(copy, src);
}
Also used : JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 4 with JDBCSequentialFile

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

the class JDBCSequentialFileFactoryTest method testCloneFile.

@Test
public void testCloneFile() throws Exception {
    JDBCSequentialFile file = (JDBCSequentialFile) factory.createSequentialFile("test.txt");
    file.open();
    // Create buffer and fill with test data
    int bufferSize = 1024;
    ActiveMQBuffer src = ActiveMQBuffers.fixedBuffer(bufferSize);
    for (int i = 0; i < bufferSize; i++) {
        src.writeByte((byte) 5);
    }
    IOCallbackCountdown callback = new IOCallbackCountdown(1);
    file.internalWrite(src, callback);
    assertEquals(bufferSize, file.size());
    JDBCSequentialFile copy = (JDBCSequentialFile) file.cloneFile();
    copy.open();
    assertEquals(bufferSize, copy.size());
    assertEquals(bufferSize, file.size());
}
Also used : JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 5 with JDBCSequentialFile

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

the class JDBCSequentialFileFactoryTest method testGetFileSizeWorksWhenNotOpen.

/**
 * Using a real file system users are not required to call file.open() in order to read the file size.  The file
 * descriptor has enough information.  However, with JDBC we do require that some information is loaded in order to
 * get the underlying BLOB.  This tests ensures that file.size() returns the correct value, without the user calling
 * file.open() with JDBCSequentialFile.
 *
 * @throws Exception
 */
@Test
public void testGetFileSizeWorksWhenNotOpen() throws Exception {
    // Create test file with some data.
    int testFileSize = 1024;
    String fileName = "testFile.txt";
    SequentialFile file = factory.createSequentialFile(fileName);
    file.open();
    // Write some data to the file
    ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(new byte[1024]);
    file.write(buffer, true);
    file.close();
    try {
        // Create a new pointer to the test file and ensure file.size() returns the correct value.
        SequentialFile file2 = factory.createSequentialFile(fileName);
        assertEquals(testFileSize, file2.size());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)6 Test (org.junit.Test)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 JDBCSequentialFileFactory (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)2 ArrayList (java.util.ArrayList)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 PropertySQLProvider (org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider)1 SQLProvider (org.apache.activemq.artemis.jdbc.store.sql.SQLProvider)1