Search in sources :

Example 46 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ClusterImpl method checkStoredLastConfigServer.

/**
 * Check to see if stored last config server property loaded properly
 *
 * System.exit if the last config server info is corrupted the last refresh timestamp info is corrupted and unable to
 * reset potentially last config server info is corrupted: store LoadPropertyException occurred with key corruption and
 * LastConfigServer property does not in store
 *
 * In future release, the System.exit behavior may be changed to allow administratively repair - eg. through imqbrokerd
 * option to force set last config server info to the current master broker
 */
private void checkStoredLastConfigServer() throws BrokerException {
    Store s = Globals.getStore();
    boolean bad = false;
    boolean potentiallyBad = false;
    LoadException le = s.getLoadPropertyException();
    LoadException savele = null;
    while (le != null) {
        Object o = le.getKey();
        if (o == null || !(o instanceof String)) {
            potentiallyBad = true;
            savele = le;
            le = le.getNextException();
            continue;
        }
        if (((String) o).equals(ClusterGlobals.STORE_PROPERTY_LASTCONFIGSERVER)) {
            logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER, le);
            bad = true;
            break;
        }
        if (((String) o).equals(ClusterGlobals.STORE_PROPERTY_LASTREFRESHTIME)) {
            logger.log(Logger.WARNING, BrokerResources.W_CLUSTER_LOAD_LASTREFRESHTIME, le);
            try {
                s.updateProperty(ClusterGlobals.STORE_PROPERTY_LASTREFRESHTIME, Long.valueOf(-1), false);
            } catch (BrokerException e) {
                logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_RESET_LASTREFRESHTIME, e);
                bad = true;
                break;
            }
        }
        le = le.getNextException();
    }
    if (potentiallyBad && !bad) {
        try {
            if (s.getProperty(ClusterGlobals.STORE_PROPERTY_LASTCONFIGSERVER) == null) {
                logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER, savele);
                bad = true;
            }
        } catch (BrokerException e) {
            logger.log(Logger.ERROR, e.getMessage(), e);
            logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER, savele);
            bad = true;
        }
    }
    if (bad) {
        logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER);
        Broker.getBroker().exit(1, Globals.getBrokerResources().getKString(BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER), BrokerEvent.Type.FATAL_ERROR);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Store(com.sun.messaging.jmq.jmsserver.persist.api.Store) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException)

Example 47 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ClusterImpl method processFirstInfoPacket.

