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

📄 messageimpl.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * Redistribution and use of this software and associated documentation
 * ("Software"), with or without modification, are permitted provided
 * that the following conditions are met:
 *
 * 1. Redistributions of source code must retain copyright
 *    statements and notices.  Redistributions must also contain a
 *    copy of this document.
 *
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions and the
 *    following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. The name "Exolab" must not be used to endorse or promote
 *    products derived from this Software without prior written
 *    permission of Exoffice Technologies.  For written permission,
 *    please contact info@exolab.org.
 *
 * 4. Products derived from this Software may not be called "Exolab"
 *    nor may "Exolab" appear in their names without prior written
 *    permission of Exoffice Technologies. Exolab is a registered
 *    trademark of Exoffice Technologies.
 *
 * 5. Due credit should be given to the Exolab Project
 *    (http://www.exolab.org/).
 *
 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: MessageImpl.java,v 1.21 2003/11/02 11:05:55 tanderson Exp $
 *
 * Date         Author  Changes
 * 02/26/2000   jimm    Created
 */


package org.exolab.jms.message;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Enumeration;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageNotReadableException;
import javax.jms.MessageNotWriteableException;

import org.exolab.jms.Identifiable;


/**
 * This class implements the javax.jms.Message interface
 *
 * @version     $Revision: 1.21 $ $Date: 2003/11/02 11:05:55 $
 * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
 * @see         javax.jms.Message
 */
public class MessageImpl implements
    Message, Externalizable, Cloneable, Identifiable {

    /**
     * Object version no. for serialization
     */
    static final long serialVersionUID = 1;

    /**
     * This is a reference to the session that created the message. It
     * is used for acknowledgment
     */
    private MessageSessionIfc _session = null;

    /**
     * Contains the message header information as specified by the JMS
     * specifications
     */
    private MessageHeader _messageHeader = new MessageHeader();

    /**
     * Holds the properties for the message
     */
    private MessageProperties _messageProperties = new MessageProperties();

    /**
     * If true, message properties are read-only
     */
    protected boolean _propertiesReadOnly = false;

    /**
     * If true, the message body is read-only
     */
    protected boolean _bodyReadOnly = false;

    /**
     * This is the time that the message was accepted by the server
     */
    protected long _acceptedTime;

    /**
     * This is the sequence number assigned to it by the message
     * manager when the message is accepted.
     */
    protected long _sequenceNumber;

    /**
     * This message was received on this connection
     */
    protected transient int _connectionId;

    /**
     * This flag indicates that the message has been processed by the provider
     */
    protected boolean _processed = false;

    /**
     * Empty byte array for initialisation purposes
     */
    protected static final byte[] EMPTY = new byte[0];


    /**
     * Default constructor, required to support externalization
     */
    public MessageImpl() {
    }

    /**
     * Clone an instance of this object
     *
     * @return a new copy of this object
     * @throws CloneNotSupportedException if object or attributesare not
     * cloneable
     */
    public Object clone() throws CloneNotSupportedException {
        MessageImpl result = (MessageImpl) super.clone();
        result._messageHeader = (MessageHeader) _messageHeader.clone();
        result._messageProperties =
            (MessageProperties) _messageProperties.clone();
        return result;
    }

    // implementation of Externalizable.writeExternal
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeLong(serialVersionUID);
        // the individual read-only states are meaningless when streaming;
        // they only affect the client when clearProperties or clearBody is
        // is invoked
        out.writeBoolean(_propertiesReadOnly || _bodyReadOnly);
        out.writeBoolean(_processed);
        out.writeLong(_acceptedTime);
        out.writeLong(_sequenceNumber);
        out.writeObject(_messageHeader);
        out.writeObject(_messageProperties);
    }

    // implementation of Externalizable.readExternal
    public void readExternal(ObjectInput in)
        throws IOException, ClassNotFoundException {
        long version = in.readLong();
        if (version == serialVersionUID) {
            boolean readOnly = in.readBoolean();
            _propertiesReadOnly = readOnly;
            _bodyReadOnly = readOnly;
            _processed = in.readBoolean();
            _acceptedTime = in.readLong();
            _sequenceNumber = in.readLong();
            _messageHeader = (MessageHeader) in.readObject();
            _messageProperties = (MessageProperties) in.readObject();
        } else {
            throw new IOException("Incorrect version enountered: " +
                version + ". This version = " +
                serialVersionUID);
        }
    }

    public void setSession(MessageSessionIfc session) {
        _session = session;
        MessageId id = _messageHeader.getMessageId();
        if (id != null) {
            _messageHeader.setAckMessageID(id.getId());
        }
    }

    public String getJMSMessageID() throws JMSException {
        return _messageHeader.getJMSMessageID();
    }

    public void setJMSMessageID(String id) throws JMSException {
        _messageHeader.setJMSMessageID(id);
    }

    /**
     * Returns the identifier of the message for acknowledgment.
     * This will typically be the same as that returned by 
     * {@link #getJMSMessageID}, unless the message was republished after
     * its receipt. If the message is republished, this method will return
     * the original message identifier, whereas {@link #getJMSMessageID} will
     * return that of the last publication.
     *
     * @return the identifier of the message for acknowledgment
     */
    public String getAckMessageID() {
        return _messageHeader.getAckMessageID();
    }


    public long getJMSTimestamp() throws JMSException {
        return _messageHeader.getJMSTimestamp();
    }

    public void setJMSTimestamp(long timestamp) throws JMSException {
        _messageHeader.setJMSTimestamp(timestamp);
    }

    /**
     * Return the wildcard value if there is one.
     *
     * @return the wildcard string
     */
    public String getWildcard() {
        return _messageHeader.getWildcard();
    }

    /**
     * Return the message id
     *
     * @return MessageId
     */
    public MessageId getMessageId() {
        return _messageHeader.getMessageId();
    }

    /**
     * Set the wildcard string.
     *
     * @param wildcard The wildcard.
     */
    public void setWildcard(String wildcard) {
        _messageHeader.setWildcard(wildcard);
    }

    /**
     * Get the value of consumerId
     *
     * @return the consumerId
     */
    public String getConsumerId() {
        return _messageHeader.getConsumerId();
    }

    /**
     * Set the value of consumerId
     *
     * @param consumerId the consumerId
     */
    public void setConsumerId(String consumerId) {
        _messageHeader.setConsumerId(consumerId);
    }

    /**
     * Get the value of the client session consumer identifier
     *
     * @return the value of the client session consumer identifier
     */
    public long getClientId() {
        return _messageHeader.getClientId();
    }

    /**
     * Set the value of the client session consumer identifer
     *
     * @param clientId the client session consumer identifier
     */
    public void setClientId(long clientId) {
        _messageHeader.setClientId(clientId);
    }

    // Not supported
    public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
        return _messageHeader.getJMSCorrelationIDAsBytes();
    }

    // Not supported
    public void setJMSCorrelationIDAsBytes(byte[] correlationID)
        throws JMSException {
        _messageHeader.setJMSCorrelationIDAsBytes(correlationID);
    }

    public void setJMSCorrelationID(String correlationID) throws JMSException {
        _messageHeader.setJMSCorrelationID(correlationID);
    }

    public String getJMSCorrelationID() throws JMSException {
        return _messageHeader.getJMSCorrelationID();
    }

    public Destination getJMSReplyTo() throws JMSException {
        return _messageHeader.getJMSReplyTo();
    }

    public void setJMSReplyTo(Destination replyTo) throws JMSException {
        _messageHeader.setJMSReplyTo(replyTo);
    }

⌨️ 快捷键说明

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