📄 message.java
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2001 - ScalAgent Distributed Technologies * Copyright (C) 1996 - Dyade * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Initial developer(s): Frederic Maistre (INRIA) * Contributor(s): Nicolas Tachker (ScalAgent) */package com.scalagent.kjoram;import com.scalagent.kjoram.excepts.IllegalStateException;import com.scalagent.kjoram.excepts.*;import com.scalagent.kjoram.messages.*;import java.util.*;/** * A Joram message wraps a proprietary MOM message which is actually the * effective MOM transport facility for the JMS operations. */public class Message{ /** The wrapped MOM message. */ protected com.scalagent.kjoram.messages.Message momMsg; /** * If the message is actually consumed, the session that consumes it, * <code>null</code> otherwise. */ protected Session sess = null; /** * Constructs a bright new <code>Message</code>. */ Message() { momMsg = new com.scalagent.kjoram.messages.Message(); } /** * Constructs a <code>Message</code> wrapping a MOM message consumed by a * session. * * @param sess The consuming session. * @param momMsg The MOM message to wrap. */ Message(Session sess, com.scalagent.kjoram.messages.Message momMsg) { this.sess = sess; this.momMsg = momMsg; } /** * API method. * * @exception IllegalStateException If the session is closed. * @exception JMSException If the acknowledgement fails for any other * reason. */ public void acknowledge() throws JMSException { if (sess == null || sess.transacted || sess.acknowledgeMode != Session.CLIENT_ACKNOWLEDGE) return; if (sess.closed) throw new IllegalStateException("Forbidden call on a closed session."); sess.acknowledge(); } /** * API method. * * @exception JMSException Actually never thrown. */ public void clearBody() throws JMSException { momMsg.clearBody(); } /** * API method. * * @exception JMSException Actually never thrown. */ public void clearProperties() throws JMSException { momMsg.clearProperties(); } /** * API method. * * @exception JMSException Actually never thrown. */ public boolean propertyExists(String name) throws JMSException { return momMsg.propertyExists(name); } /** * API method. * * @exception JMSException Actually never thrown. */ public Enumeration getPropertyNames() throws JMSException { return momMsg.getPropertyNames(); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSMessageID(String id) throws JMSException { momMsg.setIdentifier(id); } /** * API method. * * @exception JMSException If the priority value is incorrect. */ public void setJMSPriority(int priority) throws JMSException { if (0 <= priority && priority <= 9) momMsg.setPriority(priority); else throw new JMSException("Priority of "+ priority +" is not valid" + " (should be an integer between 0 and 9)."); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSDestination(Destination dest) throws JMSException { if (dest == null) momMsg.setDestination(null, true); if (dest instanceof Queue) momMsg.setDestination(((Queue) dest).getQueueName(), true); else momMsg.setDestination(((Topic) dest).getTopicName(), false); if (dest instanceof TemporaryQueue || dest instanceof TemporaryTopic) momMsg.setOptionalHeader("JMSTempDestination", new Boolean(true)); else momMsg.setOptionalHeader("JMSTempDestination", new Boolean(false)); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSExpiration(long expiration) throws JMSException { momMsg.setExpiration(expiration); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSRedelivered(boolean redelivered) throws JMSException { momMsg.denied = redelivered; } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSReplyTo(Destination replyTo) throws JMSException { if (replyTo == null) momMsg.setReplyTo(null, true); if (replyTo instanceof Queue) momMsg.setReplyTo(((Queue) replyTo).getQueueName(), true); else momMsg.setReplyTo(((Topic) replyTo).getTopicName(), false); if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic) momMsg.setOptionalHeader("JMSTempReplyTo", new Boolean(true)); else momMsg.setOptionalHeader("JMSTempReplyTo", new Boolean(false)); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSTimestamp(long timestamp) throws JMSException { momMsg.setTimestamp(timestamp); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSCorrelationID(String correlationID) throws JMSException { momMsg.setCorrelationId(correlationID); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException { momMsg.setCorrelationId(ConversionHelper.toString(correlationID)); } /** * API method. * * @exception JMSException Actually never thrown. */ public void setJMSType(String type) throws JMSException { momMsg.setOptionalHeader("JMSType", type); } /** * API method. * * @exception JMSException If the delivery mode is incorrect. */ public void setJMSDeliveryMode(int deliveryMode) throws JMSException { if (deliveryMode != DeliveryMode.PERSISTENT && deliveryMode != DeliveryMode.NON_PERSISTENT) throw new JMSException("Invalid delivery mode."); momMsg.setPersistent(deliveryMode == DeliveryMode.PERSISTENT); } /** * API method. * * @exception JMSException Actually never thrown. */ public String getJMSMessageID() throws JMSException { return momMsg.getIdentifier(); } /** * API method. * * @exception JMSException Actually never thrown. */ public int getJMSPriority() throws JMSException { return momMsg.getPriority(); } /** * API method. * * @exception JMSException Actually never thrown. */ public int getJMSDeliveryMode() throws JMSException { if (momMsg.getPersistent()) return DeliveryMode.PERSISTENT; else return DeliveryMode.NON_PERSISTENT; } /** * API method. * * @exception JMSException Actually never thrown. */ public Destination getJMSDestination() throws JMSException { String id = momMsg.getDestinationId(); boolean queue = momMsg.toQueue(); Object temporaryValue = null; boolean temporary = false; try { temporaryValue = momMsg.getOptionalHeader("JMSTempDestination"); temporary = ConversionHelper.toBoolean(temporaryValue); } // If the value can't be retrieved, it might be because the sender is // not a JMS client and did not know about temporary destinations... catch (Exception exc) {} if (queue) { if (temporary) return new TemporaryQueue(id, null); else return new Queue(id); } else { if (temporary) return new TemporaryTopic(id, null); else return new Topic(id); } } /** * API method. * * @exception JMSException Actually never thrown. */ public long getJMSExpiration() throws JMSException { return momMsg.getExpiration(); } /** * API method. * * @exception JMSException Actually never thrown. */ public boolean getJMSRedelivered() throws JMSException { return momMsg.denied; } /** * API method. * * @exception JMSException Actually never thrown. */ public Destination getJMSReplyTo() throws JMSException { String id = momMsg.getReplyToId(); boolean queue = momMsg.replyToQueue(); Object temporaryValue = null; boolean temporary = false; if (id == null) return null; try { temporaryValue = momMsg.getOptionalHeader("JMSTempReplyTo"); temporary = ConversionHelper.toBoolean(temporaryValue); } // If the value can't be retrieved, it might be because the sender is not // a JMS client... catch (Exception exc) {} if (queue) { if (temporary) return new TemporaryQueue(id, null); else return new Queue(id); } else { if (temporary) return new TemporaryTopic(id, null); else return new Topic(id); } } /** * API method. * * @exception JMSException Actually never thrown. */ public long getJMSTimestamp() throws JMSException { return momMsg.getTimestamp(); } /** * API method. * * @exception JMSException Actually never thrown. */ public String getJMSType() throws JMSException { Object value = momMsg.getOptionalHeader("JMSType"); return ConversionHelper.toString(value); } /** * API method. * * @exception JMSException Actually never thrown. */ public String getJMSCorrelationID() throws JMSException { return momMsg.getCorrelationId(); } /** * API method. * * @exception MessageFormatException In case of a problem while retrieving * the field. */ public byte[] getJMSCorrelationIDAsBytes() throws JMSException { try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -