Search in sources :

Example 1 with PersistedBindings

use of org.apache.activemq.artemis.jms.persistence.config.PersistedBindings in project activemq-artemis by apache.

the class JMSServerManagerImpl method recoverBindings.

private void recoverBindings() throws Exception {
    // now its time to add journal recovered stuff
    List<PersistedBindings> bindingsSpace = storage.recoverPersistedBindings();
    for (PersistedBindings record : bindingsSpace) {
        Map<String, List<String>> mapBindings;
        Map<String, ?> objects;
        switch(record.getType()) {
            case Queue:
                mapBindings = queueBindings;
                objects = queues;
                break;
            case Topic:
                mapBindings = topicBindings;
                objects = topics;
                break;
            default:
            case ConnectionFactory:
                mapBindings = connectionFactoryBindings;
                objects = connectionFactories;
                break;
        }
        Object objectToBind = objects.get(record.getName());
        List<String> bindingsList = mapBindings.get(record.getName());
        if (objectToBind == null) {
            unRecoveredBindings.put(record.getName(), record.getBindings());
            continue;
        }
        if (bindingsList == null) {
            bindingsList = new ArrayList<>();
            mapBindings.put(record.getName(), bindingsList);
        }
        for (String bindings : record.getBindings()) {
            bindingsList.add(bindings);
            bindToBindings(bindings, objectToBind);
        }
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings)

Example 2 with PersistedBindings

use of org.apache.activemq.artemis.jms.persistence.config.PersistedBindings in project activemq-artemis by apache.

the class JMSStorageManagerTest method testJNDIPersistence.

// https://issues.jboss.org/browse/HORNETQ-812
@Test
public void testJNDIPersistence() throws Exception {
    createJMSStorage();
    jmsJournal.storeDestination(new PersistedDestination(PersistedType.Queue, "jndiPersistQueue", null, true));
    jmsJournal.addBindings(PersistedType.Queue, "jndiPersistQueue", "jndi-1");
    List<PersistedDestination> destinations = jmsJournal.recoverDestinations();
    List<PersistedBindings> jndiList = jmsJournal.recoverPersistedBindings();
    Assert.assertEquals(1, destinations.size());
    Assert.assertEquals(1, jndiList.size());
    jmsJournal.deleteDestination(PersistedType.Queue, "jndiPersistQueue");
    destinations = jmsJournal.recoverDestinations();
    Assert.assertEquals(0, destinations.size());
    jmsJournal.stop();
    createJMSStorage();
    destinations = jmsJournal.recoverDestinations();
    Assert.assertEquals(0, destinations.size());
    jndiList = jmsJournal.recoverPersistedBindings();
    Assert.assertEquals(1, jndiList.size());
    PersistedBindings jndi = jndiList.get(0);
    List<String> jndis = jndi.getBindings();
    Assert.assertEquals(1, jndis.size());
    Assert.assertEquals("jndi-1", jndis.get(0));
}
Also used : PersistedDestination(org.apache.activemq.artemis.jms.persistence.config.PersistedDestination) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) Test(org.junit.Test)

Example 3 with PersistedBindings

use of org.apache.activemq.artemis.jms.persistence.config.PersistedBindings in project activemq-artemis by apache.

the class JMSJournalStorageManagerImpl method deleteBindings.

@Override
public void deleteBindings(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) {
        return;
    } else {
        jmsJournal.appendDeleteRecordTransactional(tx, currentBindings.getId());
    }
    currentBindings.deleteBinding(address);
    if (currentBindings.getBindings().size() == 0) {
        mapBindings.remove(key);
    } else {
        long newId = idGenerator.generateID();
        currentBindings.setId(newId);
        jmsJournal.appendAddRecordTransactional(tx, newId, BINDING_RECORD, currentBindings);
    }
    jmsJournal.appendCommitRecord(tx, true);
}
Also used : PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 4 with PersistedBindings

use of org.apache.activemq.artemis.jms.persistence.config.PersistedBindings 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);
}
Also used : PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 5 with PersistedBindings

use of org.apache.activemq.artemis.jms.persistence.config.PersistedBindings 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);
        }
    }
}
Also used : PersistedDestination(org.apache.activemq.artemis.jms.persistence.config.PersistedDestination) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) ArrayList(java.util.ArrayList) PersistedConnectionFactory(org.apache.activemq.artemis.jms.persistence.config.PersistedConnectionFactory) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

PersistedBindings (org.apache.activemq.artemis.jms.persistence.config.PersistedBindings)5 Pair (org.apache.activemq.artemis.api.core.Pair)3 PersistedType (org.apache.activemq.artemis.jms.persistence.config.PersistedType)3 ArrayList (java.util.ArrayList)2 PersistedDestination (org.apache.activemq.artemis.jms.persistence.config.PersistedDestination)2 List (java.util.List)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)1 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)1 PersistedConnectionFactory (org.apache.activemq.artemis.jms.persistence.config.PersistedConnectionFactory)1 Test (org.junit.Test)1 NodeList (org.w3c.dom.NodeList)1