⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2001 - 2004 ScalAgent Distributed Technologies * Copyright (C) 1996 - 2000 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): ScalAgent Distributed Technologies */package org.objectweb.joram.client.jms;import org.objectweb.joram.shared.excepts.*;import org.objectweb.joram.shared.messages.*;import java.util.*;import javax.jms.JMSException;import javax.jms.IllegalStateException;import javax.jms.MessageEOFException;import javax.jms.MessageFormatException;import javax.jms.MessageNotWriteableException;import org.objectweb.util.monolog.api.BasicLevel;/** * Implements the <code>javax.jms.Message</code> interface. * <p> * A Joram message wraps a proprietary MOM message which is actually the * effective MOM transport facility for the JMS operations. */public class Message implements javax.jms.Message {  /** The wrapped MOM message. */  protected org.objectweb.joram.shared.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 = org.objectweb.joram.shared.messages.Message.create();  }  /**   * 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, org.objectweb.joram.shared.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.getTransacted()        || sess.getAcknowledgeMode() != javax.jms.Session.CLIENT_ACKNOWLEDGE)      return;    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();  }   /**   * Resets the read-only flag, in order to allow the modification   * of message properties.   *   * @exception JMSException  Actually never thrown.   */  public void resetPropertiesRO() throws JMSException {    momMsg.resetPropertiesRO();  }   /**   * 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(javax.jms.Destination dest)     throws JMSException {    if (dest == null) {      momMsg.setDestination(null, null);    } else {      momMsg.setDestination(        ((org.objectweb.joram.client.jms.Destination) dest).getName(),         ((org.objectweb.joram.client.jms.Destination) dest).getType());    }  }  /**   * 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(javax.jms.Destination replyTo) throws JMSException  {    if (replyTo == null) {      momMsg.setDestination(null, null);    } else {      momMsg.setReplyTo(        ((org.objectweb.joram.client.jms.Destination) replyTo).getName(),         ((org.objectweb.joram.client.jms.Destination) replyTo).getType());    }  }    /**   * 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)  {    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 != javax.jms.DeliveryMode.PERSISTENT        && deliveryMode != javax.jms.DeliveryMode.NON_PERSISTENT)      throw new JMSException("Invalid delivery mode.");    momMsg.setPersistent(deliveryMode == javax.jms.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 javax.jms.DeliveryMode.PERSISTENT;    else      return javax.jms.DeliveryMode.NON_PERSISTENT;  }  /**   * API method.   *   * @exception JMSException  Actually never thrown.   */  public javax.jms.Destination getJMSDestination()     throws JMSException {    String id = momMsg.getDestinationId();    String type = momMsg.toType();    if (id != null) {      // The destination name is unknown      try {        return Destination.newInstance(id, null, type);      } catch (Exception exc) {        throw new JMSException(exc.getMessage());      }    } else return null;  }  /**   * 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 javax.jms.Destination getJMSReplyTo()     throws JMSException {    String id = momMsg.getReplyToId();    String type = momMsg.replyToType();    if (id != null) {      // The destination name is unknown      try {        return Destination.newInstance(id, null, type);      } catch (Exception exc) {        throw new JMSException(exc.getMessage());      }    } else return null;  }  /**   * 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 {      return ConversionHelper.toBytes(momMsg.getCorrelationId());    }    catch (MessageValueException mE) {      throw new MessageFormatException(mE.getMessage());    }  }  /**   * API method.   *   * @exception MessageNotWriteableException  If the message is read-only.   * @exception JMSException  If the property name is invalid.   */  public void setBooleanProperty(String name, boolean value)            throws JMSException  {    doSetProperty(name, new Boolean(value));  }  /**   * API method.   *   * @exception MessageNotWriteableException  If the message is read-only.   * @exception JMSException  If the property name is invalid.   */  public void setByteProperty(String name, byte value) throws JMSException  {    doSetProperty(name, new Byte(value));  }  /**   * API method.   *   * @exception MessageNotWriteableException  If the message is read-only.   * @exception JMSException  If the property name is invalid.   */  public void setDoubleProperty(String name, double value) throws JMSException  {    doSetProperty(name, new Double(value));  }  /**   * API method.   *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -