Search in sources :

Example 16 with MQAddress

use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.

the class ClusterUtil method getBrokerAddress.

public static String getBrokerAddress(String brokerID) {
    ClusterManager cmgr;
    ClusteredBroker bkr;
    MQAddress addr;
    if (brokerID == null) {
        return (null);
    }
    cmgr = Globals.getClusterManager();
    if (cmgr == null) {
        return (null);
    }
    bkr = cmgr.getBroker(brokerID);
    if (bkr == null) {
        return (null);
    }
    addr = bkr.getBrokerURL();
    if (addr == null) {
        return (null);
    }
    return (addr.toString());
}
Also used : MQAddress(com.sun.messaging.jmq.io.MQAddress) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)

Example 17 with MQAddress

use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.

the class PortMapper method setHostname.

/**
 * Change the portmapper service's host interface
 */
private synchronized void setHostname(String hostname, boolean initOnly) throws PropertyUpdateException {
    MQAddress mqaddr = null;
    try {
        String h = hostname;
        if (hostname != null && hostname.equals(Globals.HOSTNAME_ALL)) {
            h = null;
        }
        mqaddr = MQAddress.getMQAddress(h, getPort());
    } catch (Exception e) {
        throw new PropertyUpdateException(hostname + ": " + e.toString(), e);
    }
    if (hostname == null || hostname.equals(Globals.HOSTNAME_ALL) || hostname.trim().length() == 0) {
        // Bind to all
        this.hostname = null;
        this.bindAddr = null;
        mqaddress = mqaddr;
        if (!initOnly) {
            PUService pu = Globals.getPUService();
            if (pu != null) {
                try {
                    pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
                } catch (IOException e) {
                    logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
                }
            }
        }
        return;
    }
    if (hostname.equals(this.hostname)) {
        return;
    }
    try {
        if (Globals.isConfigForCluster()) {
            String hn = hostname;
            if (hn.equals("localhost")) {
                hn = null;
            }
            this.bindAddr = BrokerMQAddress.resolveBindAddress(hn, true);
            mqaddr = MQAddress.getMQAddress(this.bindAddr.getHostAddress(), getPort());
        } else {
            this.bindAddr = InetAddress.getByName(hostname);
        }
    } catch (Exception e) {
        throw new PropertyUpdateException(rb.getString(rb.E_BAD_HOSTNAME, hostname), e);
    }
    this.hostname = hostname;
    this.mqaddress = mqaddr;
    LockFile lf = LockFile.getCurrentLockFile();
    try {
        if (lf != null) {
            lf.updateHostname(mqaddress.getHostName(), Globals.getUseFileLockForLockFile());
        }
    } catch (IOException e) {
        logger.log(Logger.WARNING, rb.E_LOCKFILE_BADUPDATE, e);
    }
    if (serverSocket != null) {
        // one with the new port
        try {
            serverSocket.close();
        } catch (IOException e) {
        }
    }
    if (!initOnly) {
        PUService pu = Globals.getPUService();
        if (pu != null) {
            try {
                pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
            } catch (IOException e) {
                logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
            }
        }
    }
}
Also used : PUService(com.sun.messaging.portunif.PUService) MQAddress(com.sun.messaging.jmq.io.MQAddress) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress) LockFile(com.sun.messaging.jmq.jmsserver.util.LockFile) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 18 with MQAddress

use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.

the class UpdateClusterBrokerListHandler method handle.

