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;
}
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;
}
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);
}
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());
}
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();
}
}
Aggregations