use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method prepareTransaction.
/**
* Pepare a transaction.
*
* @param connectionId The Id of the connection
* @param transactionId If non-zero, the transaction being prepared is identified by this broker-generated id
* @param xid If transactionId is zero, then xid contains the Xid of the XA transaction being prepared
*
* @return The JMSServiceReply of the request to prepare a transaction
*
* @throws JMSServiceException if the Status returned for the prepareTransaction 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 prepareTransaction(long connectionId, long transactionId, Xid xid) throws JMSServiceException {
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
TransactionUID txnUID = null;
JMQXid jmqXid = null;
cxn = checkConnectionId(connectionId, "prepareTransaction");
/*
* If transactionId is 0, extract it from XID
*/
if (transactionId == 0) {
jmqXid = new JMQXid(xid);
Object[] oo = TransactionList.mapXidToTid(jmqXid, cxn);
if (oo == null) {
String errStr = "prepareTransaction(" + connectionId + "): Unknown XID " + jmqXid;
BrokerException be = new BrokerException(errStr, Status.NOT_FOUND);
props.put("JMQStatus", getErrorReplyStatus(be));
throw new JMSServiceException(errStr, be, props);
}
txnUID = (TransactionUID) oo[1];
} else {
txnUID = new TransactionUID(transactionId);
}
try {
protocol.prepareTransaction(txnUID, cxn);
} catch (BrokerException be) {
String errStr = "prepareTransaction: prepare transaction failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId + ", 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 JMSServiceImpl method rollbackTransaction.
@Override
public JMSServiceReply rollbackTransaction(long connectionId, long transactionId, Xid xid, boolean redeliver, boolean setRedelivered, int maxRollbacks, boolean dmqOnMaxRollbacks) throws JMSServiceException {
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
TransactionUID txnUID = null;
JMQXid jmqXid = null;
cxn = checkConnectionId(connectionId, "rollbackTransaction");
txnUID = new TransactionUID(transactionId);
if (xid != null) {
jmqXid = new JMQXid(xid);
}
try {
protocol.rollbackTransaction(txnUID, jmqXid, cxn, redeliver, setRedelivered, maxRollbacks, dmqOnMaxRollbacks);
} catch (BrokerException be) {
String errStr = "rollbackTransaction: rollback transaction failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId + ", 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 JMSServiceImpl method fetchMessage.
/**
* Fetch a message from 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 fetch the message
* @param timeout The maximum time to wait (in milliseconds) for a message to be available before returning.<br>
* Note that the method must return immediately if there is a message available for this consumerId at the time the call
* is made.<br>
* <UL>
* <LI>When timeout is positive, the call must wait for a maximum of the specificied number of milliseconds before
* returning. If a message is available before the timeout expires, the method returns with the message as soon as it is
* available.</LI>
* <LI>When timeout is 0, the call must block until a message is available to return or until the session is stopped.
* </LI>
* <LI>When the timeout is negative (less than 0), the call must return immediately, with a message if one is available
* or with a null, if a message is not available immediately.</LI>
* </UL>
* @param acknowledge If this is set to {@code true} then it implies that the caller is asking for the message to be
* <b>acknowledged</b> before the method returns. If this operation is part of a transaction, the {@code transactionId}
* parameter will be non-zero.
* @param transactionId If non-zero, this is the transactionId in which to acknowledge the message being returned if the
* {@code acknowledge} parameter is set to {@code true}.
*
* @return The JMSPacket which contains the message being returned.
*
* @throws JMSServiceException if broker encounters an error. {@link JMSServiceReply.Status} contains the reason for the
* error.
*/
@Override
public JMSPacket fetchMessage(long connectionId, long sessionId, long consumerId, long timeout, boolean acknowledge, long transactionId) throws JMSServiceException {
JMSPacket msg = null;
IMQConnection cxn;
Session session;
cxn = checkConnectionId(connectionId, "fetchMessage");
session = checkSessionId(sessionId, "fetchMessage");
SessionListener slistener = getListener(session.getSessionUID());
ConsumerUID conUID;
try {
conUID = new ConsumerUID(consumerId);
msg = slistener.getNextConsumerPacket(conUID, timeout);
if ((msg != null) && acknowledge) {
TransactionUID txnUID = null;
if (transactionId != 0) {
txnUID = new TransactionUID(transactionId);
}
SysMessageID[] ids = new SysMessageID[1];
ids[0] = ((Packet) msg).getSysMessageID();
ConsumerUID[] cids = new ConsumerUID[1];
cids[0] = conUID;
Globals.getProtocol().acknowledge(cxn, txnUID, false, AckHandler.ACKNOWLEDGE_REQUEST, null, null, 0, ids, cids);
}
} catch (Exception e) {
HashMap props = new HashMap();
String errStr = "fetchMessage: Fetch Message failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", consumer ID: " + consumerId;
logger.logStack(Logger.ERROR, errStr, e);
props.put("JMQStatus", JMSServiceReply.Status.ERROR);
throw new JMSServiceException(errStr, e, props);
}
return (msg);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method endTransaction.
/**
* End a transaction.
*
* @param connectionId The Id of the connection
* @param transactionId If non-zero, the transaction being ended is identified by this broker-generated id
* @param xid If transactionId is zero, then xid contains the Xid of the XA transaction being ended
* @param flags If this is an XA transaction, then flags is one of:
* <UL>
* <LI>XAResource.TMSUSPEND: If suspending a transaction</LI>
* <LI>XAResource.TMFAIL: If failing a transaction</LI>
* <LI>XAResource.TMSUCCESS: If ending a transaction</LI>
* </UL>
*
* @return The JMSServiceReply of the request to end a transaction
*
* @throws JMSServiceException if the Status returned for the endTransaction 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 endTransaction(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 = null;
cxn = checkConnectionId(connectionId, "endTransaction");
txnUID = new TransactionUID(transactionId);
if (xid != null) {
jmqXid = new JMQXid(xid);
xaFlags = Integer.valueOf(flags);
}
try {
protocol.endTransaction(txnUID, jmqXid, xaFlags, cxn);
} catch (BrokerException be) {
String errStr = "endTransaction: end transaction failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId + ", 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 SessionListener method process.
/**
* method which handles delivering messages
*/
public void process() {
if (sync) {
// there doesnt need to be an external thread
throw new RuntimeException("Cannot invoke SessionListener.process() when in synchronous receiving mode");
}
synchronized (sessionLock) {
if (destroyed) {
valid = false;
sessionLock.notifyAll();
return;
}
valid = true;
}
while (valid) {
// if we are not busy, wait for the eventListener to wake us up
while (valid && (!session.isBusy() || stopped)) {
// get the lock
synchronized (sessionLock) {
islocked = true;
sessionLock.notifyAll();
// instead check the sessionLockNotify flag
if (sessionLockNotify || !valid || stopped) {
sessionLockNotify = false;
continue;
}
try {
sessionLock.wait();
} catch (Exception ex) {
Globals.getLogger().log(Logger.DEBUGHIGH, "Exception in sessionlock wait", ex);
}
}
}
if (!valid) {
continue;
}
synchronized (sessionLock) {
// we dont care if we are about to notify
sessionLockNotify = false;
islocked = false;
}
if (session.isBusy() && !stopped && valid) {
// cool, we have something to do
Packet p = new Packet();
// retrieve the next packet and its ConsumerUID
ConsumerUID uid = session.fillNextPacket(p);
if (uid == null) {
// weird, something went wrong, try again
continue;
}
// Get the consumer object
Consumer con = (Consumer) consumers.get(uid);
try {
JMSAck ack = null;
// call the deliver method
ack = con.deliver(p);
if (ack != null) {
long transactionId = ack.getTransactionId(), consumerId = ack.getConsumerId();
SysMessageID sysMsgId = ack.getSysMessageID();
TransactionUID txnUID = null;
ConsumerUID conUID = null;
if (transactionId != 0) {
txnUID = new TransactionUID(transactionId);
}
if (consumerId != 0) {
conUID = new ConsumerUID(consumerId);
}
IMQConnection cxn = parent.checkConnectionId(ack.getConnectionId(), "Listener Thread");
SysMessageID[] ids = new SysMessageID[1];
// ids[0] = sysMsgId;
// ids[0] = ((Packet)p).getSysMessageID();
ids[0] = sysMsgId;
ConsumerUID[] cids = new ConsumerUID[1];
cids[0] = conUID;
Globals.getProtocol().acknowledge(cxn, txnUID, false, AckHandler.ACKNOWLEDGE_REQUEST, null, null, 0, ids, cids);
}
} catch (Exception ex) {
if (ex instanceof ConsumerClosedNoDeliveryException) {
if (parent.getDEBUG()) {
Globals.getLogger().logStack(Logger.INFO, "DirectConsumer " + con + " is closed, message " + p.getSysMessageID() + " can not be deliverd", ex);
}
} else {
// I have no idea what the exception might mean so just
// log it and go on
Globals.getLogger().logStack(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_CANNOT_DELIVER_MESSAGE_TO_CONSUMER, p.getSysMessageID(), uid + " DirectConsumer[" + con + "]"), ex);
}
}
}
}
}
Aggregations