Search in sources :

Example 16 with BrokerAddress

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

the class TransactionDAOImpl method getTransactionHomeBroker.

/**
 * Get the transaction home broker for the specified transaction.
 *
 * @param conn database connection
 * @param txnUID the transaction ID
 * @return BrokerAddress object
 */
@Override
public BrokerAddress getTransactionHomeBroker(Connection conn, TransactionUID txnUID) throws BrokerException {
    BrokerAddress txnHomeBroker = null;
    long id = txnUID.longValue();
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectTxnHomeBrokerSQL);
        pstmt.setLong(1, id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            txnHomeBroker = (BrokerAddress) Util.readObject(rs, 1);
        } else {
            throw new BrokerException(br.getKString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, String.valueOf(id)), Status.NOT_FOUND);
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectTxnHomeBrokerSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        BrokerException be = new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTION_FAILED, txnUID), ex);
        be.setSQLRecoverable(true);
        throw be;
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return txnHomeBroker;
}
Also used : BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) IOException(java.io.IOException)

Example 17 with BrokerAddress

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

the class ConsumerInfoNotifyManager method run.

@Override
public void run() {
    ArrayList pendingEvents = new ArrayList();
    while (!shutdown) {
        boolean dowait = true;
        List list = null;
        synchronized (eventQueue) {
            list = new ArrayList(eventQueue);
        }
        if (list.size() > 0 && pendingEvents.size() > 0) {
            Iterator itr = list.iterator();
            Object e = null;
            while (itr.hasNext()) {
                e = itr.next();
                if (!pendingEvents.contains(e)) {
                    dowait = false;
                    break;
                }
            }
        } else if (pendingEvents.size() == 0) {
            dowait = eventQueue.isEmpty();
        }
        synchronized (this) {
            if (dowait || eventQueue.isEmpty()) {
                try {
                    wait();
                } catch (InterruptedException inte) {
                }
            }
        }
        if (shutdown) {
            return;
        }
        HashMap notifications = new HashMap();
        Object[] events = eventQueue.toArray();
        Object o = null;
        for (int i = 0; i < events.length && !shutdown; i++) {
            o = events[i];
            if (DEBUG) {
                logger.log(logger.INFO, "Processing " + o);
            }
            if (o instanceof ConsumerAddedEvent) {
                ConsumerAddedEvent e = (ConsumerAddedEvent) o;
                IMQConnection conn = (IMQConnection) cm.getConnection(e.connid);
                if (e.dest.getAllActiveConsumerCount() > 0) {
                    if (conn == null || conn.isConnectionStarted()) {
                        notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_READY));
                    } else {
                        pendingEvents.add(o);
                        continue;
                    }
                } else {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_NOT_READY));
                }
                eventQueue.remove(o);
                pendingEvents.remove(o);
                continue;
            }
            if (o instanceof RemoteConsumerAddedEvent) {
                RemoteConsumerAddedEvent e = (RemoteConsumerAddedEvent) o;
                if (e.dest.getAllActiveConsumerCount() > 0) {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_READY));
                } else {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_NOT_READY));
                }
                eventQueue.remove(o);
                continue;
            }
            if (o instanceof ConsumerRemovedEvent) {
                ConsumerRemovedEvent e = (ConsumerRemovedEvent) o;
                if (e.dest.getAllActiveConsumerCount() == 0) {
                    notifications.put(e.dest.getDestinationUID(), new ConsumerInfoNotification(e.dest.getDestinationUID(), e.dest.getType(), CONSUMER_NOT_READY));
                }
                eventQueue.remove(o);
                continue;
            }
            if (o instanceof ConnectionStartedEvent) {
                ConnectionStartedEvent e = (ConnectionStartedEvent) o;
                for (int j = 0; j < events.length && !shutdown; j++) {
                    Object oo = events[j];
                    if (oo instanceof ConsumerAddedEvent) {
                        ConsumerAddedEvent ee = (ConsumerAddedEvent) oo;
                        IMQConnection conn = (IMQConnection) cm.getConnection(ee.connid);
                        if (conn != null && conn == e.conn && ee.dest.getAllActiveConsumerCount() > 0) {
                            notifications.put(ee.dest.getDestinationUID(), new ConsumerInfoNotification(ee.dest.getDestinationUID(), ee.dest.getType(), CONSUMER_READY));
                            pendingEvents.remove(ee);
                        }
                    }
                }
                eventQueue.remove(e);
                continue;
            }
            if (o instanceof ConsumerInfoRequestEvent) {
                boolean foundmatch = false;
                boolean hasconsumer = false;
                boolean notifyadded = false;
                ConsumerInfoRequestEvent e = (ConsumerInfoRequestEvent) o;
                Iterator[] itrs = DestinationList.getAllDestinations(null);
                // PART
                Iterator itr = itrs[0];
                while (itr.hasNext()) {
                    Destination d = (Destination) itr.next();
                    if (d.isInternal()) {
                        continue;
                    }
                    if ((!e.duid.isWildcard() && d.getDestinationUID().equals(e.duid))) {
                        foundmatch = true;
                        if (d.getAllActiveConsumerCount() == 0) {
                            notifications.put(d.getDestinationUID(), new ConsumerInfoNotification(d.getDestinationUID(), d.getType(), CONSUMER_NOT_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                            notifyadded = true;
                            break;
                        }
                        hasconsumer = true;
                        Iterator itrr = d.getAllActiveConsumers().iterator();
                        while (itrr.hasNext()) {
                            Consumer c = (Consumer) itrr.next();
                            IMQConnection conn = (IMQConnection) cm.getConnection(c.getConnectionUID());
                            BrokerAddress ba = c.getConsumerUID().getBrokerAddress();
                            if ((conn != null && conn.isConnectionStarted()) || (ba != null && ba != Globals.getMyAddress())) {
                                notifications.put(d.getDestinationUID(), new ConsumerInfoNotification(d.getDestinationUID(), d.getType(), CONSUMER_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                                notifyadded = true;
                                break;
                            }
                        }
                        break;
                    }
                    if (e.duid.isWildcard() && DestinationUID.match(d.getDestinationUID(), e.duid)) {
                        foundmatch = true;
                        if (d.getAllActiveConsumerCount() == 0) {
                            continue;
                        }
                        hasconsumer = true;
                        Iterator itrr = d.getAllActiveConsumers().iterator();
                        while (itrr.hasNext()) {
                            Consumer c = (Consumer) itrr.next();
                            IMQConnection conn = (IMQConnection) cm.getConnection(c.getConnectionUID());
                            BrokerAddress ba = c.getConsumerUID().getBrokerAddress();
                            if ((conn != null && conn.isConnectionStarted()) || (ba != null && ba != Globals.getMyAddress())) {
                                notifications.put(d.getDestinationUID(), new ConsumerInfoNotification(d.getDestinationUID(), e.destType, CONSUMER_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                                notifyadded = true;
                                break;
                            }
                        }
                        if (notifyadded) {
                            break;
                        }
                    }
                }
                if (!foundmatch || (!hasconsumer && !notifyadded)) {
                    notifications.put(e.duid, new ConsumerInfoNotification(e.duid, e.destType, CONSUMER_NOT_READY, ((ConsumerInfoRequestEvent) o).infoType, true));
                }
                eventQueue.remove(o);
            }
        }
        Iterator itr = notifications.values().iterator();
        ConsumerInfoNotification cin = null;
        while (itr.hasNext()) {
            cin = (ConsumerInfoNotification) itr.next();
            if (DEBUG) {
                logger.log(logger.INFO, "Sending " + cin);
            }
            if (cin.shouldNotify()) {
                cm.sendConsumerInfo(InfoRequestHandler.REQUEST_CONSUMER_INFO, cin.duid, cin.destType, cin.infoType, cin.sendToWildcard);
            }
        }
        notifications.clear();
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) Iterator(java.util.Iterator) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with BrokerAddress

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

the class BrokerConsumers method commitRecoveryRemoteTransaction.

private boolean commitRecoveryRemoteTransaction(TransactionList translist, TransactionUID tid, com.sun.messaging.jmq.jmsserver.core.BrokerAddress from) throws BrokerException {
    logger.log(logger.INFO, "Committing recovery remote transaction " + tid + " from " + from);
    TransactionBroker ba = translist.getRemoteTransactionHomeBroker(tid);
    BrokerAddress currba = (ba == null) ? null : ba.getCurrentBrokerAddress();
    if (currba == null || !currba.equals(from)) {
        logger.log(logger.WARNING, "Committed remote transaction " + tid + " home broker " + ba + " not " + from);
    }
    RemoteTransactionAckEntry[] tae = translist.getRecoveryRemoteTransactionAcks(tid);
    if (tae == null) {
        logger.log(logger.WARNING, "No recovery transaction acks to process for committing remote transaction " + tid);
        return true;
    }
    boolean done = true;
    for (int j = 0; j < tae.length; j++) {
        if (tae[j].processed()) {
            continue;
        }
        TransactionAcknowledgement[] tas = tae[j].getAcks();
        for (int i = 0; i < tas.length; i++) {
            SysMessageID sysid = tas[i].getSysMessageID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID uid = tas[i].getConsumerUID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID suid = tas[i].getStoredConsumerUID();
            if (suid == null) {
                suid = uid;
            }
            // PART
            PacketReference ref = DL.get(null, sysid);
            if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
                continue;
            }
            try {
                if (ref.acknowledged(uid, suid, true, true)) {
                    ref.getDestination().removeMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
                }
            } catch (Exception ex) {
                done = false;
                logger.logStack(Logger.ERROR, Globals.getBrokerResources().E_INTERNAL_BROKER_ERROR, ex.getMessage(), ex);
            }
        }
    }
    return done;
}
Also used : TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) IOException(java.io.IOException) AckEntryNotFoundException(com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 19 with BrokerAddress

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

the class BrokerConsumers method rollbackRecoveryRemoteTransaction.

private void rollbackRecoveryRemoteTransaction(TransactionList translist, TransactionUID tid, com.sun.messaging.jmq.jmsserver.core.BrokerAddress from) throws BrokerException {
    logger.log(logger.INFO, "Rolling back recovery remote transaction " + tid + " from " + from);
    TransactionState ts = translist.getRemoteTransactionState(tid);
    if (ts == null || ts.getState() != TransactionState.ROLLEDBACK) {
        throw new BrokerException(Globals.getBrokerResources().E_INTERNAL_BROKER_ERROR, "Unexpected broker state " + ts + " for processing Rolledback remote transaction " + tid);
    }
    TransactionBroker ba = translist.getRemoteTransactionHomeBroker(tid);
    BrokerAddress currba = (ba == null) ? null : ba.getCurrentBrokerAddress();
    if (currba == null || !currba.equals(from)) {
        logger.log(logger.WARNING, "Rolledback remote transaction " + tid + " home broker " + ba + " not " + from);
    }
    RemoteTransactionAckEntry[] tae = translist.getRecoveryRemoteTransactionAcks(tid);
    if (tae == null) {
        logger.log(logger.WARNING, "No recovery transaction acks to process for rolling back remote transaction " + tid);
        return;
    }
    for (int j = 0; j < tae.length; j++) {
        if (tae[j].processed()) {
            continue;
        }
        TransactionAcknowledgement[] tas = tae[j].getAcks();
        for (int i = 0; i < tas.length; i++) {
            SysMessageID sysid = tas[i].getSysMessageID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID cuid = tas[i].getConsumerUID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID suid = tas[i].getStoredConsumerUID();
            if (suid == null) {
                suid = cuid;
            }
            // PART
            PacketReference ref = DL.get(null, sysid);
            if (ref == null) {
                if (getDEBUG()) {
                    logger.log(logger.INFO, "[" + sysid + ":" + cuid + "] reference not found in rolling back recovery remote transaction " + tid);
                }
                continue;
            }
            ref.getDestination().forwardOrphanMessage(ref, suid);
        }
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 20 with BrokerAddress

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

the class GetTransactionsHandler method getTransactionInfo.

private static Hashtable getTransactionInfo(TransactionList tl, TransactionUID id, int type, boolean showpartition) {
    Logger logger = Globals.getLogger();
    TransactionState ts = tl.retrieveState(id);
    if (type == LOCAL) {
        ts = tl.retrieveState(id, true);
    } else if (type == CLUSTER) {
        ts = tl.retrieveState(id, true);
    } else if (type == REMOTE) {
        ts = tl.getRemoteTransactionState(id);
    }
    if (ts == null) {
        return null;
    }
    JMQXid xid = tl.UIDToXid(id);
    Hashtable table = new Hashtable();
    table.put("type", Integer.valueOf(type));
    if (xid != null) {
        table.put("xid", xid.toString());
    }
    PartitionedStore pstore = tl.getPartitionedStore();
    table.put("txnid", Long.valueOf(id.longValue()) + (showpartition ? "[" + pstore.getPartitionID() + (pstore.isPrimaryPartition() ? "*]" : "]") : ""));
    if (ts.getUser() != null) {
        table.put("user", ts.getUser());
    }
    if (ts.getClientID() != null) {
        table.put("clientid", ts.getClientID());
    }
    table.put("timestamp", Long.valueOf(System.currentTimeMillis() - id.age()));
    table.put("connection", ts.getConnectionString());
    table.put("nmsgs", Integer.valueOf(tl.retrieveNSentMessages(id)));
    if (type != REMOTE) {
        table.put("nacks", Integer.valueOf(tl.retrieveNConsumedMessages(id)));
    } else {
        table.put("nacks", Integer.valueOf(tl.retrieveNRemoteConsumedMessages(id)));
    }
    table.put("state", Integer.valueOf(ts.getState()));
    ConnectionUID cuid = ts.getConnectionUID();
    if (cuid != null) {
        table.put("connectionid", Long.valueOf(cuid.longValue()));
    }
    TransactionBroker homeBroker = tl.getRemoteTransactionHomeBroker(id);
    String homeBrokerStr = "";
    if (homeBroker != null) {
        homeBrokerStr = homeBroker.getBrokerAddress().toString();
    }
    table.put("homebroker", homeBrokerStr);
    TransactionBroker[] brokers = null;
    if (type != REMOTE) {
        try {
            brokers = tl.getClusterTransactionBrokers(id);
        } catch (BrokerException be) {
            logger.log(Logger.WARNING, "Exception caught while obtaining list of brokers in transaction", be);
        }
    }
    StringBuilder allBrokers = new StringBuilder();
    StringBuilder pendingBrokers = new StringBuilder();
    if (brokers != null) {
        for (int i = 0; i < brokers.length; ++i) {
            TransactionBroker oneBroker = brokers[i];
            BrokerAddress addr = oneBroker.getBrokerAddress();
            if (allBrokers.length() != 0) {
                allBrokers.append(", ");
            }
            allBrokers.append(addr);
            if (oneBroker.isCompleted()) {
                continue;
            }
            if (pendingBrokers.length() != 0) {
                pendingBrokers.append(", ");
            }
            pendingBrokers.append(addr);
        }
    }
    table.put("allbrokers", allBrokers.toString());
    table.put("pendingbrokers", pendingBrokers.toString());
    return table;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) Hashtable(java.util.Hashtable) Logger(com.sun.messaging.jmq.util.log.Logger) JMQXid(com.sun.messaging.jmq.util.JMQXid) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Aggregations

BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)34 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)18 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)14 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)10 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)9 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)9 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)9 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 UID (com.sun.messaging.jmq.util.UID)7 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)7 ArrayList (java.util.ArrayList)7 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)6 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)6 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)5 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)5 Iterator (java.util.Iterator)5 List (java.util.List)5 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)4