Search in sources :

Example 11 with HAClusteredBroker

use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.

the class JDBCHABrokerInfoMap method get.

/**
 * Retrieves the HAClusteredBroker associated with the passed in broker id. If the id is not found in the hashtable, the
 * database will be checked.
 *
 * @param key the brokerid to lookup
 * @param update update against store
 * @return the HAClusteredBroker object (or null if one can't be found)
 */
@Override
public Object get(Object key, boolean update) {
    Object o = super.get(key);
    if (o == null || update) {
        try {
            HABrokerInfo m = Globals.getStore().getBrokerInfo((String) key);
            if (m != null && o == null) {
                HAClusteredBroker cb = new HAClusteredBrokerImpl((String) key, m, parent);
                put(key, cb);
                parent.brokerChanged(ClusterReason.ADDED, cb.getBrokerName(), null, cb, cb.getBrokerSessionUID(), null);
                o = cb;
            }
            if (m != null && update) {
                ((HAClusteredBrokerImpl) o).update(m);
            }
        } catch (BrokerException ex) {
            Globals.getLogger().logStack(Logger.WARNING, "Exception while creating broker entry " + key, ex);
        }
    }
    return o;
}
Also used : HABrokerInfo(com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HAClusteredBroker(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker)

Example 12 with HAClusteredBroker

use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.

the class SFSHABrokerInfoMap method updateHAMapForState.

private void updateHAMapForState(BrokerState state) throws BrokerException {
    Map map = null;
    if (state == null) {
        map = Globals.getStore().getAllBrokerInfos();
    } else {
        map = Globals.getStore().getAllBrokerInfoByState(state);
    }
    Iterator itr = map.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        String key = (String) entry.getKey();
        HABrokerInfo bi = (HABrokerInfo) entry.getValue();
        HAClusteredBrokerImpl impl = (HAClusteredBrokerImpl) get(key);
        if (impl == null) {
            HAClusteredBroker cb = new SFSHAClusteredBrokerImpl(bi.getId(), bi, parent);
            put(key, cb);
            parent.brokerChanged(ClusterReason.ADDED, cb.getBrokerName(), null, cb, cb.getBrokerSessionUID(), null);
        } else {
            impl.update(bi);
        }
    }
    if (state == null) {
        itr = entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry) itr.next();
            String key = (String) entry.getKey();
            if (!map.containsKey(key)) {
                itr.remove();
                HAClusteredBrokerImpl impl = (HAClusteredBrokerImpl) entry.getValue();
                parent.brokerChanged(ClusterReason.REMOVED, impl.getBrokerName(), impl, null, impl.getBrokerSessionUID(), null);
            }
        }
    }
}
Also used : HABrokerInfo(com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo) Iterator(java.util.Iterator) HAClusteredBroker(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker) HashMap(java.util.HashMap) Map(java.util.Map) AutoClusterBrokerMap(com.sun.messaging.jmq.jmsserver.cluster.manager.AutoClusterBrokerMap)

Aggregations

HAClusteredBroker (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker)12 HABrokerInfo (com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo)6 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)6 AutoClusterBrokerMap (com.sun.messaging.jmq.jmsserver.cluster.manager.AutoClusterBrokerMap)4 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 PropertyUpdateException (com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException)2 UID (com.sun.messaging.jmq.util.UID)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GPacket (com.sun.messaging.jmq.io.GPacket)1