Search in sources :

Example 66 with BrokerException

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

the class DestinationList method remoteCheckTakeoverMsgs.

public static void remoteCheckTakeoverMsgs(Map<String, String> msgs, String brokerid, PartitionedStore ps) throws BrokerException {
    Set destroyConns = new HashSet();
    Map<String, String> badsysids = null;
    Iterator<Map.Entry<String, String>> itr = msgs.entrySet().iterator();
    Map.Entry<String, String> me = null;
    String sysidstr = null, duidstr = null;
    SysMessageID sysid = null;
    DestinationUID duid = null;
    while (itr.hasNext()) {
        me = itr.next();
        sysidstr = me.getKey();
        duidstr = me.getValue();
        try {
            sysid = SysMessageID.get(sysidstr);
        } catch (InvalidSysMessageIDException e) {
            Globals.getLogger().logStack(Logger.ERROR, e.getMessage(), e);
            if (!Globals.getStore().getStoreType().equals(Store.JDBC_STORE_TYPE)) {
                throw e;
            }
            duid = new DestinationUID(duidstr);
            Globals.getLogger().log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.X_TAKEOVER_MSGID_CORRUPT_TRY_REPAIR, sysidstr, duidstr));
            try {
                Packet p = null;
                try {
                    p = ps.getMessage(duid, sysidstr);
                } catch (BrokerException ee) {
                    Throwable cause = ee.getCause();
                    String[] args = { sysidstr, "[?]", duidstr, cause.toString() };
                    String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_REPAIR_CORRUPTED_MSGID_IN_STORE, args);
                    Globals.getLogger().logStack(Logger.ERROR, emsg, ee);
                    if (cause instanceof InvalidPacketException) {
                        handleInvalidPacket(sysidstr, duidstr, emsg, (InvalidPacketException) cause, ps);
                        itr.remove();
                        continue;
                    } else {
                        throw ee;
                    }
                }
                sysid = p.getSysMessageID();
                String realsysidstr = sysid.getUniqueName();
                String[] args3 = { sysidstr, realsysidstr, duidstr };
                Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.X_REPAIR_CORRUPTED_MSGID_TO, args3));
                ps.repairCorruptedSysMessageID(sysid, sysidstr, duidstr, true);
                if (badsysids == null) {
                    badsysids = new HashMap<>();
                }
                badsysids.put(sysidstr, realsysidstr);
            } catch (BrokerException ee) {
                Globals.getLogger().logStack(Logger.ERROR, e.getMessage(), ee);
                throw e;
            }
        }
        PacketReference ref = get(null, sysid);
        if (ref == null) {
            continue;
        }
        Iterator cnitr = ref.getRemoteConsumerUIDs().values().iterator();
        while (cnitr.hasNext()) {
            destroyConns.add(cnitr.next());
        }
    }
    if (badsysids != null) {
        itr = badsysids.entrySet().iterator();
        String v = null;
        while (itr.hasNext()) {
            me = itr.next();
            v = msgs.remove(me.getKey());
            msgs.put(me.getValue(), v);
        }
    }
    destroyConnections(destroyConns, GoodbyeReason.BKR_IN_TAKEOVER, GoodbyeReason.toString(GoodbyeReason.BKR_IN_TAKEOVER) + ":" + brokerid);
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SizeString(com.sun.messaging.jmq.util.SizeString) InvalidPacketException(com.sun.messaging.jmq.io.InvalidPacketException) InvalidSysMessageIDException(com.sun.messaging.jmq.io.InvalidSysMessageIDException) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 67 with BrokerException

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

the class DestinationList method createDMQ.