/**
 * Handle the incomming administration message.
 *
 * @param con The Connection the message came in on.
 * @param cmd_msg The administration message
 * @param cmd_props The properties from the administration message
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    int status = Status.OK;
    String msg = null;
    if (DEBUG) {
        logger.log(Logger.INFO, this.getClass().getName() + ": " + cmd_props);
    }
    if (Globals.getHAEnabled()) {
        status = Status.ERROR;
        msg = rb.getKString(rb.E_OP_NOT_APPLY_TO_HA_BROKER, MessageType.getString(MessageType.UPDATE_CLUSTER_BROKERLIST));
        logger.log(Logger.ERROR, msg);
    } else if (!Globals.isJMSRAManagedBroker()) {
        status = Status.ERROR;
        msg = rb.getKString(rb.E_BROKER_NOT_JMSRA_MANAGED_IGNORE_OP, MessageType.getString(MessageType.UPDATE_CLUSTER_BROKERLIST));
        logger.log(Logger.ERROR, msg);
        msg = "BAD REQUEST";
    } else {
        try {
            ClusterManager cm = Globals.getClusterManager();
            MQAddress self = cm.getMQAddress();
            String brokerlist = (String) cmd_props.get(MessageType.JMQ_CLUSTER_BROKERLIST);
            Set brokers = cm.parseBrokerList(brokerlist);
            MQAddress master = (cm.getMasterBroker() == null ? null : cm.getMasterBroker().getBrokerURL());
            logger.log(logger.INFO, rb.getKString(rb.I_UPDATE_BROKERLIST, self + (master == null ? "]" : "(" + cm.CONFIG_SERVER + "=" + master + ")"), "[" + brokerlist + "]"));
            if (master != null && !brokers.contains(master)) {
                msg = rb.getKString(rb.X_REMOVE_MASTERBROKER_NOT_ALLOWED, master.toString(), brokers.toString() + "[" + brokerlist + "]");
                throw new BrokerException(msg);
            }
            if (!brokers.contains(self)) {
                brokerlist = "";
            }
            Properties prop = new Properties();
            prop.put(cm.AUTOCONNECT_PROPERTY, brokerlist);
            BrokerConfig bcfg = Globals.getConfig();
            bcfg.updateProperties(prop, true);
        } catch (PropertyUpdateException e) {
            status = Status.BAD_REQUEST;
            msg = e.getMessage();
            logger.log(Logger.WARNING, msg);
        } catch (Exception e) {
            status = Status.ERROR;
            msg = e.toString();
            logger.log(Logger.WARNING, msg);
        }
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.UPDATE_CLUSTER_BROKERLIST_REPLY, status, msg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) Set(java.util.Set) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) MQAddress(com.sun.messaging.jmq.io.MQAddress) Properties(java.util.Properties) ClusterManager(com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 19 with MQAddress

use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.

the class ClusterConfig method getLocalBrokerInfo.

public CompositeData getLocalBrokerInfo() throws MBeanException {
    ClusterManager cm = Globals.getClusterManager();
    CompositeData cd = null;
    if (cm == null) {
        return (null);
    }
    MQAddress address = cm.getMQAddress();
    String id = null;
    try {
        id = cm.lookupBrokerID(BrokerMQAddress.createAddress(address.toString()));
    } catch (Exception e) {
        handleGetterException(ClusterAttributes.LOCAL_BROKER_INFO, e);
    }
    if ((id == null) || (id.equals(""))) {
        return (null);
    }
    try {
        ClusteredBroker cb = cm.getBroker(id);
        if (cb == null) {
            return (null);
        }
        cd = ClusterUtil.getConfigCompositeData(cb);
    } catch (Exception e) {
        handleGetterException(ClusterAttributes.LOCAL_BROKER_INFO, e);
    }
    return (cd);
}
Also used : MQAddress(com.sun.messaging.jmq.io.MQAddress) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress) CompositeData(javax.management.openmbean.CompositeData) MBeanException(javax.management.MBeanException) PropertyUpdateException(com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 20 with MQAddress

use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.

the class SFSHAClusteredBrokerImpl method update.

@Override
public void update(HABrokerInfo m) {
    MQAddress oldaddr = address;
    synchronized (this) {
        this.brokerid = m.getId();
        String urlstr = m.getUrl();
        try {
            address = BrokerMQAddress.createAddress(urlstr);
        } catch (Exception ex) {
            logger.logStack(logger.WARNING, ex.getMessage(), ex);
            address = oldaddr;
        }
    }
    if (!oldaddr.equals(address)) {
        parent.brokerChanged(ClusterReason.ADDRESS_CHANGED, this.getBrokerName(), oldaddr, this.address, null, null);
    }
}
Also used : MQAddress(com.sun.messaging.jmq.io.MQAddress) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

MQAddress (com.sun.messaging.jmq.io.MQAddress)22 BrokerMQAddress (com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)16 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)11 MalformedURLException (java.net.MalformedURLException)4 UnknownHostException (java.net.UnknownHostException)3 MBeanException (javax.management.MBeanException)3 CompositeData (javax.management.openmbean.CompositeData)3 PropertyUpdateException (com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException)2 UID (com.sun.messaging.jmq.util.UID)2 Logger (com.sun.messaging.jmq.util.log.Logger)2 Packet (com.sun.messaging.jmq.io.Packet)1 ClusterManager (com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager)1 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)1 TakeoverLockException (com.sun.messaging.jmq.jmsserver.persist.api.TakeoverLockException)1 LockFile (com.sun.messaging.jmq.jmsserver.util.LockFile)1 StoreBeingTakenOverException (com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException)1 PUService (com.sun.messaging.portunif.PUService)1 Properties (java.util.Properties)1 Set (java.util.Set)1 OpenDataException (javax.management.openmbean.OpenDataException)1