Search in sources :

Example 1 with AdminMessageHandler

use of com.sun.messaging.bridge.admin.handlers.AdminMessageHandler in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method init.

/**
 * Initialize the bridge service manager
 */
@Override
public synchronized void init(BridgeBaseContext ctx) throws Exception {
    com.sun.messaging.jmq.jmsclient.Debug.setUseLogger(true);
    FaultInjection.setBridgeBaseContext(ctx);
    _bc = ctx;
    Properties props = _bc.getBridgeConfig();
    String activekey = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ".activelist";
    List<String> alist = BridgeUtil.getListProperty(activekey, props);
    int size = alist.size();
    String name = null;
    Iterator<String> itr = alist.iterator();
    while (itr.hasNext()) {
        name = itr.next();
        try {
            loadBridge(name);
        } catch (BridgeException e) {
            if (e.getStatus() == Status.NOT_MODIFIED) {
                continue;
            }
            _bc.logError(_bmr.getKString(_bmr.E_LOAD_BRIDGE_FAILED, name, e.getMessage()), null);
            throw e;
        }
    }
    if (_bc.isHAEnabled()) {
        JMSBridgeStore store = (JMSBridgeStore) _bc.getJDBCStore();
        if (store == null) {
            throw new BridgeException("null JDBC store");
        }
        List jmsbridges = store.getJMSBridges(null);
        name = null;
        itr = alist.iterator();
        while (itr.hasNext()) {
            name = itr.next();
            String type = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + name + ".type");
            if (type == null) {
                throw new BridgeException(_bmr.getString(_bmr.X_BRIDGE_NO_TYPE, name));
            }
            if (!type.trim().toUpperCase(_bmr.getLocale()).equals(Bridge.JMS_TYPE)) {
                continue;
            }
            if (jmsbridges.contains(name)) {
                continue;
            }
            try {
                store.addJMSBridge(name, true, null);
            } catch (DupKeyException e) {
                _bc.logInfo(_bmr.getKString(_bmr.I_JMSBRIDGE_NOT_OWNER, name), null);
                itr.remove();
            }
        }
        jmsbridges = store.getJMSBridges(null);
        itr = jmsbridges.iterator();
        while (itr.hasNext()) {
            name = itr.next();
            if (alist.contains(name)) {
                continue;
            }
            alist.add(name);
            try {
                loadBridge(name);
            } catch (BridgeException e) {
                _bc.logError(_bmr.getKString(_bmr.E_LOAD_BRIDGE_FAILED, name, e.getMessage()), null);
                throw e;
            }
        }
        if (alist.size() != size) {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            itr = alist.iterator();
            while (itr.hasNext()) {
                if (i > 0) {
                    sb.append(',');
                }
                sb.append(itr.next());
                i++;
            }
            Properties p = new Properties();
            p.setProperty(activekey, sb.toString());
            _bc.updateBridgeConfig(p);
        }
    }
    String keyu = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ctx.PROP_ADMIN_USER_SUFFIX;
    String keyp = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ctx.PROP_ADMIN_PASSWORD_SUFFIX;
    _user = props.getProperty(keyu);
    _passwd = props.getProperty(keyp);
    if (_user == null || _user.trim().length() == 0) {
        throw new JMSException(_bmr.getString(_bmr.X_BRIDGE_NO_ADMIN_USER, keyu));
    }
    _user = _user.trim();
    if (_passwd == null || _passwd.trim().length() == 0) {
        throw new JMSException(_bmr.getString(_bmr.X_BRIDGE_NO_ADMIN_PASSWORD, keyp));
    }
    _passwd = _passwd.trim();
    _adminHandler = new AdminMessageHandler(this);
    _state = State.STOPPED;
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) AdminMessageHandler(com.sun.messaging.bridge.admin.handlers.AdminMessageHandler) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) JMSBridgeStore(com.sun.messaging.bridge.api.JMSBridgeStore) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties)

Aggregations

AdminMessageHandler (com.sun.messaging.bridge.admin.handlers.AdminMessageHandler)1 BridgeException (com.sun.messaging.bridge.api.BridgeException)1 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)1 JMSBridgeStore (com.sun.messaging.bridge.api.JMSBridgeStore)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1