Search in sources :

Example 6 with Destination

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

the class TransactionListLoader method loadDestinations.

private static void loadDestinations(PartitionedStore store) throws BrokerException {
    if (!loaded) {
        loaded = true;
        Globals.getDestinationList().loadDestinations(store);
        Iterator[] itrs = Globals.getDestinationList().getAllDestinations(store);
        Iterator itr = itrs[0];
        while (itr.hasNext()) {
            Destination d = (Destination) itr.next();
            d.load();
        }
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) Iterator(java.util.Iterator)

Example 7 with Destination

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

the class TransactionListLoader method unrouteLoadedTransactionAckMessage.

private static void unrouteLoadedTransactionAckMessage(PartitionedStore store, DestinationUID destID, SysMessageID ackedSysMsgID, ConsumerUID consumerID) throws BrokerException {
    logger.log(Logger.DEBUG, " trying to unroute prepared acknowledged message: destID =  " + destID + " ackedMsgId=" + ackedSysMsgID);
    Destination dest = null;
    PacketReference ackedMessage = null;
    if (destID != null) {
        Destination[] ds = Globals.getDestinationList().getDestination(store, destID);
        dest = ds[0];
        if (dest != null) {
            dest.load();
            ackedMessage = dest.getMessage(ackedSysMsgID);
            if (ackedMessage == null) {
                String msg = "Could not find packet for " + ackedSysMsgID + "in dest " + dest;
                logger.log(Logger.WARNING, msg);
                return;
            }
        } else {
            // this could happen e.g. if empty auto dest has been destroyed
            String msg = "Could not find destination for " + destID;
            logger.log(Logger.WARNING, msg);
            return;
        }
    } else {
        // no destid stored for some reason so need to load all dests
        logger.log(Logger.WARNING, "No dest ID for acked message. Will need to load all dests " + ackedSysMsgID);
        loadDestinations(store);
        ackedMessage = Globals.getDestinationList().get(store, ackedSysMsgID);
        dest = ackedMessage.getDestination();
    }
    // need to unroute messages that have been consumed in a prepared
    // transaction.
    // they cannot be redelivered unless the transaction rolls back.
    dest.unrouteLoadedTransactionAckMessage(ackedMessage, consumerID);
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference)

Example 8 with Destination

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

the class TransactionListLoader method handleSentMessages.

static void handleSentMessages(TransactionList transactionList, TransactionWork txnWork) throws BrokerException {
    for (int i = 0; i < txnWork.numSentMessages(); i++) {
        TransactionWorkMessage msg = txnWork.getSentMessages().get(i);
        Packet packet = msg.getMessage();
        DestinationUID duid = msg.getDestUID();
        logger.log(Logger.DEBUG, " handleSentMessages: duid= " + duid);
        PacketReference pr = PacketReference.createReference(transactionList.getPartitionedStore(), packet, duid, null);
        Destination[] ds = Globals.getDestinationList().getDestination(transactionList.getPartitionedStore(), duid);
        Destination d = ds[0];
        if (d == null) {
            // Lets recreate it here.
            try {
                int type = (duid.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC);
                ds = Globals.getDestinationList().getDestination(transactionList.getPartitionedStore(), duid.getName(), type, true, true);
                d = ds[0];
            } catch (IOException e) {
                throw new BrokerException("Could not recreate destination " + duid, e);
            }
        }
        // check it is loaded
        d.load();
        logger.log(Logger.DEBUG, " loadTransactions: processing prepared sent message " + packet.getMessageID());
        // queue message
        d.queueMessage(pr, true);
        // store (should not really be persisted as we are using txnLog)
        // pr.store();
        // add message to transaction
        transactionList.addMessage(pr.getTransactionID(), pr.getSysMessageID(), true);
    }
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) IOException(java.io.IOException)

Example 9 with Destination

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

the class CompactDestinationHandler 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() + ": " + "Compacting: " + cmd_props);
    }
    logger.log(Logger.INFO, Globals.getBrokerResources().I_COMPACTING, cmd_props);
    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;
    boolean compactAll = false;
    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 {
            if (destination != null) {
                // compact one destination
                Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(type.intValue()));
                // PART
                Destination d = ds[0];
                if (d != null) {
                    if (d.isPaused()) {
                        d.compact();
                    } else {
                        status = Status.ERROR;
                        String msg = rb.getString(rb.E_DESTINATION_NOT_PAUSED);
                        errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, msg);
                        logger.log(Logger.ERROR, errMsg);
                    }
                } else {
                    status = Status.ERROR;
                    String subError = rb.getString(rb.E_NO_SUCH_DESTINATION, getDestinationType(type.intValue()), destination);
                    errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, subError);
                    logger.log(Logger.ERROR, errMsg);
                }
            } else {
                Iterator[] itrs = DL.getAllDestinations(null);
                Iterator itr = itrs[0];
                boolean docompact = true;
                while (itr.hasNext()) {
                    // make sure all are paused
                    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;
                    }
                    if (!d.isPaused()) {
                        docompact = false;
                        status = Status.ERROR;
                        String msg = rb.getString(rb.E_SOME_DESTINATIONS_NOT_PAUSED);
                        errMsg = rb.getString(rb.X_COMPACT_DSTS_EXCEPTION, msg);
                        logger.log(Logger.ERROR, errMsg);
                    }
                }
                if (docompact) {
                    itrs = DL.getAllDestinations(null);
                    // PART
                    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.compact();
                    }
                }
            }
        } catch (Exception e) {
            status = Status.ERROR;
            if (compactAll) {
                errMsg = rb.getString(rb.X_COMPACT_DSTS_EXCEPTION, e.toString());
            } else {
                errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, e.toString());
            }
            logger.log(Logger.ERROR, errMsg, e);
        }
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.COMPACT_DESTINATION_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) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)

Example 10 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination 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)

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