Search in sources :

Example 46 with DestinationUID

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

the class AdminDataHandler method handle.

/**
 * Method to handle administration messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    if (DEBUG) {
        logger.log(Logger.DEBUGMED, "AdminDataHandler: handle() [ Received JMS Admin Message] {0} ", msg.toString());
        if (logger.level >= Logger.DEBUGHIGH) {
            msg.dump(System.out);
        }
    }
    String dest = msg.getDestination();
    // administration Queue
    if (!msg.getIsQueue() || (!dest.equals(MessageType.JMQ_ADMIN_DEST) && !dest.equals(MessageType.JMQ_BRIDGE_ADMIN_DEST))) {
        // Normal message. Let standard JMS data handler deal with it.
        return super.handle(con, msg);
    }
    boolean bridgeAdmin = false;
    if (dest.equals(MessageType.JMQ_BRIDGE_ADMIN_DEST)) {
        if (DEBUG) {
            logger.log(Logger.INFO, "Received bridge admin message");
        }
        bridgeAdmin = true;
    }
    Hashtable props = null;
    Integer msgType = null;
    try {
        props = msg.getProperties();
        msgType = (Integer) props.get(MessageType.JMQ_MESSAGE_TYPE);
    } catch (Exception e) {
        // Programming error. No need to I18N
        String emsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Admin: Could not extract properties from pkt");
        logger.logStack(Logger.WARNING, emsg, e);
        throw new BrokerException(emsg, e);
    }
    if (msgType == null) {
        // Programming error. No need to I18N
        String emsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Message received on administration destination " + dest + " has no " + MessageType.JMQ_MESSAGE_TYPE + " property ignoring it.");
        logger.log(Logger.WARNING, emsg);
        throw new BrokerException(emsg);
    }
    /**
     */
    if (bridgeAdmin) {
        if (msgType.intValue() != MessageType.HELLO) {
            return super.handle(con, msg);
        }
    }
    // send the reply (if necessary)
    if (msg.getSendAcknowledge()) {
        Packet pkt = new Packet(con.useDirectBuffers());
        pkt.setPacketType(PacketType.SEND_REPLY);
        pkt.setConsumerID(msg.getConsumerID());
        Hashtable hash = new Hashtable();
        hash.put("JMQStatus", Integer.valueOf(Status.OK));
        pkt.setProperties(hash);
        con.sendControlMessage(pkt);
    }
    Producer pausedProducer = checkFlow(msg, con);
    if (pausedProducer != null) {
        DestinationUID duid = DestinationUID.getUID(msg.getDestination(), msg.getIsQueue());
        Destination[] ds = DL.findDestination(DL.getAdminPartition(), duid);
        Destination d = ds[0];
        pauseProducer(d, duid, pausedProducer, con);
    }
    // Administrative message. Process it.
    // Get message type property
    // Get AdminCmdHandler for this message type
    int t = msgType.intValue();
    AdminCmdHandler ach = null;
    /*
         * If the connection is authenticated using admin key authentication then it is considered "restricted" and can only
         * perform minimal operations. Anything else is forbidden.
         */
    if (con.getAccessController().isRestrictedAdmin() && t != MessageType.SHUTDOWN && t != MessageType.HELLO && t != MessageType.RESTART) {
        logger.log(Logger.WARNING, BrokerResources.W_FORBIDDEN_ADMIN_OP, MessageType.getString(t));
        Packet reply = new Packet(con.useDirectBuffers());
        reply.setPacketType(PacketType.OBJECT_MESSAGE);
        // By convention reply message is the message type + 1
        AdminCmdHandler.setProperties(reply, t + 1, Status.FORBIDDEN, null);
        sendReply(con, msg, reply);
        // done
        return true;
    }
    // if we arent shutdown .. track our handler cnt
    if (t != MessageType.SHUTDOWN && t != MessageType.MIGRATESTORE_BROKER) {
        incrementActiveHandlers();
    }
    try {
        if (BrokerStateHandler.isShuttingDown()) {
            String message = Globals.getBrokerResources().getKString(BrokerResources.I_ADMIN_BKR_SHUTTINGDOWN, MessageType.getString(t));
            logger.log(Logger.WARNING, message);
            Packet reply = new Packet(con.useDirectBuffers());
            reply.setPacketType(PacketType.OBJECT_MESSAGE);
            // By convention reply message is the message type + 1
            AdminCmdHandler.setProperties(reply, t + 1, Status.UNAVAILABLE, message);
            sendReply(con, msg, reply);
            // done
            return true;
        }
        if (!Broker.getBroker().startupComplete) {
            String message = Globals.getBrokerResources().getKString(BrokerResources.I_ADMIN_BKR_NOT_READY, MessageType.getString(t));
            logger.log(Logger.WARNING, message);
            Packet reply = new Packet(con.useDirectBuffers());
            reply.setPacketType(PacketType.OBJECT_MESSAGE);
            // By convention reply message is the message type + 1
            AdminCmdHandler.setProperties(reply, t + 1, Status.UNAVAILABLE, message);
            sendReply(con, msg, reply);
            // done
            return true;
        }
        try {
            ach = handlers[t];
        } catch (IndexOutOfBoundsException e) {
            logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Bad " + MessageType.JMQ_MESSAGE_TYPE + ": " + t, e);
            return true;
        }
        if (ach == null) {
            logger.log(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "No administration handler found for message type " + msgType + ". Ignoring.");
            return true;
        } else {
            // Call command handler to handle message
            try {
                return ach.handle(con, msg, props);
            } catch (Exception e) {
                // Excepion before sendReply
                int estatus = Status.ERROR;
                String emsg = e.getMessage();
                if (e instanceof BrokerException) {
                    estatus = ((BrokerException) e).getStatusCode();
                } else {
                    emsg = Globals.getBrokerResources().getKString(BrokerResources.X_INTERNAL_EXCEPTION, e.toString());
                }
                logger.logStack(Logger.ERROR, emsg, e);
                Packet reply = new Packet(con.useDirectBuffers());
                reply.setPacketType(PacketType.OBJECT_MESSAGE);
                AdminCmdHandler.setProperties(reply, t + 1, estatus, emsg);
                sendReply(con, msg, reply);
                // done
                return true;
            }
        }
    } finally {
        if (t != MessageType.SHUTDOWN && t != MessageType.MIGRATESTORE_BROKER) {
            decrementActiveHandlers();
        }
    }
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Hashtable(java.util.Hashtable) IOException(java.io.IOException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Producer(com.sun.messaging.jmq.jmsserver.core.Producer)

Example 47 with DestinationUID

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

the class TransactionList method logRemoteTransaction.

private void logRemoteTransaction(TransactionUID id, TransactionState ts, TransactionAcknowledgement[] txnAcks, BrokerAddress txnHomeBroker, boolean recovery, boolean newtxn, boolean localremote, boolean persist) throws BrokerException {
    RemoteTransactionInformation rti = null;
    boolean added = false;
    exclusiveLock.lock();
    try {
        rti = (RemoteTransactionInformation) remoteTranslist.get(id);
        if (newtxn) {
            if (rti != null || inuse_translist.contains(id) || translist.containsKey(id)) {
                throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_TRANSACTIONID_INUSE, id.toString()), BrokerResources.X_TRANSACTIONID_INUSE, (Throwable) null, Status.CONFLICT);
            }
        }
        if (rti == null) {
            rti = new RemoteTransactionInformation(id, ts, txnAcks, txnHomeBroker, recovery, localremote);
            inuse_translist.add(id);
            remoteTranslist.put(id, rti);
            added = true;
        }
    } finally {
        exclusiveLock.unlock();
    }
    if (!added) {
        if (!Globals.getHAEnabled()) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_TRANSACTIONID_INUSE, id.toString()), BrokerResources.X_TRANSACTIONID_INUSE, (Throwable) null, Status.CONFLICT);
        }
        // lock TransactionInformation object
        synchronized (rti) {
            if (!rti.getTransactionHomeBroker().equals(new TransactionBroker(txnHomeBroker))) {
                throw new BrokerException("Transaction home broker mismatch:" + txnHomeBroker.toString() + " but existed " + rti.getTransactionHomeBroker());
            }
            if (!recovery) {
                throw new BrokerException("XXXI18N-Internal Error: unexpected non-recovery, TUID=" + id);
            }
            if (rti.getState().getState() != ts.getState()) {
                throw new BrokerException("XXXI18N-Internal Error: state mismatch:" + TransactionState.toString(ts.getState()) + ", but exist" + TransactionState.toString(rti.getState().getState()) + "TUID=" + id);
            }
            rti.addRecoveryTransactionAcks(txnAcks);
        }
    }
    if (persist && added) {
        try {
            if (!Globals.getHAEnabled()) {
                if (!Globals.isNewTxnLogEnabled()) {
                    pstore.storeRemoteTransaction(id, ts, txnAcks, txnHomeBroker, Destination.PERSIST_SYNC);
                } else {
                    // store the dest ids as well so we can process txns more efficiently on restart
                    // (no need to load all destinations)
                    DestinationUID[] destIds = new DestinationUID[txnAcks.length];
                    for (int i = 0; i < txnAcks.length; i++) {
                        SysMessageID sid = txnAcks[i].getSysMessageID();
                        PacketReference p = DL.get(pstore, sid);
                        DestinationUID destID = null;
                        if (p != null) {
                            destID = p.getDestinationUID();
                        } else {
                            logger.log(Logger.WARNING, "Could not find packet for " + sid);
                        }
                        destIds[i] = destID;
                    }
                    RemoteTransaction remoteTransaction = new RemoteTransaction(id, ts, txnAcks, destIds, txnHomeBroker);
                    ((TxnLoggingStore) pstore).logTxn(remoteTransaction);
                }
            } else {
                pstore.updateRemoteTransaction(id, txnAcks, txnHomeBroker, Destination.PERSIST_SYNC);
            }
        } catch (Exception ex) {
            if (added) {
                exclusiveLock.lock();
                try {
                    inuse_translist.remove(id);
                    remoteTranslist.remove(id);
                } finally {
                    exclusiveLock.unlock();
                }
            }
            logger.logStack(Logger.ERROR, ex.getMessage() + (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage()), ex);
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_TRANSACTION_STORE_ERROR, id.toString()), BrokerResources.X_TRANSACTION_STORE_ERROR, ex, Status.ERROR);
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) TxnLoggingStore(com.sun.messaging.jmq.jmsserver.persist.api.TxnLoggingStore) IOException(java.io.IOException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 48 with DestinationUID

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

the class TransactionListLoader method handleMessageAcks.

static void handleMessageAcks(TransactionList transactionList, TransactionUID tid, TransactionWork txnWork) throws BrokerException {
    for (int i = 0; i < txnWork.numMessageAcknowledgments(); i++) {
        TransactionWorkMessageAck msgAck = txnWork.getMessageAcknowledgments().get(i);
        DestinationUID destID = msgAck.getDestUID();
        handleAck(transactionList, tid, destID, msgAck.getSysMessageID(), msgAck.getConsumerID());
    }
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID)

Example 49 with DestinationUID

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

the class TransactionListLoader method loadRemoteTransactions.

private static void loadRemoteTransactions(PartitionedStore store, TransactionList transactionList) throws BrokerException, IOException {
    List<BaseTransaction> incompleteTxns = ((TxnLoggingStore) store).getIncompleteTransactions(BaseTransaction.REMOTE_TRANSACTION_TYPE);
    String msg = " loading " + incompleteTxns.size() + " incomplete remote transactions:  ";
    logger.log(Logger.DEBUG, msg);
    Iterator<BaseTransaction> iter = incompleteTxns.iterator();
    while (iter.hasNext()) {
        RemoteTransaction remoteTxn = (RemoteTransaction) iter.next();
        TransactionUID tid = remoteTxn.getTid();
        TransactionState state = remoteTxn.getTransactionState();
        TransactionAcknowledgement[] tas = remoteTxn.getTxnAcks();
        DestinationUID[] destIds = remoteTxn.getDestIds();
        msg = " loadTransactions: processing remote transaction " + tid + " state= " + state;
        logger.log(Logger.DEBUG, msg);
        BrokerAddress remoteTransactionHomeBroker = remoteTxn.getTxnHomeBroker();
        transactionList.logRemoteTransaction(tid, state, tas, remoteTransactionHomeBroker, true, true, false);
        for (int i = 0; i < tas.length; i++) {
            TransactionAcknowledgement ta = tas[i];
            DestinationUID destId = destIds[i];
            unrouteLoadedTransactionAckMessage(store, destId, ta.getSysMessageID(), ta.getStoredConsumerUID());
        }
    }
}
Also used : BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) TxnLoggingStore(com.sun.messaging.jmq.jmsserver.persist.api.TxnLoggingStore)

Example 50 with DestinationUID

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

the class TransactionLogReplayer method replayAcknowledgedMessage.

private void replayAcknowledgedMessage(TransactionWorkMessageAck messageAck, Set dstLoadedSet) throws IOException, BrokerException {
    DestinationUID did = messageAck.getDestUID();
    SysMessageID mid = messageAck.getSysMessageID();
    ConsumerUID iid = messageAck.getConsumerID();
    if (Store.getDEBUG()) {
        String msg = getPrefix() + " replaying acknowledged message " + messageAck;
        logger.log(Logger.INFO, msg);
    }
    // Make sure dst exists; autocreate if possible
    Destination[] ds = Globals.getDestinationList().getDestination(msgStore.parent, did.getName(), did.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC, true, true);
    Destination dst = ds[0];
    // Load all msgs inorder to update consumer states
    if (!dstLoadedSet.contains(dst)) {
        dst.load();
        // Keep track of what has been loaded
        dstLoadedSet.add(dst);
    }
    if (msgStore.containsMessage(did, mid)) {
        logger.log(logger.FORCE, BrokerResources.I_UPDATE_INT_STATE_TXNLOG, iid, mid);
        // use try using the correct value; see bug 6516160
        if (dst.isQueue() && iid.longValue() != 0) {
            msgStore.updateInterestState(did, mid, PacketReference.getQueueUID(), PartitionedStore.INTEREST_STATE_ACKNOWLEDGED, false);
        } else {
            msgStore.updateInterestState(did, mid, iid, PartitionedStore.INTEREST_STATE_ACKNOWLEDGED, false);
        }
        acknowledgeOnReplay(dst, mid, iid);
    } else {
        logger.log(logger.FORCE, BrokerResources.I_DISREGARD_INT_STATE_TXNLOG, iid, mid);
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Aggregations

DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)61 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)25 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)20 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)20 Iterator (java.util.Iterator)18 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)16 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)16 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)10 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)9 ArrayList (java.util.ArrayList)9 Packet (com.sun.messaging.jmq.io.Packet)8 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)8 IOException (java.io.IOException)8 ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)6 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)6 HashMap (java.util.HashMap)6 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)5 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)5 Session (com.sun.messaging.jmq.jmsserver.core.Session)5 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)5