private synchronized Queue createDMQ() throws BrokerException, IOException {
    if (pstore == null) {
        throw new RuntimeException("IllegalStateException: " + "DestinaionList.createDMQ: no store partition set");
    }
    DestinationUID uid = DestinationUID.getUID(DMQ_NAME, true);
    Queue dmq = null;
    dmq = (Queue) destinationList.get(uid);
    try {
        if (dmq == null) {
            Globals.getLogger().log(Logger.INFO, BrokerResources.I_DMQ_CREATING_DMQ);
            dmq = (Queue) createDestination(DMQ_NAME, DestType.DEST_TYPE_QUEUE | DestType.DEST_DMQ, true, false, null, false, false);
            dmq.maxProducerLimit = 0;
            dmq.scope = (Globals.getHAEnabled() ? DestScope.CLUSTER : DestScope.LOCAL);
            dmq.msgSizeLimit = null;
            dmq.setLimitBehavior(DestLimitBehavior.REMOVE_OLDEST);
            dmq.setByteCapacity(new SizeString(_defKByteDMQCapacity));
            dmq.setCapacity(1000);
            dmq.maxPrefetch = 1000;
            // deal with remaining properties
            dmq.isDMQ = true;
            dmq.useDMQ = false;
            dmq.update();
        }
    } catch (BrokerException ex) {
        if (ex.getStatusCode() == Status.CONFLICT) {
            // another broker may have created this while we were loading
            Globals.getLogger().logStack(Logger.DEBUG, "Another broker may have created the DMQ, reloading", ex);
            dmq = (Queue) pstore.getDestination(uid);
            if (dmq == null) {
                ex.overrideStatusCode(Status.ERROR);
                throw ex;
            }
            dmq.setDestinationList(this);
        } else {
            throw ex;
        }
    }
    dmq.load(true, null, null);
    return dmq;
}
Also used : SizeString(com.sun.messaging.jmq.util.SizeString) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 68 with BrokerException

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

the class DestinationList method addStorePartition.

public static void addStorePartition(PartitionedStore ps, boolean errdup) throws BrokerException {
    acquirePartitionLock(false);
    try {
        synchronized (destinationListList) {
            if (destinationListList.get(ps) != null) {
                String emsg = "Partition " + ps + " has already been loaded";
                if (errdup) {
                    throw new BrokerException(emsg);
                }
                Globals.getLogger().log(Logger.INFO, emsg);
                return;
            }
            DestinationList dl = new DestinationList(ps);
            TransactionList tl = new TransactionList(dl);
            dl.setTransactionList(tl);
            dl.loadDestinations();
            Subscription.initDuraSubscriptions(dl);
            Subscription.initNonDuraSharedSubscriptions(dl);
            Consumer.attachConsumers(dl);
            destinationListList.put(ps, dl);
            tl.postProcess();
            addPartitionListener(tl);
            notifyPartitionAdded(ps, dl);
        }
    } finally {
        releasePartitionLock(false);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SizeString(com.sun.messaging.jmq.util.SizeString) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 69 with BrokerException

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

the class DestinationList method init.

public static void init() throws BrokerException {
    if (inited) {
        if (shutdown) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER));
        }
        return;
    }
    shutdown = false;
    inited = true;
    if (canAutoCreate(true)) {
        Globals.getLogger().log(Logger.INFO, BrokerResources.I_QUEUE_AUTOCREATE_ENABLED);
    }
    if (!canAutoCreate(false)) {
        Globals.getLogger().log(Logger.INFO, BrokerResources.I_TOPIC_AUTOCREATE_DISABLED);
    }
    BrokerConfig cfg = Globals.getConfig();
    // OK add listeners for the properties
    cfg.addListener(SYSTEM_MAX_SIZE, cl);
    cfg.addListener(SYSTEM_MAX_COUNT, cl);
    cfg.addListener(MAX_MESSAGE_SIZE, cl);
    cfg.addListener(AUTO_QUEUE_STR, cl);
    cfg.addListener(AUTO_TOPIC_STR, cl);
    cfg.addListener(DST_REAP_STR, cl);
    cfg.addListener(MSG_REAP_STR, cl);
    cfg.addListener(AUTO_MAX_NUM_MSGS, cl);
    cfg.addListener(AUTO_MAX_TOTAL_BYTES, cl);
    cfg.addListener(AUTO_MAX_BYTES_MSG, cl);
    cfg.addListener(AUTO_MAX_NUM_PRODUCERS, cl);
    cfg.addListener(AUTO_LOCAL_ONLY, cl);
    cfg.addListener(AUTO_LIMIT_BEHAVIOR, cl);
    cfg.addListener(USE_DMQ_STR, cl);
    cfg.addListener(TRUNCATE_BODY_STR, cl);
    cfg.addListener(LOG_MSGS_STR, cl);
    cfg.addListener(DEBUG_LISTS_PROP, cl);
    cfg.addListener(CHECK_MSGS_RATE_AT_DEST_CAPACITY_RATIO_PROP, cl);
    cfg.addListener(CHECK_MSGS_RATE_FOR_ALL_PROP, cl);
    // now configure the system based on the properties
    setMaxSize(cfg.getSizeProperty(SYSTEM_MAX_SIZE));
    setMaxMessages(cfg.getIntProperty(SYSTEM_MAX_COUNT));
    setIndividualMessageMax(cfg.getSizeProperty(MAX_MESSAGE_SIZE));
    Queue.init();
    if (Globals.getStore().getPartitionModeEnabled()) {
        try {
            String typ = cfg.getProperty(CONN_STRATEGY_PROP, CONN_STRATEGY_DEFAULT);
            String cl = null;
            if (typ.equalsIgnoreCase(MIN_CONN_STRATEGY)) {
                cl = MIN_CONN_STRATEGY_CLASS;
            } else if (typ.equalsIgnoreCase(RR_CONN_STRATEGY)) {
                cl = RR_CONN_STRATEGY_CLASS;
            } else {
                Globals.getLogger().log(Logger.WARNING, "XXXIngore unknown " + typ + " for " + CONN_STRATEGY_PROP);
                cl = MIN_CONN_STRATEGY_CLASS;
            }
            if (Globals.isNucleusManagedBroker()) {
                partitionStrategy = Globals.getHabitat().getService(ConnToPartitionStrategy.class, cl);
            } else {
                partitionStrategy = (ConnToPartitionStrategy) Class.forName(cl).getDeclaredConstructor().newInstance();
            }
        } catch (Exception e) {
            throw new BrokerException(e.getMessage(), e);
        }
    }
    DestinationList dl = null;
    List<PartitionedStore> partitions = Globals.getStore().getAllStorePartitions();
    if (Globals.getStore().getPartitionModeEnabled()) {
        partitionMode = true;
        if (Globals.getStore().isPartitionMigratable()) {
            partitionMigratable = true;
        }
    } else if (partitions.size() > 1) {
        BrokerException ex = new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.E_INTERNAL_BROKER_ERROR, "Unexpected " + partitions.size() + "store partitions when partition mode disabled"));
        Globals.getLogger().logStack(Logger.ERROR, ex.getMessage(), ex);
        throw ex;
    }
    partitionModeInited = true;
    PartitionedStore partition = null;
    Iterator<PartitionedStore> itr1 = partitions.iterator();
    while (itr1.hasNext()) {
        partition = itr1.next();
        dl = new DestinationList(partition);
        destinationListList.put(partition, dl);
    }
    TransactionList tl = null;
    Iterator<DestinationList> itr2 = destinationListList.values().iterator();
    while (itr2.hasNext()) {
        dl = itr2.next();
        tl = new TransactionList(dl);
        dl.setTransactionList(tl);
    }
    Iterator<DestinationList> itr = destinationListList.values().iterator();
    while (itr.hasNext()) {
        dl = itr.next();
        dl.loadDestinations();
        addPartitionListener(dl.getTransactionList());
        notifyPartitionAdded(dl.getPartitionedStore(), dl);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SizeString(com.sun.messaging.jmq.util.SizeString) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) InvalidSysMessageIDException(com.sun.messaging.jmq.io.InvalidSysMessageIDException) PartitionNotFoundException(com.sun.messaging.jmq.jmsserver.util.PartitionNotFoundException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) InvalidPacketException(com.sun.messaging.jmq.io.InvalidPacketException) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 70 with BrokerException

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

the class DestinationList method loadDestinations.

private void loadDestinations() throws BrokerException {
    synchronized (destinationListLock) {
        if (destsLoaded) {
            return;
        }
        destsLoaded = true;
    }
    logger.log(Logger.INFO, br.getKString(br.I_RETRIEVE_STORED_DESTINATIONS) + logsuffix);
    // before we do anything else, make sure we dont have any
    // unexpected exceptions
    LoadException load_ex = pstore.getLoadDestinationException();
    if (load_ex != null) {
        // some messages could not be loaded
        LoadException processing = load_ex;
        while (processing != null) {
            String destid = (String) processing.getKey();
            Destination d = (Destination) processing.getValue();
            if (destid == null && d == null) {
                logger.log(Logger.WARNING, "LoadDestinationException: " + "Both key and value are corrupted");
                continue;
            }
            if (destid == null) {
                // store with valid key
                try {
                    pstore.storeDestination(d, PERSIST_SYNC);
                } catch (Exception ex) {
                    logger.log(Logger.WARNING, BrokerResources.W_DST_RECREATE_FAILED, d.toString(), ex);
                    try {
                        pstore.removeDestination(d, true);
                    } catch (Exception ex1) {
                        logger.logStack(Logger.DEBUG, "Unable to remove dest", ex1);
                    }
                }
            } else {
                DestinationUID duid = new DestinationUID(destid);
                String name = duid.getName();
                boolean isqueue = duid.isQueue();
                int type = isqueue ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC;
                // if this is a temp destination etc
                try {
                    d = createDestination(name, type);
                    d.store();
                    logger.log(Logger.WARNING, BrokerResources.W_DST_REGENERATE, duid.getLocalizedName());
                } catch (Exception ex) {
                    logger.log(Logger.WARNING, BrokerResources.W_DST_REGENERATE_ERROR, duid, ex);
                    try {
                        if (duid.isQueue()) {
                            d = new Queue(duid);
                        } else {
                            d = new Topic(duid);
                        }
                        pstore.removeDestination(d, true);
                    } catch (Exception ex1) {
                        logger.logStack(Logger.DEBUG, "Unable to remove dest", ex1);
                    }
                }
            }
            // end if
            processing = processing.getNextException();
        }
    // end while
    }
    // retrieve stored destinations
    try {
        Destination[] dests = pstore.getAllDestinations();
        logger.log(Logger.INFO, br.getKString(br.I_RETRIEVED_STORED_DESTINATIONS, String.valueOf(dests.length)) + logsuffix);
        for (int i = 0; i < dests.length; i++) {
            if (dests[i] == null) {
                continue;
            }
            if (DEBUG) {
                logger.log(Logger.INFO, "Process stored destination " + dests[i]);
            }
            dests[i].setDestinationList(this);
            if (!dests[i].isAdmin() && (dests[i].getIsDMQ() || !dests[i].isInternal())) {
                dests[i].initialize();
            }
            if (dests[i].isAutoCreated() && dests[i].size == 0 && dests[i].bytes == 0) {
                destinationList.remove(dests[i].getDestinationUID());
                try {
                    Globals.getLogger().log(logger.INFO, br.getKString(br.I_DESTROYING_DESTINATION, dests[i].getName()) + logsuffix);
                    dests[i].destroy(Globals.getBrokerResources().getString(BrokerResources.M_AUTO_REAPED) + logsuffix);
                } catch (BrokerException ex) {
                    // 
                    if (ex.getStatusCode() == Status.NOT_FOUND) {
                        // someone else removed it already
                        return;
                    }
                    throw ex;
                }
            } else {
                addDestination(dests[i], false);
            }
        }
        deadMessageQueue = createDMQ();
        // iterate through and deal with monitors
        Iterator itr = destinationList.values().iterator();
        while (itr.hasNext()) {
            Destination d = (Destination) itr.next();
            try {
                d.initMonitor();
            } catch (IOException ex) {
                logger.logStack(logger.INFO, BrokerResources.I_CANT_LOAD_MONITOR, d.toString(), ex);
                itr.remove();
            }
        }
    } catch (BrokerException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.X_LOAD_DESTINATIONS_FAILED, ex);
        throw ex;
    } catch (IOException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.X_LOAD_DESTINATIONS_FAILED, ex);
        throw new BrokerException(BrokerResources.X_LOAD_DESTINATIONS_FAILED, ex);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SizeString(com.sun.messaging.jmq.util.SizeString) InvalidSysMessageIDException(com.sun.messaging.jmq.io.InvalidSysMessageIDException) PartitionNotFoundException(com.sun.messaging.jmq.jmsserver.util.PartitionNotFoundException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) InvalidPacketException(com.sun.messaging.jmq.io.InvalidPacketException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException)

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