Search in sources :

Example 11 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method startBridge.

/**
 * @return true if started successful, false if asynchronously started
 *
 * @throws Exception if start failed
 */
public synchronized boolean startBridge(String name, String[] args, String type) throws Exception {
    if (type != null && !type.equals(Bridge.JMS_TYPE) && !type.equals(Bridge.STOMP_TYPE)) {
        throw new IllegalArgumentException(_bmr.getKString(_bmr.X_BRIDGE_INVALID_TYPE, type));
    }
    Bridge b = null;
    if (name != null) {
        b = _bridges.get(name);
        if (b == null) {
            throw new BridgeException(_bmr.getKString(_bmr.X_BRIDGE_NAME_NOT_FOUND, name));
        }
        if (type != null && !type.equals(b.getType())) {
            String[] eparam = new String[] { name, b.getType(), type };
            throw new BridgeException(_bmr.getKString(_bmr.X_BRIDGE_TYPE_MISMATCH, eparam));
        }
        return startBridge(b, args);
    }
    boolean async = false;
    for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
        b = pair.getValue();
        if (type != null && !b.getType().equals(type)) {
            continue;
        }
        if (!startBridge(b, args)) {
            async = true;
        }
    }
    return !async;
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Bridge(com.sun.messaging.bridge.api.Bridge)

Example 12 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method unloadBridge.

public synchronized void unloadBridge(String name) throws Exception {
    _bc.logInfo("Unloading bridge " + name, null);
    Bridge b = _bridges.get(name);
    if (b == null) {
        _bc.logInfo("Bridge " + name + " is not loaded.", null);
        throw new BridgeException("Bridge " + name + " is not loaded.", Status.NOT_MODIFIED);
    }
    stopBridge(name, null, null);
    _bridges.remove(name);
    b.setName(null);
    Properties props = _bc.getBridgeConfig();
    List<String> alist = BridgeUtil.getListProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + ".activelist", props);
    String tmpn = null;
    StringBuilder sbuf = new StringBuilder();
    Iterator<String> itr = alist.iterator();
    while (itr.hasNext()) {
        tmpn = itr.next();
        if (!tmpn.equals(name)) {
            if (sbuf.length() > 0) {
                sbuf.append(',');
            }
            sbuf.append(tmpn);
        }
    }
    Properties p = new Properties();
    p.setProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + ".activelist", sbuf.toString());
    _bc.updateBridgeConfig(p);
    _bc.logInfo("Unloaded bridge " + name, null);
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) Properties(java.util.Properties) Bridge(com.sun.messaging.bridge.api.Bridge)

Example 13 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method loadBridge.

/**
 */
public synchronized void loadBridge(String name) throws Exception {
    _bc.logInfo("Loading bridge " + name, null);
    Locale loc = _bmr.getLocale();
    Bridge b = _bridges.get(name);
    if (b != null) {
        _bc.logInfo("Bridge " + name + " is already loaded.", null);
        throw new BridgeException(_bmr.getString(_bmr.I_BRIDGE_ALREADY_LOADED, name), Status.NOT_MODIFIED);
    }
    /*
         * Properties props = _bc.getBridgeConfig();
         *
         * String activekey = props.getProperty( BridgeBaseContext.PROP_PREFIX)+".activelist"; List<String> alist =
         * BridgeUtil.getListProperty(activekey, props);
         *
         * String tmpn = null; boolean found = false; Iterator<String> itr = alist.iterator(); while (itr.hasNext()) { tmpn =
         * itr.next(); if (tmpn.equals(name)) { found = true; break; } } if (!found) { String oldactives =
         * props.getProperty(activekey); String newactives = oldactives+","+name; Properties p = new Properties();
         * p.setProperty(activekey, newactives); _bc.updateBridgeConfig(p); }
         */
    Properties props = _bc.getBridgeConfig();
    String type = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + name + ".type");
    if (type == null) {
        String emsg = _bmr.getKString(_bmr.E_LOAD_BRIDGE_NO_TYPE, name);
        _bc.logError(emsg, null);
        throw new BridgeException(emsg);
    }
    type = type.toLowerCase(loc);
    if (!type.toUpperCase(loc).equals(Bridge.JMS_TYPE) && !type.toUpperCase(loc).equals(Bridge.STOMP_TYPE)) {
        String emsg = _bmr.getKString(_bmr.X_BRIDGE_TYPE_NOSUPPORT, name, type);
        _bc.logError(emsg, null);
        throw new BridgeException(emsg);
    }
    String classn = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + type + ".class");
    if (classn == null) {
        String emsg = _bmr.getKString(_bmr.E_LOAD_BRIDGE_NO_CLASS, name);
        _bc.logError(emsg, null);
        throw new BridgeException(emsg);
    }
    if (_bc.isRunningOnNucleus()) {
        b = habitat.getService(Bridge.class, type.toUpperCase(loc));
    } else {
        b = (Bridge) Class.forName(classn).getDeclaredConstructor().newInstance();
    }
    if (!b.isMultipliable() && !b.getType().toLowerCase().equals(name.toLowerCase())) {
        String emsg = _bmr.getKString(_bmr.E_BRIDGE_NAME_TYPE_NOT_SAME, name, b.getType());
        _bc.logError(emsg, null);
        throw new BridgeException(emsg);
    }
    if (DEBUG) {
        _bc.logInfo("Loaded brigde " + name + " by classloader " + b.getClass().getClassLoader() + "(parent:" + this.getClass().getClassLoader() + ")", null);
    }
    b.setName(name);
    _bridges.put(name, b);
    _bc.logInfo("Loaded bridge " + name, null);
}
Also used : Locale(java.util.Locale) BridgeException(com.sun.messaging.bridge.api.BridgeException) Properties(java.util.Properties) Bridge(com.sun.messaging.bridge.api.Bridge)

