Search in sources :

Example 11 with BrokerResources

use of com.sun.messaging.jmq.jmsserver.resources.BrokerResources in project openmq by eclipse-ee4j.

the class ConsumerUtil method getConsumerInfo.

public static CompositeData getConsumerInfo(String consumerID) throws BrokerException, OpenDataException {
    CompositeData cd = null;
    ConsumerUID tmpcid, cid = null;
    BrokerResources rb = Globals.getBrokerResources();
    if (consumerID == null) {
        throw new IllegalArgumentException(rb.getString(rb.X_JMX_NULL_CONSUMER_ID_SPEC));
    }
    long longCid = 0;
    try {
        longCid = Long.parseLong(consumerID);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(rb.getString(rb.X_JMX_INVALID_CONSUMER_ID_SPEC, consumerID));
    }
    tmpcid = new ConsumerUID(longCid);
    Consumer con = Consumer.getConsumer(tmpcid);
    if (con == null) {
        throw new BrokerException(rb.getString(rb.X_JMX_CONSUMER_NOT_FOUND, consumerID));
    }
    // triggers the broker to load messages if necessary
    con.load();
    cid = con.getConsumerUID();
    if (cid == null) {
        throw new BrokerException(rb.getString(rb.X_JMX_CONSUMER_NOT_FOUND, consumerID));
    }
    cd = getConsumerInfo(cid);
    return (cd);
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) CompositeData(javax.management.openmbean.CompositeData) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources)

Example 12 with BrokerResources

use of com.sun.messaging.jmq.jmsserver.resources.BrokerResources in project openmq by eclipse-ee4j.

the class ChangeRecord method prepareRestoreRecords.

/**
 * Preparing for restoring change records.
 */
public static List<ChangeRecordInfo> prepareRestoreRecords(String fileName) throws Exception {
    Logger logger = Globals.getLogger();
    BrokerResources br = Globals.getBrokerResources();
    if (DEBUG) {
        logger.logToAll(Logger.INFO, "ChangeRecord.prepareRestoreRecords from file " + fileName);
    }
    FileInputStream fis = null;
    DataInputStream dis = null;
    try {
        // Make sure that the file does exist.
        File f = new File(fileName);
        if (!f.exists()) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_RESTORE1, fileName);
            logger.log(Logger.WARNING, emsg);
            throw new BrokerException(emsg);
        }
        fis = new FileInputStream(f);
        dis = new DataInputStream(fis);
        // Version
        int curversion = dis.readInt();
        // Signature.
        String sig = dis.readUTF();
        if (!sig.equals(ProtocolGlobals.CFGSRV_BACKUP_PROPERTY)) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_RESTORE2, fileName);
            logger.logToAll(Logger.WARNING, emsg);
            throw new BrokerException(emsg);
        }
        if (curversion < ProtocolGlobals.VERSION_350 || curversion > ProtocolGlobals.getCurrentVersion()) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_RESTORE3, String.valueOf(curversion), String.valueOf(ProtocolGlobals.getCurrentVersion()));
            logger.logToAll(Logger.ERROR, emsg);
            throw new BrokerException(emsg);
        }
        ArrayList<ChangeRecordInfo> records = new ArrayList<>();
        while (true) {
            int recsize = dis.readInt();
            if (recsize == 0) {
                break;
            }
            byte[] rec = new byte[recsize];
            dis.readFully(rec, 0, recsize);
            ChangeRecordInfo cri = new ChangeRecordInfo();
            cri.setRecord(rec);
            ChangeRecord cr = makeChangeRecord(rec);
            cri.setType(cr.getPacketType());
            cri.setUKey(cr.getUniqueKey());
            cri.setDuraAdd(cr.isDuraAdd());
            if (Globals.useSharedConfigRecord()) {
                String uuid = cr.getUUID();
                if (uuid == null) {
                    uuid = UUID.randomUUID().toString();
                }
                cri.setUUID(uuid);
            }
            records.add(cri);
            if (DEBUG) {
                logger.logToAll(Logger.INFO, "ChangeRecord.prepareRestoreRecords restore record " + cri);
            }
        }
        dis.close();
        fis.close();
        logger.logToAll(Logger.INFO, br.getKString(br.I_CLUSTER_MB_RESTORE_PROCESS_RECORDS, String.valueOf(records.size()), fileName));
        return records;
    } catch (Exception e) {
        String emsg = br.getKString(br.W_MBUS_RESTORE_ERROR, fileName, e.getMessage());
        logger.logStack(Logger.ERROR, emsg, e);
        throw e;
    } finally {
        if (dis != null) {
            try {
                dis.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ArrayList(java.util.ArrayList) 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 13 with BrokerResources

use of com.sun.messaging.jmq.jmsserver.resources.BrokerResources in project openmq by eclipse-ee4j.

the class ShareConfigChangeDBManager method throwTableLockedException.

@Override
protected void throwTableLockedException(TableLock lock) throws BrokerException {
    BrokerResources br = Globals.getBrokerResources();
    String emsg = null;
    if (lock.port != 0) {
        emsg = br.getKString(br.E_SHARECC_TABLE_LOCKED_BY, lock.host, String.valueOf(lock.port));
        throw new BrokerException(emsg, br.E_SHARECC_TABLE_LOCKED_BY, null, Status.CONFLICT);
    }
    emsg = br.getKString(br.E_SHARECC_TABLE_LOCKED_BY_DBMGR, "imqdbmgr");
    throw new BrokerException(emsg, br.E_SHARECC_TABLE_LOCKED_BY_DBMGR, null, Status.CONFLICT);
}
Also used : BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources)

Aggregations

BrokerResources (com.sun.messaging.jmq.jmsserver.resources.BrokerResources)13 Logger (com.sun.messaging.jmq.util.log.Logger)7 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)6 Iterator (java.util.Iterator)4 SizeString (com.sun.messaging.jmq.util.SizeString)3 ArrayList (java.util.ArrayList)3 CompositeData (javax.management.openmbean.CompositeData)3 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 ChangeRecordInfo (com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)2 ConnectionManager (com.sun.messaging.jmq.jmsserver.service.ConnectionManager)2 Service (com.sun.messaging.jmq.jmsserver.service.Service)2 List (java.util.List)2 BrokerMQAddress (com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)1 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)1 ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)1 IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)1