use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class JMSJournalStorageManagerImpl method addBindings.
@Override
public void addBindings(PersistedType type, String name, String... address) throws Exception {
Pair<PersistedType, String> key = new Pair<>(type, name);
long tx = idGenerator.generateID();
PersistedBindings currentBindings = mapBindings.get(key);
if (currentBindings != null) {
jmsJournal.appendDeleteRecordTransactional(tx, currentBindings.getId());
} else {
currentBindings = new PersistedBindings(type, name);
}
mapBindings.put(key, currentBindings);
for (String adItem : address) {
currentBindings.addBinding(adItem);
}
long newId = idGenerator.generateID();
currentBindings.setId(newId);
jmsJournal.appendAddRecordTransactional(tx, newId, BINDING_RECORD, currentBindings);
jmsJournal.appendCommitRecord(tx, true);
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class JMSJournalStorageManagerImpl method load.
@Override
public void load() throws Exception {
mapFactories.clear();
List<RecordInfo> data = new ArrayList<>();
ArrayList<PreparedTransactionInfo> list = new ArrayList<>();
jmsJournal.load(data, list, null);
for (RecordInfo record : data) {
long id = record.id;
ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
byte rec = record.getUserRecordType();
if (rec == CF_RECORD) {
PersistedConnectionFactory cf = new PersistedConnectionFactory();
cf.decode(buffer);
cf.setId(id);
mapFactories.put(cf.getName(), cf);
} else if (rec == DESTINATION_RECORD) {
PersistedDestination destination = new PersistedDestination();
destination.decode(buffer);
destination.setId(id);
destinations.put(new Pair<>(destination.getType(), destination.getName()), destination);
} else if (rec == BINDING_RECORD) {
PersistedBindings bindings = new PersistedBindings();
bindings.decode(buffer);
bindings.setId(id);
Pair<PersistedType, String> key = new Pair<>(bindings.getType(), bindings.getName());
mapBindings.put(key, bindings);
} else {
throw new IllegalStateException("Invalid record type " + rec);
}
}
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class NIOJournalCompactTest method testControlFile.
// General tests
// =============
@Test
public void testControlFile() throws Exception {
ArrayList<JournalFile> dataFiles = new ArrayList<>();
for (int i = 0; i < 5; i++) {
SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst");
dataFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
}
ArrayList<JournalFile> newFiles = new ArrayList<>();
for (int i = 0; i < 3; i++) {
SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst.new");
newFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
}
ArrayList<Pair<String, String>> renames = new ArrayList<>();
renames.add(new Pair<>("a", "b"));
renames.add(new Pair<>("c", "d"));
AbstractJournalUpdateTask.writeControlFile(fileFactory, dataFiles, newFiles, renames);
ArrayList<String> strDataFiles = new ArrayList<>();
ArrayList<String> strNewFiles = new ArrayList<>();
ArrayList<Pair<String, String>> renamesRead = new ArrayList<>();
Assert.assertNotNull(JournalCompactor.readControlFile(fileFactory, strDataFiles, strNewFiles, renamesRead));
Assert.assertEquals(dataFiles.size(), strDataFiles.size());
Assert.assertEquals(newFiles.size(), strNewFiles.size());
Assert.assertEquals(renames.size(), renamesRead.size());
Iterator<String> iterDataFiles = strDataFiles.iterator();
for (JournalFile file : dataFiles) {
Assert.assertEquals(file.getFile().getFileName(), iterDataFiles.next());
}
Assert.assertFalse(iterDataFiles.hasNext());
Iterator<String> iterNewFiles = strNewFiles.iterator();
for (JournalFile file : newFiles) {
Assert.assertEquals(file.getFile().getFileName(), iterNewFiles.next());
}
Assert.assertFalse(iterNewFiles.hasNext());
Iterator<Pair<String, String>> iterRename = renames.iterator();
for (Pair<String, String> rename : renamesRead) {
Pair<String, String> original = iterRename.next();
Assert.assertEquals(original.getA(), rename.getA());
Assert.assertEquals(original.getB(), rename.getB());
}
Assert.assertFalse(iterNewFiles.hasNext());
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class ActiveMQTestBase method loadMessageJournal.
/**
* Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
* independent of being deleted or not
*
* @param config
* @return
* @throws Exception
*/
protected Pair<List<RecordInfo>, List<PreparedTransactionInfo>> loadMessageJournal(Configuration config) throws Exception {
JournalImpl messagesJournal = null;
try {
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null, 1);
messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
final List<RecordInfo> committedRecords = new LinkedList<>();
final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
messagesJournal.start();
messagesJournal.load(committedRecords, preparedTransactions, null, false);
return new Pair<>(committedRecords, preparedTransactions);
} finally {
try {
if (messagesJournal != null) {
messagesJournal.stop();
}
} catch (Throwable ignored) {
}
}
}
Aggregations