Example 14 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method pauseBridge.

public synchronized void pauseBridge(String name, String[] args, String type) throws Exception {
    if (type != null && !type.equals(Bridge.JMS_TYPE) && !type.equals(Bridge.STOMP_TYPE)) {
        throw new IllegalArgumentException(_bmr.getKString(_bmr.X_BRIDGE_INVALID_TYPE, type));
    }
    if (name == null && type == null) {
        throw new UnsupportedOperationException(_bmr.getKString(_bmr.X_BRIDGE_PAUSE_NO_TYPE));
    }
    Bridge b = null;
    if (name != null) {
        b = _bridges.get(name);
        if (b == null) {
            throw new BridgeException(_bmr.getKString(_bmr.X_BRIDGE_NAME_NOT_FOUND, name));
        }
        if (type != null && !type.equals(b.getType())) {
            String[] eparam = new String[] { name, b.getType(), type };
            throw new BridgeException(_bmr.getKString(_bmr.X_BRIDGE_TYPE_MISMATCH, eparam));
        }
        pauseBridge(b, args);
        return;
    }
    for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
        b = pair.getValue();
        if (type != null && !b.getType().equals(type)) {
            continue;
        }
        pauseBridge(b, args);
    }
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Bridge(com.sun.messaging.bridge.api.Bridge)

Example 15 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method start.

/**
 * Start the bridge service manager
 */
@Override
public synchronized void start() throws Exception {
    if (_bc == null || _state == State.UNINITIALIZED) {
        throw new BridgeException(_bmr.getString(_bmr.X_BRIDGE_SERVICE_MANAGER_NOT_INITED));
    }
    _state = State.STARTING;
    Properties props = _bc.getBridgeConfig();
    try {
        Bridge b = null;
        String name = null;
        for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
            b = pair.getValue();
            name = b.getName();
            String autostart = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + name + ".autostart", "true");
            boolean doautostart = Boolean.valueOf(autostart);
            try {
                if (doautostart) {
                    String[] args = null;
                    if (_bc.isStartWithReset()) {
                        args = new String[] { "-reset" };
                    }
                    startBridge(b, args);
                }
            } catch (BridgeException e) {
                if (e.getStatus() == Status.CREATED) {
                    continue;
                }
                throw e;
            }
        }
    } catch (Exception e) {
        try {
            stopBridge(null, null, null);
        } catch (Throwable t) {
        }
        throw e;
    }
    try {
        var _cf = new ConnectionFactory();
        _cf.setProperty(com.sun.messaging.ConnectionConfiguration.imqAddressList, _bc.getBrokerServiceAddress("tcp", com.sun.messaging.jmq.ClientConstants.CONNECTIONTYPE_ADMIN));
        _cf.setProperty(com.sun.messaging.ConnectionConfiguration.imqReconnectEnabled, "false");
        _connection = _cf.createConnection(_user, _passwd);
        _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        _adminQueue = _session.createTemporaryQueue();
        MessageConsumer mc = _session.createConsumer(_adminQueue);
        mc.setMessageListener(this);
        _connection.start();
    } catch (Exception e) {
        try {
            stopBridge(null, null, null);
            if (_connection != null) {
                _connection.close();
            }
        } catch (Throwable t) {
        }
        throw e;
    }
    _state = State.STARTED;
}
Also used : Properties(java.util.Properties) BridgeException(com.sun.messaging.bridge.api.BridgeException) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) BridgeException(com.sun.messaging.bridge.api.BridgeException) ConnectionFactory(com.sun.messaging.ConnectionFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Bridge(com.sun.messaging.bridge.api.Bridge)

Aggregations

BridgeException (com.sun.messaging.bridge.api.BridgeException)16 Bridge (com.sun.messaging.bridge.api.Bridge)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 Properties (java.util.Properties)5 Message (jakarta.jms.Message)3 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)2 Destination (jakarta.jms.Destination)2 JMSException (jakarta.jms.JMSException)2 MessageProducer (jakarta.jms.MessageProducer)2 HeuristicMixedException (jakarta.transaction.HeuristicMixedException)2 HeuristicRollbackException (jakarta.transaction.HeuristicRollbackException)2 RollbackException (jakarta.transaction.RollbackException)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 ConnectionFactory (com.sun.messaging.ConnectionFactory)1 AdminMessageHandler (com.sun.messaging.bridge.admin.handlers.AdminMessageHandler)1 BridgeManagerResources (com.sun.messaging.bridge.admin.resources.BridgeManagerResources)1 BridgeCmdSharedReplyData (com.sun.messaging.bridge.api.BridgeCmdSharedReplyData)1