Search in sources :

Example 1 with SizeString

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

the class CreateDestinationHandler 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
 */
@SuppressWarnings("deprecation")
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    DestinationInfo info;
    info = (DestinationInfo) getBodyObject(cmd_msg);
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Creating destination: " + cmd_props + ": " + info.toString());
    }
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    int status = Status.OK;
    String errMsg = null;
    // Default attributes of the destination
    int type = DestType.DEST_TYPE_QUEUE | DestType.DEST_FLAVOR_SINGLE;
    int maxMessages = -1;
    SizeString maxMessageBytes = null;
    SizeString maxMessageSize = null;
    HAMonitorService hamonitor = Globals.getHAMonitorService();
    if (hamonitor != null && hamonitor.inTakeover()) {
        status = Status.ERROR;
        errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
        logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
    } else if (MemoryGlobals.getMEM_DISALLOW_CREATE_DEST()) {
        status = Status.ERROR;
        errMsg = rb.W_LOW_MEM_REJECT_DEST;
    } else if (info.isModified(DestinationInfo.NAME)) {
        if (info.isModified(DestinationInfo.TYPE)) {
            type = info.type;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGES)) {
            maxMessages = info.maxMessages;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_BYTES)) {
            maxMessageBytes = new SizeString();
            maxMessageBytes.setBytes(info.maxMessageBytes);
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_SIZE)) {
            maxMessageSize = new SizeString();
            maxMessageSize.setBytes(info.maxMessageSize);
        }
    } else {
        status = Status.ERROR;
        errMsg = rb.X_NO_DEST_NAME_SET;
    }
    // XXX create destination
    if (status == Status.OK) {
        if (DestType.destNameIsInternal(info.name)) {
            status = Status.ERROR;
            errMsg = rb.getKString(rb.X_CANNOT_CREATE_INTERNAL_DEST, info.name, DestType.INTERNAL_DEST_PREFIX);
        } else {
            if (isValidDestinationName(info.name)) {
                try {
                    DL.createDestination(null, info.name, type);
                } catch (Exception ex) {
                    status = Status.ERROR;
                    errMsg = rb.getKString(rb.X_CREATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
                    if (ex instanceof ConflictException) {
                        logger.log(Logger.INFO, errMsg, ex);
                    } else {
                        logger.logStack(Logger.INFO, errMsg, ex);
                    }
                }
            } else {
                status = Status.ERROR;
                errMsg = rb.getKString(rb.X_DEST_NAME_INVALID, info.name);
            }
        }
    }
    if (status == Status.OK) {
        try {
            Destination[] ds = DL.getDestination(null, info.name, DestType.isQueue(type));
            Destination d = ds[0];
            d.setCapacity(maxMessages);
            d.setByteCapacity(maxMessageBytes);
            d.setMaxByteSize(maxMessageSize);
            if (info.isModified(info.DEST_SCOPE)) {
                int scope = info.destScope;
                d.setScope(scope);
            }
            if (info.isModified(info.DEST_LIMIT)) {
                int destlimit = info.destLimitBehavior;
                d.setLimitBehavior(destlimit);
            }
            if (info.isModified(info.DEST_PREFETCH)) {
                int prefetch = info.maxPrefetch;
                d.setMaxPrefetch(prefetch);
            }
            if (info.isModified(info.DEST_CDP)) {
                int clusterdeliverypolicy = info.destCDP;
                d.setClusterDeliveryPolicy(clusterdeliverypolicy);
            }
            if (info.isModified(info.MAX_ACTIVE_CONSUMERS)) {
                int maxcons = info.maxActiveConsumers;
                d.setMaxActiveConsumers(maxcons);
            }
            if (info.isModified(info.MAX_PRODUCERS)) {
                int maxp = info.maxProducers;
                d.setMaxProducers(maxp);
            }
            if (info.isModified(info.MAX_FAILOVER_CONSUMERS)) {
                int maxcons = info.maxFailoverConsumers;
                d.setMaxFailoverConsumers(maxcons);
            }
            if (info.isModified(info.MAX_SHARED_CONSUMERS)) {
                int maxsharedcons = info.maxNumSharedConsumers;
                d.setMaxSharedConsumers(maxsharedcons);
            }
            if (info.isModified(info.SHARE_FLOW_LIMIT)) {
                int sflowlimit = info.sharedConsumerFlowLimit;
                d.setSharedFlowLimit(sflowlimit);
            }
            if (info.isModified(info.USE_DMQ)) {
                boolean dmq = info.useDMQ;
                d.setUseDMQ(dmq);
            }
            if (info.isModified(info.VALIDATE_XML_SCHEMA_ENABLED)) {
                d.setValidateXMLSchemaEnabled(info.validateXMLSchemaEnabled);
            }
            if (info.isModified(info.XML_SCHEMA_URI_LIST)) {
                d.setXMLSchemaUriList(info.XMLSchemaUriList);
            }
            if (info.isModified(info.RELOAD_XML_SCHEMA_ON_FAILURE)) {
                d.setReloadXMLSchemaOnFailure(info.reloadXMLSchemaOnFailure);
            }
            d.update();
            // audit logging for create destination
            Globals.getAuditSession().destinationOperation(con.getUserName(), con.remoteHostString(), MQAuditSession.CREATE_DESTINATION, d.isQueue() ? MQAuditSession.QUEUE : MQAuditSession.TOPIC, d.getDestinationName());
        } catch (Exception ex) {
            // remove the destination
            try {
                DestinationUID duid = DestinationUID.getUID(info.name, DestType.isQueue(type));
                DL.removeDestination(null, duid, false, ex.toString());
            } catch (Exception ex1) {
            // if we cant destroy .. its ok .. ignore the exception
            }
            status = Status.ERROR;
            errMsg = rb.getString(rb.X_UPDATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
            logger.logStack(Logger.WARNING, errMsg, ex);
        }
    }
    // Send reply
    setProperties(reply, MessageType.CREATE_DESTINATION_REPLY, status, errMsg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) SizeString(com.sun.messaging.jmq.util.SizeString) DestinationInfo(com.sun.messaging.jmq.util.admin.DestinationInfo) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) SizeString(com.sun.messaging.jmq.util.SizeString) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException)

