use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.
the class DirectProducer method _send.
/**
* Send a Message
*/
private void _send(Destination destination, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException {
JMSPacket msgPkt = null;
DirectPacket dPkt = null;
boolean foreignMessageConverted = false;
// System.out.println("_send:Message is instanceof-"+msg.getClass().getName());
if (msg instanceof DirectPacket) {
dPkt = (DirectPacket) msg;
} else {
dPkt = DirectPacket.constructFromForeignMessage(this.jmsservice, this.ds, msg);
foreignMessageConverted = true;
}
assert dPkt != null;
dPkt.setJMSDestination(destination);
dPkt.setJMSDeliveryMode(deliveryMode);
dPkt.setJMSPriority((priority));
dPkt.setJMSExpiration(timeToLive);
dPkt.setJMSDeliveryTime(jmsDeliveryDelay);
dPkt.preparePacketForSend();
msgPkt = dPkt;
this.ds._sendMessage(msgPkt);
if (foreignMessageConverted) {
DirectPacket.updateForeignMessageAfterSend(dPkt, msg);
}
}
use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.
the class DirectSession method _fetchMessage.
/**
* Fetch a message for a consumer performing a sync receive.
* <p>
* Only one thread in a session can do this at a time.
*/
protected synchronized jakarta.jms.Message _fetchMessage(DirectConsumer consumer, long consumerId, long timeout, String methodName) throws JMSException {
JMSPacket jmsPacket = null;
jakarta.jms.Message jmsMsg = null;
SysMessageID messageID = null;
long xaTxnId = 0L;
if (this.dc.isManaged() && this.dc.isEnlisted()) {
xaTxnId = this.dc._getXAResource()._getTransactionId();
} else {
xaTxnId = this._getTransactionId();
}
try {
jmsPacket = this.jmsservice.fetchMessage(this.connectionId, this.sessionId, consumerId, timeout, this.ackOnFetch, xaTxnId);
} catch (JMSServiceException jmsse) {
}
if (jmsPacket == null) {
return null;
} else {
try {
jmsMsg = DirectPacket.constructMessage(jmsPacket, consumerId, this, this.jmsservice, false);
consumer.setLastMessageSeen(((DirectPacket) jmsMsg).getReceivedSysMessageID());
if (this.ackMode == SessionAckMode.CLIENT_ACKNOWLEDGE) {
messageID = ((DirectPacket) jmsMsg).getReceivedSysMessageID();
// Insert the message's ReceivedSysMessageID + consumerId
// for recover
unackedMessageIDs.add(messageID);
unackedConsumerIDs.add(consumerId);
}
return jmsMsg;
} catch (Exception e) {
String exerrmsg = _lgrMID_EXC + "receive:Exception constructing message:" + e.getMessage();
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(e);
_loggerJS.warning(exerrmsg);
throw jmse;
}
}
}
use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.
the class DirectSession method _fetchMessageBody.
/**
* Fetch the body of a message for a consumer performing a sync receive.
* <p>
* Only one thread in a session can do this at a time.
*/
protected synchronized <T> T _fetchMessageBody(DirectConsumer consumer, long consumerId, long timeout, Class<T> c, String methodName) throws JMSException {
T body = null;
MessageFormatException savedMFE = null;
JMSPacket jmsPacket = null;
jakarta.jms.Message jmsMsg = null;
SysMessageID messageID = null;
long xaTxnId = 0L;
if (this.dc.isManaged() && this.dc.isEnlisted()) {
xaTxnId = this.dc._getXAResource()._getTransactionId();
} else {
xaTxnId = this._getTransactionId();
}
try {
// get the next message but don't auto-acknowledge it
boolean autoAcknowledge = false;
jmsPacket = this.jmsservice.fetchMessage(this.connectionId, this.sessionId, consumerId, timeout, autoAcknowledge, xaTxnId);
} catch (JMSServiceException jmsse) {
throw new com.sun.messaging.jms.JMSException(jmsse.getMessage(), null, jmsse);
}
if (jmsPacket != null) {
try {
jmsMsg = DirectPacket.constructMessage(jmsPacket, consumerId, this, this.jmsservice, false);
if (this.ackMode == SessionAckMode.CLIENT_ACKNOWLEDGE) {
messageID = ((DirectPacket) jmsMsg).getReceivedSysMessageID();
// Insert the message's ReceivedSysMessageID + consumerId
// for recover
unackedMessageIDs.add(messageID);
unackedConsumerIDs.add(consumerId);
}
} catch (Exception e) {
String exerrmsg = _lgrMID_EXC + "receive:Exception constructing message:" + e.getMessage();
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(e);
_loggerJS.warning(exerrmsg);
throw jmse;
}
try {
body = returnPayload(jmsMsg, c);
consumer.setLastMessageSeen(((DirectPacket) jmsMsg).getReceivedSysMessageID());
} catch (MessageFormatException mfe) {
// message could not be converted
if (xaTxnId == 0L && (getAcknowledgeMode() == Session.AUTO_ACKNOWLEDGE || getAcknowledgeMode() == Session.DUPS_OK_ACKNOWLEDGE)) {
// note that we don't call setLastMessageSeen in this case
try {
SysMessageID[] messageIDs = new SysMessageID[1];
messageIDs[0] = jmsPacket.getPacket().getSysMessageID();
Long[] consumerIDs = new Long[1];
consumerIDs[0] = consumerId;
boolean setRedelivered = false;
jmsservice.redeliverMessages(this.connectionId, this.sessionId, messageIDs, consumerIDs, xaTxnId, setRedelivered);
} catch (JMSServiceException jmsse) {
throw new com.sun.messaging.jms.JMSException(jmsse.getMessage(), null, jmsse);
}
// throw now before we acknowledge it
throw mfe;
} else {
consumer.setLastMessageSeen(((DirectPacket) jmsMsg).getReceivedSysMessageID());
// throw at end of method
savedMFE = mfe;
}
}
if (this.ackOnFetch) {
try {
// ??
SysMessageID sysMessageID = jmsPacket.getPacket().getSysMessageID();
jmsservice.acknowledgeMessage(connectionId, sessionId, consumerId, sysMessageID, xaTxnId, MessageAckType.ACKNOWLEDGE);
} catch (JMSServiceException e) {
}
}
}
if (savedMFE != null)
throw savedMFE;
return body;
}
use of com.sun.messaging.jmq.io.JMSPacket 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.io.JMSPacket in project openmq by eclipse-ee4j.
the class JMSServiceImpl method browseMessages.
@Override
public JMSPacket[] browseMessages(long connectionId, long sessionId, long consumerId) throws JMSServiceException {
IMQConnection cxn;
HashMap props = new HashMap();
ConsumerUID uid;
// Session session;
JMSPacket[] msgs = null;
cxn = checkConnectionId(connectionId, "browseMessages");
// session = checkSessionId(sessionId, "browseMessages");
checkSessionId(sessionId, "browseMessages");
uid = new ConsumerUID(consumerId);
if (queueBrowseList.containsKey(uid)) {
QueueBrowserInfo qbi = (QueueBrowserInfo) queueBrowseList.get(uid);
try {
Destination dest = qbi.dest;
String selector = qbi.selector;
com.sun.messaging.jmq.jmsserver.core.Destination[] ds = null;
com.sun.messaging.jmq.jmsserver.core.Destination d = null;
ds = Globals.getDestinationList().getDestination(cxn.getPartitionedStore(), dest.getName(), (dest.getType() == Destination.Type.QUEUE));
d = ds[0];
if (d == null) {
String errStr = "browseMessages: destination not found. Connection ID:" + connectionId + ", Session ID: " + sessionId + ", Consumer ID: " + consumerId + "destination: " + dest.toString();
logger.log(Logger.ERROR, errStr);
props.put("JMQStatus", JMSServiceReply.Status.NOT_FOUND);
throw new JMSServiceException(errStr, props);
}
ArrayList msgIds = protocol.browseQueue(d, selector, cxn, cxn.getAccessController().isAccessControlEnabled());
if (msgIds != null) {
int numMsgs = msgIds.size();
if (numMsgs == 0) {
return (null);
}
msgs = new JMSPacket[numMsgs];
for (int i = 0; i < numMsgs; ++i) {
PacketReference pr = DestinationList.get(null, (SysMessageID) msgIds.get(i));
msgs[i] = pr.getPacket();
}
}
} catch (Exception e) {
String errStr = "browseMessages: Browse queue failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", consumer ID: " + consumerId;
logger.logStack(Logger.ERROR, errStr, e);
if (e instanceof SelectorFormatException) {
props.put("JMQStatus", JMSServiceReply.Status.BAD_REQUEST);
} else {
props.put("JMQStatus", getErrorReplyStatus(e));
}
if (e instanceof BrokerException) {
String ecode = ((BrokerException) e).getErrorCode();
if (ecode != null) {
props.put(JMSPacketProperties.JMQErrorCode, ecode);
}
}
throw new JMSServiceException(errStr, e, props);
}
} else {
String errStr = "browseMessages: consumer ID not found. Connection ID:" + connectionId + ", Session ID: " + sessionId + ", Consumer ID: " + consumerId;
logger.log(Logger.ERROR, errStr);
props.put("JMQStatus", JMSServiceReply.Status.NOT_FOUND);
throw new JMSServiceException(errStr, props);
}
return (msgs);
}
Aggregations