use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class TransactionInfo method updateBrokerState.
public void updateBrokerState(TransactionBroker bkr) throws BrokerException {
TransactionBroker txnBkr = (TransactionBroker) bkrMap.get(bkr.getBrokerAddress());
if (txnBkr == null) {
throw new BrokerException("TransactionBroker " + bkr + " could not be found in the store", Status.NOT_FOUND);
}
// Just update the state
txnBkr.copyState(bkr);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class TransactionInfo method setTransactionBrokers.
public void setTransactionBrokers(TransactionBroker[] bkrs) {
if (!bkrMap.isEmpty()) {
bkrMap.clear();
}
if (bkrs == null) {
txnBkrs = null;
} else {
// TransactionBroker is mutable, so we must store a copy
int size = bkrs.length;
txnBkrs = new TransactionBroker[size];
StringBuilder debugBuf = null;
for (int i = 0; i < size; i++) {
TransactionBroker txnBkr = (TransactionBroker) bkrs[i].clone();
txnBkrs[i] = txnBkr;
if (DEBUG) {
if (debugBuf == null) {
debugBuf = new StringBuilder();
}
if (i > 0) {
debugBuf.append(',');
}
debugBuf.append(txnBkr);
}
// Create a lookup map (BrokerAddress -> TransactionBroker)
bkrMap.put(txnBkr.getBrokerAddress(), txnBkr);
}
// Verify that there are no duplicate
if (bkrMap.size() != size) {
String emsg = "Unexpected Error: duplicate TransactionBroker object found " + size + " size in database, mapped to size " + bkrMap.size() + (debugBuf == null ? "" : ", bkrs=" + debugBuf.toString() + ", bkrMap=" + bkrMap);
throw new IllegalArgumentException(emsg);
}
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker 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;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker 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.data.TransactionBroker 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);
}
}
}
Aggregations