Search in sources :

Example 46 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.

the class PauseHandler 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
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Pausing: " + cmd_props);
    }
    String pauseTarget = (String) cmd_props.get(MessageType.JMQ_PAUSE_TARGET);
    String service = (String) cmd_props.get(MessageType.JMQ_SERVICE_NAME);
    String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
    Integer type = (Integer) cmd_props.get(MessageType.JMQ_DEST_TYPE);
    Integer pauseType = (Integer) cmd_props.get(MessageType.JMQ_DEST_STATE);
    int status = Status.OK;
    String errMsg = null;
    assert service == null || destination == null;
    /*
         * Compatibility with MQ 3.0.1 If pause target not set, assume that the service is being paused.
         */
    if (pauseTarget == null) {
        pauseTarget = MessageType.JMQ_SERVICE_NAME;
    }
    try {
        if (MessageType.JMQ_SERVICE_NAME.equals(pauseTarget)) {
            if (service == null) {
                logger.log(Logger.INFO, BrokerResources.I_PAUSING_ALL_SVCS);
            } else {
                logger.log(Logger.INFO, BrokerResources.I_PAUSING_SVC, service);
            }
            pauseService(true, service);
        } else if (MessageType.JMQ_DESTINATION.equals(pauseTarget)) {
            logger.log(Logger.INFO, BrokerResources.I_PAUSING_DST, destination);
            int pauseval = (pauseType == null ? DestState.PAUSED : pauseType.intValue());
            if (destination == null) {
                Iterator[] itrs = DL.getAllDestinations(null);
                // PART
                Iterator itr = itrs[0];
                while (itr.hasNext()) {
                    Destination d = (Destination) itr.next();
                    /*
                         * Skip internal, admin, or temp destinations. Skipping temp destinations may need to be revisited.
                         */
                    if (d.isInternal() || d.isAdmin() || d.isTemporary()) {
                        continue;
                    }
                    d.pauseDestination(pauseval);
                }
            } else {
                Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(type.intValue()));
                // PART
                Destination d = ds[0];
                if (d == null) {
                    String msg = Globals.getBrokerResources().getString(BrokerResources.I_PAUSED_DST_NOT_EXIST, (DestType.isQueue(type.intValue()) ? " queue:" : " topic:") + destination);
                    errMsg = msg;
                    status = Status.NOT_FOUND;
                    logger.log(Logger.ERROR, msg);
                } else {
                    if (d.isInternal() || d.isAdmin()) {
                        errMsg = Globals.getBrokerResources().getString(BrokerResources.I_PAUSED_ADMIN, (DestType.isQueue(type.intValue()) ? " queue:" : " topic:") + destination);
                        logger.log(Logger.INFO, errMsg);
                        status = Status.ERROR;
                    } else {
                        d.pauseDestination(pauseval);
                    }
                }
            }
        }
    } catch (BrokerException e) {
        logger.log(Logger.ERROR, rb.E_PAUSE_SERVICE, service, e);
        status = Status.ERROR;
        errMsg = rb.getString(rb.E_PAUSE_SERVICE, service) + ": " + e;
    } catch (IllegalArgumentException e) {
        errMsg = e.getMessage();
        status = Status.NOT_FOUND;
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.PAUSE_REPLY, status, errMsg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) Packet(com.sun.messaging.jmq.io.Packet) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Iterator(java.util.Iterator)

Example 47 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.

the class PurgeDestinationHandler 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
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Purging: " + cmd_props);
    }
    assert cmd_props != null;
    String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
    Integer destType = (Integer) cmd_props.get(MessageType.JMQ_DEST_TYPE);
    assert destination != null;
    assert destType != null;
    int status = Status.OK;
    String errMsg = 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 {
        // FOR NOW .. we have just one criteria - ALL
        String criteria_str = Globals.getBrokerResources().getKString(BrokerResources.I_ALL_PURGE_CRITERIA);
        // LKS
        // dont use filter for now
        // Filter f = deleteAll;
        logger.log(Logger.INFO, BrokerResources.I_PURGING_DESTINATION, destination, criteria_str);
        try {
            // for now .. just delete all
            Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(destType.intValue()));
            Destination d = null;
            for (int i = 0; i < ds.length; i++) {
                d = ds[i];
                if (d == null) {
                    continue;
                }
                // audit logging for purge destination
                if (i == 0) {
                    Globals.getAuditSession().destinationOperation(con.getUserName(), con.remoteHostString(), MQAuditSession.PURGE_DESTINATION, d.isQueue() ? MQAuditSession.QUEUE : MQAuditSession.TOPIC, d.getDestinationName());
                }
                d.purgeDestination();
            }
            if (d == null) {
                errMsg = Globals.getBrokerResources().getKString(BrokerResources.E_NO_SUCH_DESTINATION, getDestinationType(destType.intValue()), destination);
                Exception e = new BrokerException(errMsg);
                e.fillInStackTrace();
                status = Status.ERROR;
                logger.log(Logger.WARNING, BrokerResources.W_ADMIN_OPERATION_FAILED, e);
            }
        } catch (BrokerException ex) {
            status = Status.ERROR;
            errMsg = getMessageFromException(ex);
            logger.log(Logger.WARNING, BrokerResources.W_ADMIN_OPERATION_FAILED, ex);
        } catch (OutOfMemoryError err) {
            // throw memory error so it is handled by memory code
            throw err;
        } catch (Throwable ex) {
            status = Status.ERROR;
            errMsg = Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, ex);
            logger.logStack(Logger.WARNING, BrokerResources.W_ADMIN_OPERATION_FAILED, ex);
        }
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.PURGE_DESTINATION_REPLY, status, errMsg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 48 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.

