Search in sources :

Example 1 with Packet

use of com.sun.messaging.jmq.io.Packet in project openmq by eclipse-ee4j.

the class TransactionHandler method sendReplyBody.

/**
 * Send a reply packet with a body and properties
 */
public void sendReplyBody(IMQConnection con, Packet msg, int type, int status, Hashtable hash, byte[] body) {
    Packet pkt = new Packet(con.useDirectBuffers());
    pkt.setPacketType(type);
    pkt.setConsumerID(msg.getConsumerID());
    if (hash == null) {
        hash = new Hashtable();
    }
    hash.put("JMQStatus", Integer.valueOf(status));
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        hash.put("JMQReqID", msg.getSysMessageID().toString());
    }
    pkt.setProperties(hash);
    if (body != null) {
        pkt.setMessageBody(body);
    }
    con.sendControlMessage(pkt);
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) Hashtable(java.util.Hashtable)

Example 2 with Packet

use of com.sun.messaging.jmq.io.Packet in project openmq by eclipse-ee4j.

the class AdminCmdHandler method handle.

/**
 * Default handler. Just replies to the message with the correct reply message type and a status of "Not Implemented"
 */
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    Integer n = (Integer) cmd_props.get(MessageType.JMQ_MESSAGE_TYPE);
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    // By convention reply message is the message type + 1
    setProperties(reply, n.intValue() + 1, Status.ERROR, "Not Implemented");
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Packet(com.sun.messaging.jmq.io.Packet)

Example 3 with Packet

use of com.sun.messaging.jmq.io.Packet 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 4 with Packet

use of com.sun.messaging.jmq.io.Packet 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 5 with Packet

use of com.sun.messaging.jmq.io.Packet in project openmq by eclipse-ee4j.

the class TransactionWorkMessage method readWork.

public void readWork(DataInputStream dis) throws IOException, BrokerException {
    message = new Packet(false);
    message.generateTimestamp(false);
    message.generateSequenceNumber(false);
    message.readPacket(dis);
    int numStoredInterests = dis.readInt();
    storedInterests = new ConsumerUID[numStoredInterests];
    for (int j = 0; j < numStoredInterests; j++) {
        long cuid = dis.readLong();
        storedInterests[j] = new ConsumerUID(cuid);
    }
    // Make sure dest exists; auto-create if possible
    // this is because we will need to add messages to this
    // destination
    destUID = DestinationUID.getUID(message.getDestination(), message.getIsQueue());
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

Aggregations

Packet (com.sun.messaging.jmq.io.Packet)57 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)17 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)9 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)8 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)8 IOException (java.io.IOException)7 Hashtable (java.util.Hashtable)7 InvalidPacketException (com.sun.messaging.jmq.io.InvalidPacketException)6 Iterator (java.util.Iterator)6 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)5 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)5 SizeString (com.sun.messaging.jmq.util.SizeString)5 BrokerStateHandler (com.sun.messaging.jmq.jmsserver.BrokerStateHandler)4 HAMonitorService (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)4 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)4 InvalidSysMessageIDException (com.sun.messaging.jmq.io.InvalidSysMessageIDException)3 PacketReadEOFException (com.sun.messaging.jmq.io.PacketReadEOFException)3 ReadWritePacket (com.sun.messaging.jmq.io.ReadWritePacket)3 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)3 ByteBuffer (java.nio.ByteBuffer)3