use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method commitTransaction.
/**
* Commit a transaction.
*
* @param connectionId The Id of the connection
* @param transactionId If non-zero, the transaction being committed is identified by this broker-generated id
* @param xid If transactionId is zero, then xid contains the Xid of the XA transaction being committed
* @param flags If this is an XA transaction, then flags is one of:
* <UL>
* <LI>XAResource.TMONEPHASE:One phase commit. The transaction need not be in the PREPARED state</LI>
* <LI>XAResource.TMNOFLAGS: Two phase commit. The transaction must be in the PREPARED state</LI>
* </UL>
*
* @return The JMSServiceReply of the request to commit a transaction
*
* @throws JMSServiceException if the Status returned for the commitTransaction method is not
* {@link JMSServiceReply.Status#OK}
*
* @see JMSServiceReply.Status#getJMQTransactionID
*
* @see JMSServiceReply.Status#BAD_REQUEST
* @see JMSServiceReply.Status#NOT_FOUND
* @see JMSServiceReply.Status#PRECONDITION_FAILED
* @see JMSServiceReply.Status#TIMEOUT
* @see JMSServiceReply.Status#ERROR
*/
@Override
public JMSServiceReply commitTransaction(long connectionId, long transactionId, Xid xid, int flags) throws JMSServiceException {
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
TransactionUID txnUID = null;
JMQXid jmqXid = null;
Integer xaFlags;
cxn = checkConnectionId(connectionId, "commitTransaction");
txnUID = new TransactionUID(transactionId);
if (xid != null) {
jmqXid = new JMQXid(xid);
}
xaFlags = Integer.valueOf(flags);
try {
protocol.commitTransaction(txnUID, jmqXid, xaFlags, cxn);
} catch (BrokerException be) {
String errStr = "CommitTransaction: commit failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId;
logger.logStack(Logger.ERROR, errStr, be);
props.put("JMQStatus", getErrorReplyStatus(be));
throw new JMSServiceException(errStr, be, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
props.put("JMQTransactionID", txnUID.longValue());
reply = new JMSServiceReply(props);
return (reply);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method startTransaction.
/**
* Start a transaction.
*
* @param connectionId The Id of the connection
* @param sessionId If non-zero, this is the Id of the session in which the transaction is being created. This parameter
* is zero for XA transactions
* @param xid If non-null, an XA transaction is being started
* @param flags If xId is non-null, then flags is one of:
* <p>
* <UL>
* <LI>XAResource.TMNOFLAGS = start a brand new transaction</LI>
* <LI>XAResource.TMRESUNE = resume a previously suspended transaction</LI>
* </UL>
* @param rollback The type of transaction rollback behavior to use
* @param timeout The transaction timeout to use. The timeout is the maximum time in seconds that the transaction will
* be allowed to be in an un-prepared state.
*
* @return The JMSServiceReply of the request to start a transaction
*
* @throws JMSServiceException if the Status returned for the startTransaction method is not
* {@link JMSServiceReply.Status#OK}
*/
@Override
public JMSServiceReply startTransaction(long connectionId, long sessionId, Xid xid, int flags, JMSService.TransactionAutoRollback rollback, long timeout) throws JMSServiceException {
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
TransactionUID txnUID = null;
JMQXid jmqXid = null;
Integer xaFlags = null;
cxn = checkConnectionId(connectionId, "startTransaction");
if (xid != null) {
jmqXid = new JMQXid(xid);
xaFlags = Integer.valueOf(flags);
}
try {
txnUID = protocol.startTransaction(jmqXid, xaFlags, null, /* type */
timeout, cxn);
} catch (BrokerException be) {
String errStr = "startTransaction: start transaction failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", XID: " + xid;
logger.logStack(Logger.ERROR, errStr, be);
props.put("JMQStatus", getErrorReplyStatus(be));
throw new JMSServiceException(errStr, be, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
props.put("JMQTransactionID", txnUID.longValue());
reply = new JMSServiceReply(props);
return (reply);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class IMQConnection method cleanUpTransactions.
private synchronized void cleanUpTransactions() {
logger.log(Logger.DEBUG, "Cleaning up transactions on connection " + this);
List conlist = (List) getClientData(TRANSACTION_LIST);
if (conlist != null) {
boolean xaretainall = Globals.getConfig().getBooleanProperty(TransactionList.XA_TXN_DETACHED_RETAINALL_PROP, false);
ArrayList timeoutTIDs = new ArrayList();
TransactionUID tid = null;
boolean xaretainallLogged = false;
TransactionHandler rollbackHandler = (TransactionHandler) Globals.getPacketRouter(0).getHandler(PacketType.ROLLBACK_TRANSACTION);
TransactionList[] tls = Globals.getDestinationList().getTransactionList(pstore);
TransactionList tl = tls[0];
TransactionUID[] tuids = (TransactionUID[]) conlist.toArray(new TransactionUID[conlist.size()]);
for (int i = 0; i < tuids.length; i++) {
tid = tuids[i];
TransactionState ts = tl.retrieveState(tid);
if (ts == null) {
// nothing to do if no transaction state
continue;
}
int tstate = ts.getState();
if (tstate == TransactionState.PREPARED && ts.getOnephasePrepare()) {
ts.detachedFromConnection();
timeoutTIDs.add(tid);
String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate) + "[onephase=true]", getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
if (ts.getXid() != null) {
if (xaretainall) {
if (!xaretainallLogged) {
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_RETAIN_XA));
xaretainallLogged = true;
}
continue;
}
if (tstate > TransactionState.COMPLETE) {
String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate), getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
if (tstate == TransactionState.INCOMPLETE || tstate == TransactionState.COMPLETE) {
ts.detachedFromConnection();
timeoutTIDs.add(tid);
String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate), getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
}
if (tstate == TransactionState.PREPARED || tstate == TransactionState.COMMITTED || tstate == TransactionState.ROLLEDBACK) {
String[] args = { "" + tid, TransactionState.toString(tstate), getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
if (DEBUG || DEBUG_TXN) {
logger.log(Logger.INFO, "Cleanup connection [" + getConnectionUID() + "]: cleaning up transaction " + tid + "[" + TransactionState.toString(tstate) + "]");
}
try {
rollbackHandler.doRollback(tl, tid, ts.getXid(), null, ts, conlist, null, RollbackReason.CONNECTION_CLEANUP);
} catch (Exception e) {
String[] args = { "" + tid + "[" + TransactionState.toString(tstate) + "]", getConnectionUID().toString(), e.getMessage() };
logger.logStack(logger.WARNING, Globals.getBrokerResources().getString(BrokerResources.W_CONN_CLEANUP_ROLLBACK_TRAN_FAIL, args), e);
}
}
Iterator itr = timeoutTIDs.iterator();
while (itr.hasNext()) {
tid = (TransactionUID) itr.next();
tl.addDetachedTransactionID(tid);
}
timeoutTIDs.clear();
conlist.clear();
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class BrokerConsumers method getDebugState.
public Hashtable getDebugState() {
Hashtable ht = new Hashtable();
ArrayList l = null;
synchronized (deliveredMessages) {
l = new ArrayList(deliveredMessages.values());
}
ht.put("CLUSTER_ROUTER:deliveredMessagesCount", l.size());
Iterator itr = l.iterator();
while (itr.hasNext()) {
AckEntry e = (AckEntry) itr.next();
SysMessageID id = e.getSysMessageID();
ht.put("[deliveredMessages]" + id.toString(), e.toString());
}
synchronized (consumers) {
l = new ArrayList(consumers.keySet());
}
ht.put("consumersCount", l.size());
itr = l.iterator();
while (itr.hasNext()) {
ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
Consumer c = (Consumer) consumers.get(cuid);
if (c instanceof Subscription) {
ht.put("[consumers]" + cuid.toString(), "Subscription: " + c);
} else {
ht.put("[consumers]" + cuid.toString(), c.toString());
}
}
synchronized (activeConsumers) {
l = new ArrayList(activeConsumers);
}
ht.put("activeConsumersCount", l.size());
Vector v = new Vector();
itr = l.iterator();
while (itr.hasNext()) {
Consumer c = (Consumer) itr.next();
if (c instanceof Subscription) {
v.add("Subscription: " + c);
} else {
v.add(c.toString());
}
}
ht.put("activeConsumers", v);
synchronized (pendingConsumerUIDs) {
l = new ArrayList(pendingConsumerUIDs.keySet());
}
ht.put("pendingConsumerUIDsCount", l.size());
itr = l.iterator();
while (itr.hasNext()) {
ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
Map<TransactionUID, Set<AckEntry>> pending0, pending = null;
synchronized (deliveredMessages) {
pending0 = pendingConsumerUIDs.get(cuid);
if (pending0 != null) {
pending = new LinkedHashMap<>(pending0);
}
}
if (pending == null) {
ht.put("[pendingConsumerUIDs]" + cuid.toString(), "null");
} else {
Hashtable htt = new Hashtable();
Map.Entry<TransactionUID, Set<AckEntry>> pair = null;
TransactionUID key = null;
Iterator<Map.Entry<TransactionUID, Set<AckEntry>>> itr1 = pending.entrySet().iterator();
while (itr1.hasNext()) {
pair = itr1.next();
key = pair.getKey();
htt.put("PENDING-TID:" + (key == null ? "null" : key), new Vector(pair.getValue()));
}
ht.put("[pendingConsumerUIDs]" + cuid.toString(), htt);
}
}
synchronized (cleanupList) {
l = new ArrayList(cleanupList.keySet());
}
ht.put("cleanupListCount", l.size());
v = new Vector();
itr = l.iterator();
while (itr.hasNext()) {
ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
v.add(cuid.toString());
}
ht.put("cleanupList", v);
synchronized (listeners) {
l = new ArrayList(listeners.keySet());
}
ht.put("listenersCount", l.size());
v = new Vector();
itr = l.iterator();
while (itr.hasNext()) {
ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
v.add(cuid.toString());
}
ht.put("listeners", v);
return ht;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class BrokerConsumers method getPendingConsumerUID.
private List<AckEntry> getPendingConsumerUID(TransactionUID tid) {
assert Thread.holdsLock(deliveredMessages);
Set<Map<TransactionUID, Set<AckEntry>>> maps = null;
synchronized (pendingConsumerUIDs) {
maps = new LinkedHashSet<>(pendingConsumerUIDs.values());
}
Map<TransactionUID, Set<AckEntry>> map = null;
Iterator<Map<TransactionUID, Set<AckEntry>>> itr = maps.iterator();
while (itr.hasNext()) {
map = itr.next();
if (map == null) {
continue;
}
TransactionUID mytid = null;
Map.Entry<TransactionUID, Set<AckEntry>> pair = null;
Iterator<Map.Entry<TransactionUID, Set<AckEntry>>> itr1 = map.entrySet().iterator();
while (itr1.hasNext()) {
pair = itr1.next();
mytid = pair.getKey();
if (mytid == null || !mytid.equals(tid)) {
continue;
}
return new ArrayList<>(pair.getValue());
}
}
return new ArrayList<>();
}
Aggregations