use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class ProtocolImpl method recoverTransaction.
/**
* Recover a transaction.
*
* @param id id to recover or null if all
*/
@Override
public JMQXid[] recoverTransaction(TransactionUID id) {
if (DEBUG) {
logger.log(Logger.INFO, "ProtocolImpl.RECOVER TRANSACTION:TID=" + id);
}
// TransactionHandler handler = (TransactionHandler)
// pr.getHandler(PacketType.START_TRANSACTION);
TransactionList[] tls = DL.getTransactionList(null);
TransactionList tl = null;
TransactionState ts = null;
Map<TransactionList, Vector> map = new LinkedHashMap<>();
Vector v = null;
for (int i = 0; i < tls.length; i++) {
tl = tls[i];
if (id == null) {
v = tl.getTransactions(TransactionState.PREPARED);
map.put(tl, v);
} else {
ts = tl.retrieveState(id);
if (ts == null) {
continue;
}
if (ts.getState() == TransactionState.PREPARED) {
v = new Vector();
v.add(id);
map.put(tl, v);
break;
}
}
}
ArrayList xids = new ArrayList();
for (Map.Entry<TransactionList, Vector> pair : map.entrySet()) {
tl = pair.getKey();
v = pair.getValue();
Iterator itr = v.iterator();
while (itr.hasNext()) {
TransactionUID tuid = (TransactionUID) itr.next();
TransactionState _ts = tl.retrieveState(tuid);
if (_ts == null) {
// Should never happen
continue;
}
JMQXid _xid = _ts.getXid();
xids.add(_xid);
}
}
return (JMQXid[]) xids.toArray(new JMQXid[xids.size()]);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class RaptorProtocol method receivedTransactionInfo.
public void receivedTransactionInfo(GPacket pkt, BrokerAddress sender, MessageBusCallback cb) {
ClusterTxnInfoInfo ii = ClusterTxnInfoInfo.newInstance(pkt, c);
BrokerAddress from = sender;
UID msgss = ii.getMessageStoreSessionUID();
if (msgss != null) {
from = (BrokerAddress) sender.clone();
from.setStoreSessionUID(msgss);
}
if (DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, Globals.getBrokerResources().getString(BrokerResources.I_RECEIVED_TXN_INFO, from.toString(), ii.toString()));
}
Long tid = ii.getTransactionID();
TransactionUID tuid = new TransactionUID(tid.longValue());
int s = ii.getTransactionState();
TransactionList tl = null;
TransactionState mystate = null;
Object[] oo = TransactionList.getTransListAndState(tuid, null, true, false);
if (oo != null) {
tl = (TransactionList) oo[0];
mystate = (TransactionState) oo[1];
}
if (!ii.isOwner() || (ii.isOwner() && from.equals(selfAddress))) {
if (mystate != null && mystate.getState() == TransactionState.COMMITTED) {
if (tl.getClusterTransactionBroker(tuid, from) != null) {
if (s == TransactionState.COMMITTED || (!ii.isOwner() && s == TransactionState.NULL)) {
if (DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "Update broker " + from + " for committed cluster transaction " + tuid);
}
try {
tl.completeClusterTransactionBrokerState(tuid, TransactionState.COMMITTED, from, true);
if (!ii.isOwner() && s != TransactionState.NULL) {
sendClusterTransactionInfo(tuid, from, null);
}
} catch (Exception e) {
logger.logStack(logger.WARNING, "Unable to update transaction broker state for " + from + ", TUID=" + tuid, e);
if (!ii.isOwner()) {
return;
}
}
}
} else {
if (DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "Broker " + from + " is not a transaction broker for TUID=" + tuid);
}
}
if (!ii.isOwner()) {
return;
}
}
}
if (s == TransactionState.NULL && !ii.isOwner()) {
return;
}
List<Object[]> list = TransactionList.getTransListsAndRemoteTranStates(tuid);
if (list == null && !ii.isOwner()) {
return;
}
if (list == null && ii.isOwner()) {
try {
if (ii.getWaitfor() != null && ii.isWaitedfor((selfAddress))) {
sendRemoteTransactionInfo(tuid, from, null, true);
return;
}
} catch (Exception e) {
logger.logStack(logger.WARNING, e.getMessage(), e);
return;
}
// for rollback pending unprepared
if (s != TransactionState.NULL) {
return;
}
}
int type = -1;
switch(s) {
case TransactionState.ROLLEDBACK:
case TransactionState.FAILED:
type = ClusterGlobals.MB_MSG_TXN_ROLLEDBACK;
break;
case TransactionState.NULL:
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_REMOTE_TXN_PRESUMED_ROLLBACK, tuid, from));
type = ClusterGlobals.MB_MSG_TXN_ROLLEDBACK;
break;
case TransactionState.COMMITTED:
type = ClusterGlobals.MB_MSG_CONSUMED;
break;
default:
return;
}
try {
cb.processRemoteAck2P(null, null, type, null, tid, from);
if (s == TransactionState.COMMITTED && ii.isOwner()) {
BrokerAddress[] brokers = ii.getBrokers();
List waitfor = ii.getWaitfor();
if (brokers == null && waitfor == null) {
return;
}
if (waitfor != null) {
sendRemoteTransactionInfo(tuid, from, null, true);
}
}
} catch (Exception e) {
if (DEBUG_CLUSTER_TXN) {
logger.logStack(logger.WARNING, e.getMessage(), e);
} else {
logger.log(logger.WARNING, e.getMessage());
}
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class CallbackDispatcher method processCommitAck.
private boolean processCommitAck(final BrokerAddress sender, final GPacket pkt) {
if (!ClusterMessageAckInfo.isAckAckAsync(pkt)) {
return false;
}
Integer acktype = ClusterMessageAckInfo.getAckAckType(pkt);
if (acktype == null || acktype.intValue() != ClusterGlobals.MB_MSG_CONSUMED) {
return false;
}
Long transactionID = ClusterMessageAckInfo.getAckAckTransactionID(pkt);
if (transactionID == null) {
return false;
}
if (ClusterMessageAckInfo.getAckAckStatus(pkt) != Status.OK) {
logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_MSG_ACK_FAILED_FROM_HOME, sender, ClusterMessageAckInfo.toString(pkt)));
return true;
}
if (DEBUG_CLUSTER_TXN || DEBUG) {
logger.log(logger.INFO, "processCommitAck: Received " + ProtocolGlobals.getPacketTypeDisplayString(pkt.getType()) + " from " + sender + ": " + ClusterMessageAckInfo.toString(pkt));
}
if (fi.FAULT_INJECTION) {
ClusterMessageAckInfo.CHECKFAULT(new HashMap(), ClusterGlobals.MB_MSG_CONSUMED, transactionID, FaultInjection.MSG_REMOTE_ACK_P, FaultInjection.STAGE_3);
}
try {
final TransactionUID tuid = new TransactionUID(transactionID.longValue());
final UID ss = ClusterMessageAckInfo.getAckAckStoreSessionUID(pkt);
commitAckExecutor.execute(new Runnable() {
@Override
public void run() {
try {
BrokerAddress addr = sender;
if (ss != null) {
addr = (BrokerAddress) sender.clone();
addr.setStoreSessionUID(ss);
}
Object[] oo = TransactionList.getTransListAndState(tuid, null, true, false);
if (oo == null) {
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.W_TXN_NOT_FOUND_ON_UPDATE_TXN_COMPLETION_FOR_BKR, tuid, addr));
return;
}
TransactionList tl = (TransactionList) oo[0];
tl.completeClusterTransactionBrokerState(tuid, TransactionState.COMMITTED, addr, true);
} catch (Throwable t) {
Object[] args = { tuid, sender + "[" + ClusterMessageAckInfo.toString(pkt) + "]", t.getMessage() };
String emsg = br.getKString(br.W_UNABLE_UPDATE_CLUSTER_TXN_COMPLETE_STATE, args);
if (t instanceof BrokerException) {
if (((BrokerException) t).getStatusCode() == Status.NOT_FOUND) {
if (DEBUG_CLUSTER_TXN || DEBUG) {
logger.log(logger.WARNING, emsg + " - already completed");
}
return;
}
}
logger.logStack(logger.WARNING, emsg, t);
}
}
});
} catch (Throwable t) {
if (stopThread) {
logger.log(logger.DEBUG, "Cluster shutdown, ignore event " + ClusterMessageAckInfo.toString(pkt) + " from " + sender);
} else {
logger.logStack(logger.WARNING, "Exception in submitting for processing " + ClusterMessageAckInfo.toString(pkt) + " from " + sender, t);
}
}
return true;
}
Aggregations