use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.
the class ActiveMQTestBase method countBindingJournal.
protected HashMap<Integer, AtomicInteger> countBindingJournal(Configuration config) throws Exception {
final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
List<JournalFile> filesToRead = messagesJournal.orderFiles();
for (JournalFile file : filesToRead) {
JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
}
return recordsType;
}
use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreFactoryDatabase method newFileFactory.
@Override
public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception {
String tableName = "" + storageManager.generateID();
SequentialFileFactory factory = newFileFactory(tableName, true);
factory.start();
SequentialFile file = factory.createSequentialFile(PagingStoreFactoryDatabase.ADDRESS_FILE);
file.open();
ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(SimpleString.sizeofNullableString(address));
buffer.writeSimpleString(address);
file.write(buffer, true);
file.close();
return factory;
}
use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreFactoryNIO method reloadStores.
@Override
public List<PagingStore> reloadStores(final HierarchicalRepository<AddressSettings> addressSettingsRepository) throws Exception {
File[] files = directory.listFiles();
if (files == null) {
return Collections.<PagingStore>emptyList();
} else {
ArrayList<PagingStore> storesReturn = new ArrayList<>(files.length);
for (File file : files) {
final String guid = file.getName();
final File addressFile = new File(file, PagingStoreFactoryNIO.ADDRESS_FILE);
if (!addressFile.exists()) {
// This means this folder is from a replication copy, nothing to worry about it, we just skip it
if (!file.getName().contains(FileMoveManager.PREFIX)) {
ActiveMQServerLogger.LOGGER.pageStoreFactoryNoIdFile(file.toString(), PagingStoreFactoryNIO.ADDRESS_FILE);
}
continue;
}
String addressString;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(addressFile)))) {
addressString = reader.readLine();
}
SimpleString address = new SimpleString(addressString);
SequentialFileFactory factory = newFileFactory(guid);
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);
}
return storesReturn;
}
}
use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreFactoryNIO method newFileFactory.
@Override
public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception {
String guid = UUIDGenerator.getInstance().generateStringUUID();
SequentialFileFactory factory = newFileFactory(guid);
factory.createDirs();
File fileWithID = new File(directory, guid + File.separatorChar + PagingStoreFactoryNIO.ADDRESS_FILE);
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileWithID)))) {
writer.write(address.toString());
writer.newLine();
}
return factory;
}
use of org.apache.activemq.artemis.core.io.SequentialFileFactory in project activemq-artemis by apache.
the class HangConsumerTest method testDuplicateDestinationsOnTopic.
/**
* This will simulate what would happen with topic creationg where a single record is supposed to be created on the journal
*
* @throws Exception
*/
@Test
public void testDuplicateDestinationsOnTopic() throws Exception {
try {
for (int i = 0; i < 5; i++) {
if (server.locateQueue(SimpleString.toSimpleString("tt")) == null) {
server.createQueue(SimpleString.toSimpleString("tt"), RoutingType.ANYCAST, SimpleString.toSimpleString("tt"), SimpleString.toSimpleString(Filter.GENERIC_IGNORED_FILTER), true, false);
}
server.stop();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsLocation(), null, 1);
JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 2, 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
messagesJournal.start();
LinkedList<RecordInfo> infos = new LinkedList<>();
messagesJournal.load(infos, null, null);
int bindings = 0;
for (RecordInfo info : infos) {
System.out.println("info: " + info);
if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
bindings++;
}
}
assertEquals(1, bindings);
System.out.println("Bindings: " + bindings);
messagesJournal.stop();
if (i < 4)
server.start();
}
} finally {
try {
server.stop();
} catch (Throwable ignored) {
}
}
}
Aggregations