Example 2 with SizeString

use of com.sun.messaging.jmq.util.SizeString 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 3 with SizeString

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

the class DestinationList method setIndividualMessageMax.

/**
 * sets the maximum size of an individual message
 *
 * @param size the size limit for a message (0 is no message maximum)
 */
public static void setIndividualMessageMax(SizeString size) {
    if (size == null) {
        size = new SizeString();
    }
    individual_max_size = size;
    long bytesize = size.getBytes();
    // 
    if (bytesize <= 0) {
        bytesize = Long.MAX_VALUE;
    }
    // end of bug change
    // Inform packet code of the largest packet size allowed
    Packet.setMaxPacketSize(bytesize);
    // update memory
    if (Globals.getMemManager() != null) {
        Globals.getMemManager().updateMaxMessageSize(bytesize);
    }
}
Also used : SizeString(com.sun.messaging.jmq.util.SizeString)

Example 4 with SizeString

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

the class DestinationManagerConfig method getMaxBytesPerMsg.

public Long getMaxBytesPerMsg() throws MBeanException {
    String s = brokerProps.getProperty("imq.message.max_size");
    Long l = null;
    try {
        SizeString ss = new SizeString(s);
        l = Long.valueOf(ss.getBytes());
    } catch (Exception e) {
        handleGetterException(DestinationAttributes.MAX_BYTES_PER_MSG, e);
    }
    return (l);
}
Also used : SizeString(com.sun.messaging.jmq.util.SizeString) SizeString(com.sun.messaging.jmq.util.SizeString) MBeanException(javax.management.MBeanException) PropertyUpdateException(com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 5 with SizeString

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

the class DestinationManagerConfig method update.

@Override
public boolean update(String name, String value) {
    Object newVal, oldVal;
    if (name.equals("imq.autocreate.queue")) {
        newVal = Boolean.valueOf(value);
        try {
            oldVal = getAutoCreateQueues();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.AUTO_CREATE_QUEUES, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.AUTO_CREATE_QUEUES, newVal, oldVal);
    } else if (name.equals("imq.autocreate.queue.maxNumActiveConsumers")) {
        try {
            newVal = Integer.valueOf(value);
        } catch (NumberFormatException nfe) {
            logger.log(Logger.ERROR, getMBeanName() + ": cannot parse internal value of " + DestinationAttributes.AUTO_CREATE_QUEUE_MAX_NUM_ACTIVE_CONSUMERS + ": " + nfe);
            newVal = null;
        }
        try {
            oldVal = getAutoCreateQueueMaxNumActiveConsumers();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.AUTO_CREATE_QUEUE_MAX_NUM_ACTIVE_CONSUMERS, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.AUTO_CREATE_QUEUE_MAX_NUM_ACTIVE_CONSUMERS, newVal, oldVal);
    } else if (name.equals("imq.autocreate.queue.maxNumBackupConsumers")) {
        try {
            newVal = Integer.valueOf(value);
        } catch (NumberFormatException nfe) {
            logger.log(Logger.ERROR, getMBeanName() + ": cannot parse internal value of " + DestinationAttributes.AUTO_CREATE_QUEUE_MAX_NUM_BACKUP_CONSUMERS + ": " + nfe);
            newVal = null;
        }
        try {
            oldVal = getAutoCreateQueueMaxNumBackupConsumers();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.AUTO_CREATE_QUEUE_MAX_NUM_BACKUP_CONSUMERS, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.AUTO_CREATE_QUEUE_MAX_NUM_BACKUP_CONSUMERS, newVal, oldVal);
    } else if (name.equals("imq.autocreate.topic")) {
        newVal = Boolean.valueOf(value);
        try {
            oldVal = getAutoCreateTopics();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.AUTO_CREATE_TOPICS, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.AUTO_CREATE_TOPICS, newVal, oldVal);
    } else if (name.equals("imq.destination.DMQ.truncateBody")) {
        newVal = Boolean.valueOf(value);
        try {
            oldVal = getDMQTruncateBody();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.DMQ_TRUNCATE_BODY, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.DMQ_TRUNCATE_BODY, newVal, oldVal);
    } else if (name.equals("imq.destination.logDeadMsgs")) {
        newVal = Boolean.valueOf(value);
        try {
            oldVal = getLogDeadMsgs();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.LOG_DEAD_MSGS, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.LOG_DEAD_MSGS, newVal, oldVal);
    } else if (name.equals("imq.message.max_size")) {
        try {
            SizeString ss = new SizeString(value);
            newVal = Long.valueOf(ss.getBytes());
        } catch (NumberFormatException nfe) {
            logger.log(Logger.ERROR, getMBeanName() + ": cannot parse internal value of " + DestinationAttributes.MAX_BYTES_PER_MSG + ": " + nfe);
            newVal = null;
        }
        try {
            oldVal = getMaxBytesPerMsg();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.MAX_BYTES_PER_MSG, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.MAX_BYTES_PER_MSG, newVal, oldVal);
    } else if (name.equals("imq.system.max_count")) {
        try {
            newVal = Long.valueOf(value);
        } catch (NumberFormatException nfe) {
            logger.log(Logger.ERROR, getMBeanName() + ": cannot parse internal value of " + DestinationAttributes.MAX_NUM_MSGS + ": " + nfe);
            newVal = null;
        }
        try {
            oldVal = getMaxNumMsgs();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.MAX_NUM_MSGS, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.MAX_NUM_MSGS, newVal, oldVal);
    } else if (name.equals("imq.system.max_size")) {
        try {
            newVal = Long.valueOf(value);
        } catch (NumberFormatException nfe) {
            logger.log(Logger.ERROR, getMBeanName() + ": cannot parse internal value of " + DestinationAttributes.MAX_TOTAL_MSG_BYTES + ": " + nfe);
            newVal = null;
        }
        try {
            oldVal = getMaxTotalMsgBytes();
        } catch (MBeanException e) {
            logProblemGettingOldVal(DestinationAttributes.MAX_TOTAL_MSG_BYTES, e);
            oldVal = null;
        }
        notifyAttrChange(DestinationAttributes.MAX_TOTAL_MSG_BYTES, newVal, oldVal);
    }
    initProps();
    return true;
}
Also used : SizeString(com.sun.messaging.jmq.util.SizeString) MBeanException(javax.management.MBeanException)

Aggregations

SizeString (com.sun.messaging.jmq.util.SizeString)20 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)8 DestinationInfo (com.sun.messaging.jmq.util.admin.DestinationInfo)5 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)4 MBeanException (javax.management.MBeanException)4 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)3 BrokerAdminException (com.sun.messaging.jmq.admin.bkrutil.BrokerAdminException)2 FileTransactionLogWriter (com.sun.messaging.jmq.io.txnlog.file.FileTransactionLogWriter)2 HAMonitorService (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)2 ConflictException (com.sun.messaging.jmq.jmsserver.util.ConflictException)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)2 BrokerAdmin (com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin)1 TransactionLogRecord (com.sun.messaging.jmq.io.txnlog.TransactionLogRecord)1 BrokerConfig (com.sun.messaging.jmq.jmsserver.config.BrokerConfig)1 PropertyUpdateException (com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)1 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)1