messageimpl.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 893 行 · 第 1/2 页
JAVA
893 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source 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, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.jms.message;import com.caucho.jms.connection.JmsSession;import com.caucho.hessian.io.*;import com.caucho.vfs.*;import com.caucho.util.*;import javax.jms.*;import java.lang.ref.WeakReference;import java.io.*;import java.util.*;import java.util.logging.Level;import java.util.logging.Logger;/** * A basic message. */public class MessageImpl implements Message, java.io.Serializable{ protected static final Logger log = Logger.getLogger(MessageImpl.class.getName()); protected static final L10N L = new L10N(MessageImpl.class); private static final HashSet<String> _reserved; private volatile WeakReference<JmsSession> _sessionRef; private String _messageId; private String _correlationId; private long _timestamp; private long _expiration; private Destination _destination; private Destination _replyTo; private int _deliveryMode = DeliveryMode.PERSISTENT; private boolean _isRedelivered; private String _messageType; private int _priority = 4; private long _sequence; private HashMap<String,Object> _properties; private transient boolean _isHeaderWriteable = true; private transient boolean _isBodyWriteable = true; public MessageImpl() { } /** * Create a message, copying the properties */ public MessageImpl(Message msg) throws JMSException { _messageId = msg.getJMSMessageID(); _correlationId = msg.getJMSCorrelationID(); _timestamp = msg.getJMSTimestamp(); _expiration = msg.getJMSExpiration(); _destination = msg.getJMSDestination(); _replyTo = msg.getJMSReplyTo(); _deliveryMode = msg.getJMSDeliveryMode(); _isRedelivered = msg.getJMSRedelivered(); _messageType = msg.getJMSType(); _priority = msg.getJMSPriority(); Enumeration e = msg.getPropertyNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); setObjectProperty(name, msg.getObjectProperty(name)); } _isHeaderWriteable = false; _isBodyWriteable = false; } public MessageImpl(MessageImpl msg) { if (msg._properties != null) { _properties = new HashMap<String,Object>(msg._properties); } _messageId = msg._messageId; _correlationId = msg._correlationId; _timestamp = msg._timestamp; _expiration = msg._expiration; _destination = msg._destination; _replyTo = msg._replyTo; _deliveryMode = msg._deliveryMode; _isRedelivered = msg._isRedelivered; _messageType = msg._messageType; _priority = msg._priority; _isHeaderWriteable = false; _isBodyWriteable = false; } /** * Sets the session. */ public void setSession(JmsSession session) { _sessionRef = new WeakReference<JmsSession>(session); } /** * Returns the type enumeration. */ public MessageType getType() { return MessageType.NULL; } /** * Returns the message id. */ public String getJMSMessageID() { return _messageId; } /** * Sets the message id. * * @param id the new message id */ public void setJMSMessageID(String id) { _messageId = id; } /** * Returns the time the message was sent. */ public long getJMSTimestamp() throws JMSException { return _timestamp; } /** * Sets the time the message was sent. * * @param time the message timestamp */ public void setJMSTimestamp(long time) throws JMSException { _timestamp = time; } /** * Returns the correlation id. */ public byte []getJMSCorrelationIDAsBytes() throws JMSException { try { if (_correlationId == null) return null; else return _correlationId.getBytes("UTF8"); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); return null; } } /** * Sets the correlation id. * * @param id the correlation id */ public void setJMSCorrelationIDAsBytes(byte []id) throws JMSException { try { _correlationId = new String(id, 0, id.length, "UTF8"); } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } } /** * Returns the correlation id. */ public String getJMSCorrelationID() throws JMSException { return _correlationId; } /** * Sets the correlation id. * * @param id the correlation id */ public void setJMSCorrelationID(String id) throws JMSException { _correlationId = id; } /** * Gets the reply-to destination */ public Destination getJMSReplyTo() throws JMSException { return _replyTo; } /** * Sets the reply-to destination * * @param replyTo the destination */ public void setJMSReplyTo(Destination replyTo) throws JMSException { _replyTo = replyTo; } /** * Gets the destination */ public Destination getJMSDestination() throws JMSException { return _destination; } /** * Sets the reply-to destination * * @param destination the destination */ public void setJMSDestination(Destination destination) throws JMSException { _destination = destination; } /** * Gets the delivery model */ public int getJMSDeliveryMode() throws JMSException { return _deliveryMode; } /** * Sets the delivery mode * * @param deliveryMode the delivery mode */ public void setJMSDeliveryMode(int deliveryMode) throws JMSException { _deliveryMode = deliveryMode; } /** * Returns if the message is being redelivered. */ public boolean getJMSRedelivered() { return _isRedelivered; } /** * Sets if the message is being redelivered. * * @param deliveryMode the delivery mode */ public void setJMSRedelivered(boolean isRedelivered) { _isRedelivered = isRedelivered; } /** * Returns the message type */ public String getJMSType() throws JMSException { return _messageType; } /** * Sets the message type. * * @param type the delivery mode */ public void setJMSType(String type) throws JMSException { _messageType = type; } /** * Returns the message expiration time. */ public long getJMSExpiration() throws JMSException { return _expiration; } /** * Sets the message expiration type. * * @param time the expiration time */ public void setJMSExpiration(long time) throws JMSException { _expiration = time; } /** * Returns the message priority. */ public int getJMSPriority() { return _priority; } /** * Sets the message priority. * * @param priority the priority */ public void setJMSPriority(int priority) { _priority = priority; } /** * Clears the message properties, making them writeable. */ public void clearProperties() throws JMSException { if (_properties != null) _properties.clear(); _isHeaderWriteable = true; } /** * Returns true if the property exists. */ public boolean propertyExists(String name) throws JMSException { if (_properties == null) return false; return _properties.keySet().contains(name); } /** * Returns a boolean property with the given name. */ public boolean getBooleanProperty(String name) throws JMSException { return ObjectConverter.toBoolean(getObjectProperty(name)); } /** * Returns a property as a byte */ public byte getByteProperty(String name) throws JMSException { return ObjectConverter.toByte(getObjectProperty(name)); } /** * Returns a property as a short */ public short getShortProperty(String name) throws JMSException { return ObjectConverter.toShort(getObjectProperty(name)); } /** * Returns a property as an integer */ public int getIntProperty(String name) throws JMSException { return ObjectConverter.toInt(getObjectProperty(name)); } /** * Returns a property as a long */ public long getLongProperty(String name) throws JMSException
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?