use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class TransactionDAOImpl method getRemoteTransactionStatesByBroker.
/**
* Retrieve all remote transaction states that this broker participates in.
*
* @param conn database connection
* @param brokerID the broker ID
* @return a Map of transaction IDs and TransactionState objects; an empty Map is returned if no transactions exist in
* the store
*/
@Override
public HashMap getRemoteTransactionStatesByBroker(Connection conn, String brokerID, Long storeSession) throws BrokerException {
HashMap map = new HashMap();
boolean myConn = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
Exception myex = null;
String sql = null;
try {
// Get a connection
DBManager dbMgr = DBManager.getDBManager();
if (conn == null) {
conn = dbMgr.getConnection(true);
myConn = true;
}
if (brokerID == null) {
brokerID = dbMgr.getBrokerID();
}
if (Globals.getHAEnabled()) {
sql = selectRemoteTxnStatesByBrokerAndTypeSQL;
} else {
sql = selectTxnStatesByBrokerAndTypeSQL;
}
if (storeSession != null) {
StoreSessionDAOImpl.checkStoreSessionOwner(conn, storeSession, brokerID);
if (Globals.getHAEnabled()) {
sql = selectRemoteTxnStatesBySessionAndTypeSQL;
} else {
sql = selectTxnStatesBySessionAndTypeSQL;
}
}
if (Globals.getHAEnabled()) {
pstmt = dbMgr.createPreparedStatement(conn, sql);
pstmt.setInt(1, TransactionInfo.TXN_CLUSTER);
if (storeSession != null) {
pstmt.setLong(2, storeSession.longValue());
pstmt.setLong(3, storeSession.longValue());
} else {
pstmt.setString(2, brokerID);
pstmt.setString(3, brokerID);
}
} else {
pstmt = dbMgr.createPreparedStatement(conn, sql);
if (storeSession != null) {
pstmt.setLong(1, storeSession.longValue());
} else {
pstmt.setString(1, brokerID);
}
pstmt.setInt(2, TransactionInfo.TXN_REMOTE);
}
rs = pstmt.executeQuery();
while (rs.next()) {
try {
long id = rs.getLong(1);
int state = rs.getInt(2);
TransactionState txnState = (TransactionState) Util.readObject(rs, 3);
// update state in TransactionState object
txnState.setState(state);
map.put(new TransactionUID(id), txnState);
} catch (IOException e) {
// fail to parse TransactionState object; just log it
logger.logStack(Logger.ERROR, BrokerResources.X_PARSE_TRANSACTION_FAILED, e);
}
}
} 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("[" + sql + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTIONS_FAILED), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
return map;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class TransactionDAOImpl method getTransactionsByBroker.
/**
* Retrieve all local and cluster transaction IDs owned by a broker.
*
* @param conn database connection
* @param brokerID the broker ID
* @return a List of TransactionUID objects; an empty List is returned if the broker does not have any transactions
*/
@Override
public List getTransactionsByBroker(Connection conn, String brokerID) throws BrokerException {
List list = new ArrayList();
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;
}
// Uses the same SQL to retrieve txn states
// but just fetchs the IDs only
pstmt = dbMgr.createPreparedStatement(conn, selectTxnStatesByBrokerSQL);
pstmt.setString(1, brokerID);
rs = pstmt.executeQuery();
while (rs.next()) {
list.add(new TransactionUID(rs.getLong(1)));
}
} 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("[" + selectTxnStatesByBrokerSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_TXNS_FOR_BROKER_FAILED, brokerID), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
return list;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method acknowledgeMessage.
/**
* Acknowledge a message to the broker.
*
* @param connectionId The Id of the connection
* @param sessionId The Id of the session
* @param consumerId The Id of the consumer for which to acknowledge the message
*
* @param sysMessageID The SysMessageID of the message to be acknowledged
*
* @param transactionId If non-zero, this is the transactionId in which to acknowledge the message.
*
* @param ackType The MessageAckType for this message acknowledgement
*
* @param retryCnt retry count of client runtime in delivery the message applicable to ackType DEAD_REQUEST
* UNDELIVERABLE_REQUEST or non-null transactionId should be 0 otherwise
* @param deadComment if ackType is DEAD_REQUEST
* @param deadThr if ackType is DEAD_REQUEST
*
* @return The JMSServiceReply which contains status and information about the acknowledge request.
*
* @throws JMSServiceException If the Status returned for the acknowledgeMessage method is not
* {@link JMSServiceReply.Status#OK}.<br>
* {@link JMSServiceException#getJMSServiceReply} should be used to obtain the broker reply in case of an exception.<br>
* The reason for the exception can be obtained from {@link JMSServiceReply.Status}
*/
@Override
public JMSServiceReply acknowledgeMessage(long connectionId, long sessionId, long consumerId, SysMessageID sysMessageID, long transactionId, MessageAckType ackType, int retryCnt, String deadComment, Throwable deadThr) throws JMSServiceException {
boolean validate = false;
TransactionUID txnUID = null;
int brokerAckType;
SysMessageID[] ids = null;
ConsumerUID[] cids = null;
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
cxn = checkConnectionId(connectionId, "acknowledgeMessage");
if (transactionId != 0) {
txnUID = new TransactionUID(transactionId);
}
brokerAckType = convertToBrokerAckType(ackType);
ids = new SysMessageID[1];
ids[0] = sysMessageID;
cids = new ConsumerUID[1];
cids[0] = new ConsumerUID(consumerId);
try {
/*
* TBD: validate - should the acks just be validated (normally false) deadThr - exception associated with a dead message
* (should be null if ackType != DEAD) deadComment - the explaination why a message was marked dead (should be null if
* ackType != DEAD) retryCnt - number of times a message was retried
*
*/
protocol.acknowledge(cxn, txnUID, validate, brokerAckType, deadThr, deadComment, retryCnt, ids, cids);
} catch (Exception e) {
String errStr = "acknowledgeMessage: Sending Acknowledgement failed. Connection ID: " + connectionId;
logger.logStack(Logger.ERROR, errStr, e);
props.put("JMQStatus", getErrorReplyStatus(e));
throw new JMSServiceException(errStr, e, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
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 sendAcknowledgement.
/**
* Send a message acknowledgement to the broker. All messages acknowledged by the method must be of the same
* MessageAckType
*
* @param connectionId The Id of the connection
* @param ackType The type of the acknowledgement
* @param acks The acknowledgements
*
* @throws JMSServiceException if the Status returned for the sendAcknowledgement method is not
* {@link JMSServiceReply.Status#OK}
*/
@Override
public JMSServiceReply sendAcknowledgement(long connectionId, MessageAckType ackType, JMSPacket acks) throws JMSServiceException {
boolean validate = false;
TransactionUID txnUID = null;
int brokerAckType;
int deliverCnt = -1;
SysMessageID[] ids = null;
ConsumerUID[] cids = null;
Throwable deadThr = null;
String deadComment = null;
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
cxn = checkConnectionId(connectionId, "sendAcknowledgement");
brokerAckType = convertToBrokerAckType(ackType);
try {
/*
* TBD: txnUID - transaction id associated with the acknowledgement (or null if no transaction) validate - should the
* acks just be validated (normally false) deadThr - exception associated with a dead message (should be null if ackType
* != DEAD) deadComment - the explaination why a message was marked dead (should be null if ackType != DEAD) deliverCnt
* - number of times a dead message was delivered (should be 0 if ackType != DEAD) ids - array of message ids to process
* cids - array of consumerIDs associated with a message, should directly correspond to the same index in ids
*/
protocol.acknowledge(cxn, txnUID, validate, brokerAckType, deadThr, deadComment, deliverCnt, ids, cids);
} catch (Exception e) {
String errStr = "sendAcknowledgement: Sending Acknowledgement failed. Connection ID: " + connectionId;
logger.logStack(Logger.ERROR, errStr, e);
props.put("JMQStatus", getErrorReplyStatus(e));
throw new JMSServiceException(errStr, e, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
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 recoverTransaction.
/**
* Recover a transaction from the broker.
*
* @param connectionId The Id of the connection
* @param transactionId The id of the transaction to recover
*
* @return The transactionId is returned if the transaction is in the PREPARED state. If the transaction is not found or
* not in the PREPARED state a zero (0L) is returned.
*/
@Override
public long recoverTransaction(long connectionId, long transactionId) throws JMSServiceException {
// IMQConnection cxn;
TransactionUID txnUID = null;
JMQXid[] jmqXids;
// cxn = checkConnectionId(connectionId, "recoverTransaction");
checkConnectionId(connectionId, "recoverTransaction");
txnUID = new TransactionUID(transactionId);
try {
jmqXids = protocol.recoverTransaction(txnUID);
if (jmqXids.length > 0) {
return (transactionId);
}
} catch (Exception e) {
String errStr = "recoverTransaction: recover transaction failed. Connection ID:" + connectionId + ", Transaction ID: " + transactionId;
logger.logStack(Logger.ERROR, errStr, e);
HashMap props = new HashMap();
props.put("JMQStatus", getErrorReplyStatus(e));
throw new JMSServiceException(errStr, e, props);
}
return (0);
}
Aggregations