the class ReplaceMessageHandler method replaceMessage.

/**
 * @return new message id, not null;
 */
public String replaceMessage(String msgID, String destination, Object body, boolean isQueue) throws BrokerException, IOException {
    if (msgID == null) {
        String emsg = "REPLACE_MESSAGE: Message ID not specified";
        throw new BrokerException(emsg, Status.BAD_REQUEST);
    }
    if (destination == null) {
        String emsg = "REPLACE_MESSAGE: Message ID not specified";
        throw new BrokerException(emsg, Status.BAD_REQUEST);
    }
    if (body == null || !(body instanceof HashMap)) {
        String emsg = "REPLACE_MESSAGE: New message body specified or is of incorrect type";
        throw new BrokerException(emsg, Status.BAD_REQUEST);
    }
    HashMap hashMapBody = (HashMap) body;
    Destination[] ds = DL.getDestination(null, destination, isQueue);
    // PART
    Destination d = ds[0];
    if (d == null) {
        String emsg = "REPLACE_MESSAGE: " + rb.getString(rb.X_DESTINATION_NOT_FOUND, destination);
        throw new BrokerException(emsg, Status.NOT_FOUND);
    }
    if (DEBUG) {
        d.debug();
    }
    d.load();
    SysMessageID sysMsgID = SysMessageID.get(msgID);
    PacketReference pr = getPacketReference(sysMsgID);
    if (pr == null) {
        String emsg = "REPLACE_MESSAGE: Could not locate message " + msgID + " in destination " + destination;
        throw new BrokerException(emsg, Status.NOT_FOUND);
    }
    logger.log(Logger.INFO, rb.getKString(rb.I_ADMIN_REPLACE_MESSAGE, msgID, d.getDestinationUID()));
    if (!pr.isLocal()) {
        Object[] args = { msgID, d.getDestinationUID(), pr.getBrokerAddress() };
        String emsg = rb.getKString(rb.E_ADMIN_REPLACE_REMOTE_MSG, args);
        throw new BrokerException(emsg, Status.NOT_ALLOWED);
    }
    int oldPacketType = pr.getPacket().getPacketType();
    Integer newPacketType = (Integer) hashMapBody.get("MessageBodyType");
    if (newPacketType == null) {
        String emsg = "REPLACE_MESSAGE: MessageBodyType not specified";
        throw new BrokerException(emsg, Status.BAD_REQUEST);
    }
    if (oldPacketType != newPacketType.intValue()) {
        String emsg = "REPLACE_MESSAGE: Existing message and new message types do not match.";
        throw new BrokerException(emsg, Status.BAD_REQUEST);
    }
    byte[] bytes = getBytesFromMessage(hashMapBody);
    String newMsgID = d.replaceMessageString(sysMsgID, null, bytes);
    if (newMsgID == null) {
        String emsg = "REPLACE_MESSAGE: New message ID not returned as expected.";
        throw new BrokerException(emsg);
    }
    Object[] args = { msgID, newMsgID, d.getDestinationUID() };
    logger.log(logger.INFO, rb.getKString(rb.I_ADMIN_REPLACED_MESSAGE, args));
    return newMsgID;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference)

Example 49 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.

the class ResumeHandler 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
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Resuming: " + cmd_props);
    }
    String pauseTarget = (String) cmd_props.get(MessageType.JMQ_PAUSE_TARGET);
    String service = (String) cmd_props.get(MessageType.JMQ_SERVICE_NAME);
    String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
    Integer type = (Integer) cmd_props.get(MessageType.JMQ_DEST_TYPE);
    int status = Status.OK;
    String errMsg = null;
    assert service == null || destination == null;
    /*
         * Compatibility with MQ 3.0.1 If pause target not set, assume that the service is being paused/resumed.
         */
    if (pauseTarget == null) {
        pauseTarget = MessageType.JMQ_SERVICE_NAME;
    }
    try {
        if (MessageType.JMQ_SERVICE_NAME.equals(pauseTarget)) {
            if (service == null) {
                logger.log(Logger.INFO, BrokerResources.I_RESUMING_ALL_SVCS);
            } else {
                logger.log(Logger.INFO, BrokerResources.I_RESUMING_SVC, service);
            }
            PauseHandler.pauseService(false, service);
        } else if (MessageType.JMQ_DESTINATION.equals(pauseTarget)) {
            logger.log(Logger.INFO, BrokerResources.I_RESUMING_DST, destination);
            PauseHandler.pauseService(false, service);
            if (destination == null) {
                Iterator[] itrs = DL.getAllDestinations(null);
                Iterator itr = itrs[0];
                while (itr.hasNext()) {
                    Destination d = (Destination) itr.next();
                    if (d.isPaused()) {
                        d.resumeDestination();
                    }
                }
            } else {
                Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(type.intValue()));
                // PART
                Destination d = ds[0];
                if (d != null) {
                    d.resumeDestination();
                } else {
                    String msg = Globals.getBrokerResources().getString(BrokerResources.I_RESUMED_DST_NOT_EXIST, (DestType.isQueue(type.intValue()) ? " queue:" : " topic:") + destination);
                    errMsg = msg;
                    status = Status.NOT_FOUND;
                    logger.log(Logger.ERROR, msg);
                }
            }
        }
    } catch (Exception e) {
        status = Status.ERROR;
        errMsg = rb.getString(rb.X_RESUME_SERVICE_EXCEPTION, service, e.toString());
        logger.log(Logger.ERROR, errMsg, e);
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.RESUME_REPLY, status, errMsg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) Packet(com.sun.messaging.jmq.io.Packet) Iterator(java.util.Iterator)

Example 50 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.

the class UpdateDestinationHandler 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
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + cmd_props);
    }
    // String destination = (String)cmd_props.get(MessageType.JMQ_DESTINATION);
    DestinationInfo info = (DestinationInfo) getBodyObject(cmd_msg);
    int status = Status.OK;
    String errMsg = 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 {
        try {
            Destination[] ds = DL.getDestination(null, info.name, DestType.isQueue(info.type));
            // PART
            Destination d = ds[0];
            if (d == null) {
                errMsg = rb.getString(rb.X_DESTINATION_NOT_FOUND, info.name);
                status = Status.NOT_FOUND;
            } else {
                if (info.isModified(info.MAX_MESSAGES)) {
                    int maxMessages = info.maxMessages;
                    d.setCapacity(maxMessages);
                }
                if (info.isModified(info.MAX_MESSAGE_SIZE)) {
                    SizeString maxSize = new SizeString();
                    maxSize.setBytes(info.maxMessageSize);
                    d.setMaxByteSize(maxSize);
                }
                if (info.isModified(info.MAX_MESSAGE_BYTES)) {
                    SizeString maxBytes = new SizeString();
                    maxBytes.setBytes(info.maxMessageBytes);
                    d.setByteCapacity(maxBytes);
                }
                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_FAILOVER_CONSUMERS)) {
                    // PART
                    int maxcons = info.maxFailoverConsumers;
                    d.setMaxFailoverConsumers(maxcons);
                }
                if (info.isModified(info.MAX_PRODUCERS)) {
                    int maxproducers = info.maxProducers;
                    d.setMaxProducers(maxproducers);
                }
                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();
            }
        } catch (Exception ex) {
            errMsg = getMessageFromException(ex);
            status = Status.ERROR;
        }
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.UPDATE_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) SizeString(com.sun.messaging.jmq.util.SizeString) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)

Aggregations

Destination (com.sun.messaging.jmq.jmsserver.core.Destination)76 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)39 Iterator (java.util.Iterator)29 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)25 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)25 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)20 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)18 HashMap (java.util.HashMap)18 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)17 IOException (java.io.IOException)16 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)15 ArrayList (java.util.ArrayList)12 List (java.util.List)11 Packet (com.sun.messaging.jmq.io.Packet)9 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)9 Map (java.util.Map)9 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)8 SizeString (com.sun.messaging.jmq.util.SizeString)8 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)7 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)7