Search in sources :

Example 1 with Bridge

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

the class BridgeServiceManagerImpl method resumeBridge.

public synchronized void resumeBridge(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_RESUME_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));
        }
        resumeBridge(b, args);
        return;
    }
    for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
        b = pair.getValue();
        if (type != null && !b.getType().equals(type)) {
            continue;
        }
        resumeBridge(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 2 with Bridge

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

the class BridgeServiceManagerImpl method listBridge.

public synchronized ArrayList<BridgeCmdSharedReplyData> listBridge(String name, String[] args, String type, BridgeManagerResources bmr) throws Exception {
    if (type != null && !type.equals(Bridge.JMS_TYPE) && !type.equals(Bridge.STOMP_TYPE)) {
        throw new IllegalArgumentException(_bmr.getString(_bmr.X_BRIDGE_INVALID_TYPE, type));
    }
    if (name == null) {
        _bc.logDebug("Listing all bridges (type=" + type + ")", null);
        BridgeCmdSharedReplyData reply = new BridgeCmdSharedReplyData(3, 4, "-");
        String[] oneRow = new String[3];
        oneRow[0] = bmr.getString(BridgeCmdSharedResources.I_BGMGR_TITLE_BRIDGE_NAME);
        oneRow[1] = bmr.getString(BridgeCmdSharedResources.I_BGMGR_TITLE_BRIDGE_TYPE);
        oneRow[2] = bmr.getString(BridgeCmdSharedResources.I_BGMGR_TITLE_BRIDGE_STATE);
        reply.addTitle(oneRow);
        Bridge b = null;
        for (Map.Entry<String, Bridge> pair : _bridges.entrySet()) {
            b = pair.getValue();
            if (type != null && !b.getType().equals(type)) {
                continue;
            }
            oneRow[0] = b.getName();
            oneRow[1] = b.getType();
            oneRow[2] = b.getState().toString(bmr);
            reply.add(oneRow);
        }
        _bc.logDebug("Listed all bridges (type=" + type + ")", null);
        ArrayList<BridgeCmdSharedReplyData> replys = new ArrayList<>();
        replys.add(reply);
        return replys;
    }
    if (args == null) {
        _bc.logInfo(_bmr.getString(_bmr.I_LISTING_BRIDGE, name), null);
    } else {
        _bc.logInfo(_bmr.getString(_bmr.I_LISTING_BRIDGE_WITH, name, BridgeUtil.toString(args)), null);
    }
    Bridge b = _bridges.get(name);
    if (b == null) {
        String emsg = _bmr.getKString(_bmr.X_BRIDGE_NAME_NOT_FOUND, name);
        _bc.logError(emsg, null);
        throw new BridgeException(emsg);
    }
    BridgeContext bc = new BridgeContextImpl(_bc, b.getName());
    return b.list(bc, args, bmr);
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) ArrayList(java.util.ArrayList) BridgeContext(com.sun.messaging.bridge.api.BridgeContext) BridgeCmdSharedReplyData(com.sun.messaging.bridge.api.BridgeCmdSharedReplyData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Bridge(com.sun.messaging.bridge.api.Bridge)

Example 3 with Bridge

use of com.sun.messaging.bridge.api.Bridge 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 4 with Bridge

use of com.sun.messaging.bridge.api.Bridge 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 5 with Bridge

use of com.sun.messaging.bridge.api.Bridge 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)

Aggregations

Bridge (com.sun.messaging.bridge.api.Bridge)8 BridgeException (com.sun.messaging.bridge.api.BridgeException)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 Properties (java.util.Properties)3 ConnectionFactory (com.sun.messaging.ConnectionFactory)1 BridgeCmdSharedReplyData (com.sun.messaging.bridge.api.BridgeCmdSharedReplyData)1 BridgeContext (com.sun.messaging.bridge.api.BridgeContext)1 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1