📄 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.messages;import com.scalagent.kjoram.excepts.*;import java.io.*;import java.util.*;/** * The <code>Message</code> class actually provides the transport facility * for the data exchanged during MOM operations. * <p> * A message may either carry a String, or a serializable object, or an * hashtable, or bytes, even nothing. It is charaterized by properties and * "header" fields. */public class Message { /** The message type (SIMPLE, TEXT, MAP, BYTES). */ int type; /** <code>true</code> if the message must be persisted. **/ boolean persistent = true; /** The message identifier. */ String id = null; /** The message priority (from 0 to 9, 9 being the highest). */ int priority = 4; /** The message expiration time (0 for infinite time-to-live). */ long expiration = 0; /** The message time stamp. */ long timestamp; /** The message destination identifier. */ String toId = null; /** <code>true</code> if the message destination is a queue. */ boolean toQueue; /** The correlation identifier field. */ String correlationId = null; /** The reply to destination identifier. */ String replyToId = null; /** <code>true</code> if the "reply to" destination is a queue. */ boolean replyToQueue; /** * Table holding header fields that may be required by particular * clients (such as JMS clients). */ Hashtable optionalHeader = null; /** The bytes body. */ byte[] body_bytes = null; /** The map body. */ Hashtable body_map = null; /** The text body. */ String body_text = null; /** <code>true</code> if the body is read-only. */ boolean bodyRO = false; /** The message properties table. */ Hashtable properties = null; /** <code>true</code> if the properties are read-only. */ boolean propertiesRO = false; /** The number of delivery attempts for this message. */ public int deliveryCount = 0; /** * <code>true</code> if the message has been denied at least once by a * consumer. */ public boolean denied = false; /** <code>true</code> if the message target destination is deleted. */ public boolean deletedDest = false; /** <code>true</code> if the message expired. */ public boolean expired = false; /** <code>true</code> if the message could not be written on the dest. */ public boolean notWriteable = false; /** <code>true</code> if the message is considered as undeliverable. */ public boolean undeliverable = false; /** * The number of acknowledgements a message still expects from its * subscribers before having been fully consumed by them (field used * by JMS proxies). */ public transient int acksCounter; /** * The number of acknowledgements a message still expects from its * durable subscribers before having been fully consumed by them (field used * by JMS proxies). */ public transient int durableAcksCounter; /** * Constructs a <code>Message</code> instance. */ public Message() { this.type = MessageType.SIMPLE; } /** Sets the message identifier. */ public void setIdentifier(String id) { this.id = id; } /** Sets the message persistence mode. */ public void setPersistent(boolean persistent) { this.persistent = persistent; } /** * Sets the message priority. * * @param priority Priority value: 0 the lowest, 9 the highest, 4 normal. */ public void setPriority(int priority) { if (priority >= 0 && priority <= 9) this.priority = priority; } /** Sets the message expiration. */ public void setExpiration(long expiration) { if (expiration >= 0) this.expiration = expiration; } /** Sets the message time stamp. */ public void setTimestamp(long timestamp) { this.timestamp = timestamp; } /** * Sets the message destination. * * @param id The destination identifier. * @param queue <code>true</code> if the destination is a queue. */ public void setDestination(String id, boolean queue) { this.toId = id; this.toQueue = queue; } /** Sets the message correlation identifier. */ public void setCorrelationId(String correlationId) { this.correlationId = correlationId; } /** * Sets the destination to which a reply should be sent. * * @param id The destination identifier. * @param queue <code>true</code> if the destination is a queue. */ public void setReplyTo(String id, boolean queue) { this.replyToId = id; this.replyToQueue = queue; } /** * Sets an optional header field value. * * @param name The header field name. * @param value The corresponding value. */ public void setOptionalHeader(String name, Object value) { if (name == null || name.equals("")) throw new IllegalArgumentException("Invalid header name: " + name); if (value == null) return; if (optionalHeader == null) optionalHeader = new Hashtable(); optionalHeader.put(name, value); } /** Returns the message type. */ public int getType() { return type; } /** Returns the message identifier. */ public String getIdentifier() { return id; } /** Returns <code>true</code> if the message is persistent. */ public boolean getPersistent() { return persistent; } /** Returns the message priority. */ public int getPriority() { return priority; } /** Returns the message expiration time. */ public long getExpiration() { return expiration; } /** Returns the message time stamp. */ public long getTimestamp() { return timestamp; } /** Returns the message destination identifier. */ public String getDestinationId() { return toId; } /** Returns <code>true</code> if the destination is a queue. */ public boolean toQueue() { return toQueue; } /** Returns the message correlation identifier. */ public String getCorrelationId() { return correlationId; } /** Returns the destination id the reply should be sent to. */ public String getReplyToId() { return replyToId; } /** Returns <code>true</code> if the reply to destination is a queue. */ public boolean replyToQueue() { return replyToQueue; } /** * Returns an optional header field value. * * @param name The header field name. */ public Object getOptionalHeader(String name) { if (optionalHeader == null) return null; return optionalHeader.get(name); } /** * Sets a property as a boolean value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */ public void setBooleanProperty(String name, boolean value) throws MessageROException { preparePropSetting(name); properties.put(name, new Boolean(value)); } /** * Sets a property as a byte value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */ public void setByteProperty(String name, byte value) throws MessageROException { preparePropSetting(name); properties.put(name, new Byte(value)); } /** * Sets a property as a double value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */// public void setDoubleProperty(String name, double value)// throws MessageROException// {// preparePropSetting(name);// properties.put(name, new Double(value));// } /** * Sets a property as a float value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */// public void setFloatProperty(String name, float value)// throws MessageROException// {// preparePropSetting(name);// properties.put(name, new Float(value));// } /** * Sets a property as an int value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */ public void setIntProperty(String name, int value) throws MessageROException { preparePropSetting(name); properties.put(name, new Integer(value)); } /** * Sets a property as a long value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */ public void setLongProperty(String name, long value) throws MessageROException { preparePropSetting(name); properties.put(name, new Long(value)); } /** * Sets a property value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. * @exception MessageValueException If the value is not a Java primitive * object. */ public void setObjectProperty(String name, Object value) throws MessageException { preparePropSetting(name); if (value instanceof Boolean || value instanceof String || value instanceof Integer || value instanceof Long || value instanceof Short || value instanceof Byte) properties.put(name, value); else throw new MessageValueException("Can't set non primitive Java object" + " as a property value."); } /** * Sets a property as a short value. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */ public void setShortProperty(String name, short value) throws MessageROException { preparePropSetting(name); properties.put(name, new Short(value)); } /** * Sets a property as a String. * * @param name The property name. * @param value The property value. * * @exception MessageROException If the message properties are read-only. */ public void setStringProperty(String name, String value) throws MessageROException { preparePropSetting(name); properties.put(name, new String(value)); } /** * Returns a property as a boolean value. * * @exception MessageValueException If the property type is invalid. */ public boolean getBooleanProperty(String name) throws MessageValueException { if (properties == null) throw new RuntimeException("getBooleanProperty properties = null"); return ConversionHelper.toBoolean(properties.get(name)); } /** * * @exception MessageValueException If the property type is invalid. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -