Search in sources :

Example 61 with BrokerException

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

the class ChangeRecord method processChangeRecords.

private static void processChangeRecords(List<ChangeRecordInfo> records, ChangeRecordCallback cb, MessageBusCallback mbcb, RaptorProtocol proto) throws BrokerException {
    Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CLUSTER_PROCESS_CHANGE_RECORDS, Integer.valueOf(records.size())));
    boolean resetFlag = false;
    if (records.size() > 0 && records.get(0).isSelectAll()) {
        resetFlag = true;
    }
    String resetUUID = null;
    try {
        ArrayList l = new ArrayList();
        for (int i = 0; i < records.size(); i++) {
            ByteArrayInputStream bis = new ByteArrayInputStream(records.get(i).getRecord());
            DataInputStream dis = new DataInputStream(bis);
            GPacket gp = GPacket.getInstance();
            gp.read(dis);
            if (gp.getType() != records.get(i).getType()) {
                throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHARECC_RECORD_TYPE_CORRUPT, ProtocolGlobals.getPacketTypeString(gp.getType()), records.get(i).toString()));
            }
            if (gp.getType() == ProtocolGlobals.G_RESET_PERSISTENCE) {
                String uuid = records.get(i).getUUID();
                if (resetUUID != null && !resetUUID.equals(uuid)) {
                    throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHARECC_RESET_RECORD_UUID_CORRUPT, ProtocolGlobals.getPacketTypeString(ProtocolGlobals.G_RESET_PERSISTENCE), "[" + resetUUID + ", " + uuid + "]"));
                } else if (resetUUID == null) {
                    resetUUID = uuid;
                }
            }
            if (resetFlag) {
                l.add(gp);
            } else {
                proto.handleGPacket(mbcb, Globals.getMyAddress(), gp);
            }
        }
        if (resetFlag) {
            proto.applyPersistentStateChanges(Globals.getMyAddress(), l);
        }
        if (records.size() > 0) {
            ChangeRecordInfo rec = records.get(records.size() - 1);
            cb.setLastSyncedChangeRecord(rec);
            storeLastSeq(rec.getSeq());
            if (resetFlag && resetUUID != null) {
                rec.setResetUUID(resetUUID);
                storeLastResetUUID(resetUUID);
            }
        }
    } catch (Throwable t) {
        Globals.getLogger().logStack(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_FAIL_PROCESS_SHARECC_RECORDS, t.getMessage()), t);
        if (t instanceof BrokerException) {
            throw (BrokerException) t;
        }
        throw new BrokerException(t.getMessage(), t);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ArrayList(java.util.ArrayList) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) GPacket(com.sun.messaging.jmq.io.GPacket)

Example 62 with BrokerException

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

the class ChangeRecord method backupRecords.

/**
 * Backup the change records.
 */
public static void backupRecords(List<ChangeRecordInfo> records, String fileName, boolean throwEx) throws BrokerException {
    Logger logger = Globals.getLogger();
    if (DEBUG) {
        logger.logToAll(Logger.INFO, "ChangeRecord.backup(" + fileName + ")");
    }
    BrokerResources br = Globals.getBrokerResources();
    int loglevel = (throwEx ? Logger.ERROR : Logger.WARNING);
    FileOutputStream fos = null;
    DataOutputStream dos = null;
    try {
        // Make sure that the file does not exist.
        File f = new File(fileName);
        if (!f.createNewFile()) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_BACKUP2, fileName);
            logger.logToAll(loglevel, emsg);
            if (throwEx) {
                throw new BrokerException(emsg);
            }
            return;
        }
        fos = new FileOutputStream(f);
        dos = new DataOutputStream(fos);
        ArrayList<ChangeRecord> recordList = compressRecords(records);
        dos.writeInt(ProtocolGlobals.getCurrentVersion());
        // Signature.
        dos.writeUTF(ProtocolGlobals.CFGSRV_BACKUP_PROPERTY);
        // Write the RESET record here.
        ChangeRecordInfo cri = makeResetRecord(true);
        byte[] rst = cri.getRecord();
        dos.writeInt(rst.length);
        dos.write(rst, 0, rst.length);
        if (DEBUG) {
            logger.logToAll(Logger.INFO, "ChangeRecord.backupRecords backup record " + cri);
        }
        ChangeRecord cr = null;
        for (int i = 0; i < recordList.size(); i++) {
            cr = recordList.get(i);
            if (!cr.isDiscard()) {
                byte[] rec = cr.getBytes();
                dos.writeInt(rec.length);
                dos.write(rec, 0, rec.length);
                if (DEBUG) {
                    logger.logToAll(Logger.INFO, "ChangeRecord.backupRecords() backup record " + cr);
                }
            }
        }
        dos.writeInt(0);
        logger.logToAll(Logger.INFO, br.I_CLUSTER_MB_BACKUP_SUCCESS, fileName);
    } catch (Exception e) {
        String emsg = br.getKString(br.W_MBUS_BACKUP_ERROR, e.getMessage());
        logger.logStack((throwEx ? Logger.ERROR : Logger.WARNING), emsg, e);
        if (throwEx) {
            throw new BrokerException(emsg);
        }
    } finally {
        if (dos != null) {
            try {
                dos.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
    if (DEBUG) {
        logger.logToAll(Logger.INFO, "ChanageRecord.backup complete");
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Logger(com.sun.messaging.jmq.util.log.Logger) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources)

Example 63 with BrokerException

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

the class Destination method purgeDestination.

public void purgeDestination(boolean noerrnotfound) throws BrokerException {
    if (!loaded) {
        load(noerrnotfound);
    }
    try {
        MemoryManager mm = Globals.getMemManager();
        int maxpurge = destMessages.size();
        long removedCount = 0L;
        long indeliveryCount = 0L;
        boolean do1 = false;
        boolean oomed = false;
        List<SysMessageID> list = null;
        int count = 0;
        while (maxpurge > 0 && count < maxpurge) {
            do1 = false;
            if (oomed) {
                do1 = true;
                oomed = false;
            } else if (mm != null && mm.getCurrentLevel() > 0) {
                do1 = true;
            }
            if (!do1) {
                try {
                    list = new ArrayList<>(destMessages.getAllKeys());
                    count = maxpurge;
                } catch (OutOfMemoryError oom) {
                    oomed = true;
                    continue;
                }
            } else {
                list = destMessages.getFirstKeys(1);
            }
            if (list.isEmpty()) {
                break;
            }
            count += list.size();
            RemoveMessageReturnInfo ret = null;
            SysMessageID sysid = null;
            Iterator<SysMessageID> itr = list.iterator();
            while (itr.hasNext()) {
                sysid = itr.next();
                ret = _removeMessage(sysid, RemoveReason.PURGED, null, null, true);
                if (ret.removed) {
                    removedCount++;
                } else if (ret.indelivery) {
                    indeliveryCount++;
                }
            }
        }
        // while maxpurge
        logger.log(logger.INFO, br.getKString(br.I_NUM_MSGS_PURGED_FROM_DEST, removedCount, uid.getLocalizedName()));
        if (indeliveryCount > 0) {
            logger.log(logger.INFO, br.getKString(br.I_NUM_MSGS_INDELIVERY_NOT_PURGED_FROM_DEST, indeliveryCount, uid.getLocalizedName()));
        }
        Agent agent = Globals.getAgent();
        if (agent != null) {
            agent.notifyDestinationPurge(this);
        }
    } catch (Exception ex) {
        if (BrokerStateHandler.isShuttingDown()) {
            logger.log(Logger.INFO, BrokerResources.E_PURGE_DST_FAILED, getName(), ex);
        } else {
            logger.logStack(Logger.WARNING, BrokerResources.E_PURGE_DST_FAILED, getName(), ex);
        }
        if (ex instanceof BrokerException) {
            throw (BrokerException) ex;
        }
        throw new BrokerException(br.getKString(BrokerResources.E_PURGE_DST_FAILED, getName()), ex);
    }
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) MemoryManager(com.sun.messaging.jmq.jmsserver.memory.MemoryManager) DestinationNotFoundException(com.sun.messaging.jmq.jmsserver.util.DestinationNotFoundException) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 64 with BrokerException

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

the class Destination method queueMessage.

public boolean queueMessage(PacketReference pkt, boolean trans, boolean enforcelimit) throws BrokerException {
    if (!DL.isValid()) {
        throw new BrokerException(br.getKString(BrokerResources.I_DST_SHUTDOWN_DESTROY, getName()));
    }
    synchronized (dmc) {
        msgsIn += 1;
        msgBytesIn += pkt.byteSize();
        msgsInInternal += 1;
        if (msgsInInternal >= Long.MAX_VALUE) {
            msgsInOutLastResetTime = System.currentTimeMillis();
            msgsInInternal = 0;
            msgsOutInternal = 0;
        }
    }
    PacketListDMPair dmp = null;
    try {
        try {
            boolean check = !isAdmin() && !isInternal();
            dmp = DL.addNewMessage((check && enforcelimit), pkt);
            boolean ok = dmp.getReturn();
            if (!ok && !isDMQ) {
                // put on dead message queue
                if (!isInternal()) {
                    pkt.setDestination(this);
                    markDead(pkt, RemoveReason.EXPIRED, null);
                    DL.removePacketList(pkt.getSysMessageID(), this.getDestinationUID(), pkt);
                }
                return false;
            }
        } catch (BrokerException ex) {
            pkt.destroy();
            throw ex;
        }
        pkt.setDestination(this);
        try {
            if (!DL.isValid()) {
                pkt.destroy();
                throw new BrokerException(br.getKString(BrokerResources.I_DST_SHUTDOWN_DESTROY, getName()));
            }
            if (overrideP) {
                pkt.overridePersistence(overridePvalue);
            }
            putMessage(pkt, AddReason.QUEUED, false, enforcelimit);
            if (overrideTTL) {
                pkt.overrideExpireTime(System.currentTimeMillis() + overrideTTLvalue);
            }
            ExpirationInfo ei = pkt.getExpireInfo();
            MessageDeliveryTimeInfo di = pkt.getDeliveryTimeInfo();
            if (di != null && di.isDeliveryDue()) {
                di = null;
            }
            MsgExpirationReaper er = null;
            MessageDeliveryTimeTimer dt = null;
            if (ei != null || di != null) {
                er = expireReaper;
                dt = deliveryTimeTimer;
            }
            if (er != null && ei != null) {
                if (!DL.isValid()) {
                    String emsg = br.getKString(br.W_ADD_MSG_DEST_DESTROYED, pkt, "" + uid);
                    RuntimeException ex = new RuntimeException(emsg);
                    logger.log(Logger.WARNING, emsg);
                    removeMessage(pkt.getSysMessageID(), null);
                    throw ex;
                }
                er.addExpiringMessage(ei);
            }
            if (di != null) {
                if (!DL.isValid()) {
                    String emsg = br.getKString(br.W_ADD_MSG_DEST_DESTROYED, pkt, "" + uid);
                    RuntimeException ex = new RuntimeException(emsg);
                    ex.fillInStackTrace();
                    logger.log(Logger.WARNING, emsg);
                    removeMessage(pkt.getSysMessageID(), null);
                    throw ex;
                }
                if (dt == null) {
                    String emsg = br.getKString(br.W_ADD_MSG_NO_DELIVERY_TIMER, pkt, uid + "[" + isValid() + "]");
                    RuntimeException ex = new RuntimeException(emsg);
                    ex.fillInStackTrace();
                    logger.log(Logger.WARNING, emsg);
                    throw ex;
                }
                dt.addMessage(di);
            }
        } catch (IllegalStateException ex) {
            // message exists
            throw new BrokerException(br.getKString(BrokerResources.X_MSG_EXISTS_IN_DEST, pkt.getSysMessageID(), this.toString()), BrokerResources.X_MSG_EXISTS_IN_DEST, ex, Status.NOT_MODIFIED);
        } catch (OutOfLimitsException ex) {
            removeMessage(pkt.getSysMessageID(), RemoveReason.OVERFLOW);
            Object lmt = ex.getLimit();
            boolean unlimited = false;
            if (lmt == null) {
            } else if (lmt instanceof Integer) {
                unlimited = ((Integer) ex.getLimit()).intValue() <= 0;
            } else if (lmt instanceof Long) {
                unlimited = ((Long) ex.getLimit()).longValue() <= 0;
            }
            String[] args = { pkt.getSysMessageID().toString(), getName(), (unlimited ? br.getString(BrokerResources.M_UNLIMITED) : ex.getLimit().toString()), ex.getValue().toString() };
            String id = BrokerResources.X_INTERNAL_EXCEPTION;
            int status = Status.RESOURCE_FULL;
            switch(ex.getType()) {
                case OutOfLimitsException.CAPACITY_EXCEEDED:
                    id = BrokerResources.X_DEST_MSG_CAPACITY_EXCEEDED;
                    break;
                case OutOfLimitsException.BYTE_CAPACITY_EXCEEDED:
                    id = BrokerResources.X_DEST_MSG_BYTES_EXCEEDED;
                    break;
                case OutOfLimitsException.ITEM_SIZE_EXCEEDED:
                    id = BrokerResources.X_DEST_MSG_SIZE_EXCEEDED;
                    status = Status.ENTITY_TOO_LARGE;
                    break;
                default:
            }
            throw new BrokerException(br.getKString(id, args), id, ex, status);
        } catch (IllegalArgumentException ex) {
            removeMessage(pkt.getSysMessageID(), RemoveReason.ERROR);
            throw ex;
        }
    } finally {
        if (dmp != null) {
            dmp.nullRef();
        }
    }
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SizeString(com.sun.messaging.jmq.util.SizeString)

Example 65 with BrokerException

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

the class Destination method addProducer.

@Override
public boolean addProducer(ProducerSpi producer) throws BrokerException {
    if (isInternal()) {
        throw new BrokerException(br.getKString(BrokerResources.X_MONITOR_PRODUCER, getName()));
    }
    if (maxProducerLimit != UNLIMITED && producers.size() >= maxProducerLimit) {
        throw new BrokerException(br.getKString(BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, getName(), String.valueOf(maxProducerLimit)), BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, (Throwable) null, Status.CONFLICT);
    }
    synchronized (this) {
        if (destReaper != null) {
            destReaper.cancel();
            destReaper = null;
        }
    }
    // then we have to deal with ordering
    if (!loaded) {
        load();
    }
    try {
        synchronized (producers) {
            producers.put(producer.getProducerUID(), producer);
        }
    } catch (IndexOutOfBoundsException ex) {
        throw new BrokerException(br.getKString(BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, getName(), String.valueOf(maxProducerLimit)), BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, ex, Status.CONFLICT);
    }
    producerFlow.addProducer((Producer) producer);
    boolean active = producerFlow.checkResumeFlow((Producer) producer, false);
    logger.log(Logger.DEBUGHIGH, "Producer " + producer + " is " + active);
    return active;
}
Also used : 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