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;
}
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();
}
}
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;
}
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);
}
}
}
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;
}
Aggregations