protected void processFirstInfoPacket(GPacket gp, BrokerLink link) {
    try {
        if (!Globals.useSharedConfigRecord()) {
            // should never happen
            throw new BrokerException("Unexpected " + ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + " packet from " + link.getRemote());
        }
        ClusterFirstInfoInfo cii = ClusterFirstInfoInfo.newInstance(gp);
        ChangeRecordInfo cri = cii.getLastStoredChangeRecord();
        if (cri == null) {
            return;
        }
        logger.log(logger.INFO, br.getKString(br.I_CLUSTER_RECEIVED_FIRST_INFO, ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + "[(sharecc)" + cri.toString() + "]", link.getRemote()));
        cb.syncChangeRecordOnJoin(link.getRemote(), cri);
    } catch (Exception e) {
        logger.logStack(logger.ERROR, e.getMessage(), e);
        if (e instanceof BrokerException) {
            if (((BrokerException) e).getStatusCode() == Status.PRECONDITION_FAILED) {
                link.shutdown();
                return;
            }
        }
        link.closeConn();
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ClusterFirstInfoInfo(com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterFirstInfoInfo)

Example 48 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ClusterImpl method processLinkInit.

/**
 * Process the Packet.LINK_INIT packet.
 */
protected static LinkInfo processLinkInit(Packet p) throws Exception {
    String hostName = null;
    String instName = null;
    String brokerID = null;
    UID brokerSessionUID = null;
    UID storeSessionUID = null;
    boolean ha = false;
    int port = 0;
    BrokerAddressImpl remote = null;
    ByteArrayInputStream bis = new ByteArrayInputStream(p.getPacketBody());
    DataInputStream dis = new DataInputStream(bis);
    int clusterVersion = dis.readInt();
    hostName = dis.readUTF();
    instName = dis.readUTF();
    port = dis.readInt();
    BrokerAddressImpl configServer = null;
    boolean hasConfigServer = false;
    String cfgHostName = null;
    String cfgInstName = null;
    int cfgPort = 0;
    hasConfigServer = dis.readBoolean();
    if (hasConfigServer) {
        cfgHostName = dis.readUTF();
        cfgInstName = dis.readUTF();
        cfgPort = dis.readInt();
    }
    Properties props = new Properties();
    int nprops = dis.readInt();
    for (int i = 0; i < nprops; i++) {
        String prop = dis.readUTF();
        String value = dis.readUTF();
        props.setProperty(prop, value);
    }
    if (clusterVersion >= ProtocolGlobals.VERSION_400) {
        ha = dis.readBoolean();
        if (dis.readBoolean()) {
            brokerID = dis.readUTF();
        }
        brokerSessionUID = new UID(dis.readLong());
        if (ha) {
            storeSessionUID = new UID(dis.readLong());
        } else {
            try {
                if (dis.readBoolean()) {
                    storeSessionUID = new UID(dis.readLong());
                }
            } catch (Exception e) {
            }
        }
    }
    if (hasConfigServer) {
        if (ha) {
            throw new BrokerException(br.getKString(br.E_CLUSTER_HA_NOT_SUPPORT_MASTERBROKER));
        }
        configServer = new BrokerAddressImpl(cfgHostName, cfgInstName, cfgPort, ha, null, null, null);
    }
    remote = new BrokerAddressImpl(hostName, instName, port, ha, brokerID, brokerSessionUID, storeSessionUID);
    remote.setClusterVersion(clusterVersion);
    LinkInfo li = new LinkInfo(remote, configServer, props);
    if (clusterVersion < 0) {
        int type = clusterVersion;
        li.setServiceRequestType(type);
    }
    return li;
}
Also used : UID(com.sun.messaging.jmq.util.UID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 49 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ClusterImpl method receiveBrokerInfoReply.

private void receiveBrokerInfoReply(BrokerAddressImpl sender, GPacket gp, String realRemote) {
    BrokerInfo info = null;
    try {
        ClusterBrokerInfoReply cbi = ClusterBrokerInfoReply.newInstance(gp);
        info = cbi.getBrokerInfo();
        info.setRealRemoteString(realRemote);
        if (DEBUG) {
            logger.log(Logger.DEBUG, "Received BROKER_INFO_REPLY from " + sender);
        }
        if (!info.getBrokerAddr().equals(sender)) {
            logger.log(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "mismatched BROKER_INFO (" + info.getBrokerAddr() + ") from " + sender);
            throw new BrokerException("mismatched BROKER_INFO");
        }
        if (Globals.getHAEnabled() && cbi.isTakingover()) {
            String msg = br.getKString(BrokerResources.E_CLUSTER_TAKINGOVER_NOTIFY_RESTART, sender);
            BrokerException ex = new BrokerException(msg);
            logger.log(logger.ERROR, msg);
            Broker.getBroker().exit(Globals.getBrokerStateHandler().getRestartCode(), msg, BrokerEvent.Type.RESTART, null, true, true, true);
            throw ex;
        }
    } catch (Exception e) {
        logger.logStack(Logger.ERROR, e.getMessage(), e);
        synchronized (brokerList) {
            BrokerLink link = (BrokerLink) brokerList.get(sender);
            if (link != null) {
                link.shutdown();
            }
        }
        return;
    }
    int status = cb.addBrokerInfo(info);
    if (status == cb.ADD_BROKER_INFO_OK) {
        return;
    }
    if (status == cb.ADD_BROKER_INFO_RETRY) {
        synchronized (brokerList) {
            BrokerLink link = (BrokerLink) brokerList.get(sender);
            if (link != null) {
                link.closeConn();
            }
        }
    } else if (status == cb.ADD_BROKER_INFO_BAN) {
        synchronized (brokerList) {
            BrokerLink link = (BrokerLink) brokerList.get(sender);
            if (link != null) {
                link.shutdown();
            }
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ClusterBrokerInfoReply(com.sun.messaging.jmq.jmsserver.multibroker.ClusterBrokerInfoReply) LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerInfo(com.sun.messaging.jmq.jmsserver.multibroker.BrokerInfo)

Example 50 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ClusterImpl method changeMasterBroker.

@Override
public void changeMasterBroker(BrokerAddress newmaster, BrokerAddress oldmaster) throws BrokerException {
    synchronized (configServerLock) {
        logger.log(logger.INFO, br.getKString(br.I_CLUSTER_CHANGE_MASTER_BROKER, (configServer == null ? "null" : configServer.toString()), newmaster.toString()));
        if (configServer == null) {
            throw new BrokerException(br.getKString(br.X_CLUSTER_NO_MASTER_BROKER_REJECT_CHANGE_MASTER), Status.PRECONDITION_FAILED);
        }
        if (!oldmaster.equals(configServer)) {
            throw new BrokerException(br.getKString(br.X_CLUSTER_CHANGE_MASTER_BROKER_MISMATCH, oldmaster.toString(), configServer.toString()), Status.PRECONDITION_FAILED);
        }
        BrokerAddressImpl oldconfigServer = this.configServer;
        this.configServer = (BrokerAddressImpl) newmaster;
        String newmasterhp = newmaster.getMQAddress().getHostAddressNPort();
        String oldmasterhp = Globals.getConfig().getProperty(ClusterManager.CONFIG_SERVER);
        Properties prop = new Properties();
        prop.put(ClusterManager.CONFIG_SERVER, newmasterhp);
        try {
            Globals.getConfig().updateProperties(prop, true);
        } catch (Exception e) {
            String emsg = br.getKString(br.E_CHANGE_MASTER_BROKER_FAIL, e.getMessage());
            logger.logStack(logger.ERROR, emsg, e);
            try {
                prop.put(ClusterManager.CONFIG_SERVER, oldmasterhp);
            } catch (Exception e1) {
                logger.log(logger.ERROR, br.getKString(br.E_CLUSTER_RESTORE_MASTER_BROKER_PROP_FAIL, e1.getMessage()));
                throw new BrokerException(emsg, e, Status.ERROR);
            }
            this.configServer = oldconfigServer;
            throw new BrokerException(emsg, e, Status.PRECONDITION_FAILED);
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)290 IOException (java.io.IOException)72 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)33 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)31 SizeString (com.sun.messaging.jmq.util.SizeString)31 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)29 Iterator (java.util.Iterator)26 ArrayList (java.util.ArrayList)25 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)24 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)23 HashMap (java.util.HashMap)22 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)21 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)21 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)21 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)18 List (java.util.List)18 Packet (com.sun.messaging.jmq.io.Packet)16 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)16 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)15