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

📄 persistentmessagehandle.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 2001-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: PersistentMessageHandle.java,v 1.17 2003/08/07 13:33:04 tanderson Exp $
 *
 * Date         Author  Changes
 * 3/1/2001     jima    Created
 */
package org.exolab.jms.messagemgr;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.sql.Connection;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.transaction.TransactionManager;

import org.exolab.core.foundation.PersistentObject;
import org.exolab.jms.client.JmsDestination;
import org.exolab.jms.client.JmsQueue;
import org.exolab.jms.client.JmsTopic;
import org.exolab.jms.message.MessageHandle;
import org.exolab.jms.message.MessageId;
import org.exolab.jms.message.MessageImpl;
import org.exolab.jms.persistence.DatabaseService;
import org.exolab.jms.persistence.PersistenceException;


/**
 * A persistent message handle extends {@link MessageHandle} and references a
 * persistent message. These messages can be discarded from the cache and later
 * faulted in through the 'resolve' method.
 *
 * @version     $Revision: 1.17 $ $Date: 2003/08/07 13:33:04 $
 * @author      <a href="mailto:jima@exoffice.com">Jim Alateras</a>
 **/
public class PersistentMessageHandle
    extends PersistentObject
    implements MessageHandle, Cloneable {

    /**
     * Used for serialization
     */
    static final long serialVersionUID = 1;

    /**
     * This is the message id of the underlying message
     */
    private MessageId _id = null;

    /**
     * This is the priority of the inderlying message
     */
    private int _priority;

    /**
     * A flag indicating whether an attempt was made to deliver the message
     */
    private boolean _delivered;

    /**
     * a transient attribute, to associate this handle with an endpoint
     */
    private transient long _clientId = -1;

    /*
     * The time that the underlying message was accepted by the server
     */
    private long _acceptedTime;

    /**
     * This is the sequence number assigned to it by the message manager
     * that created this handle
     */
    private long _sequenceNumber;

    /**
     * The expiry time of this message. 0 if it doesn't expire
     */
    private long _expiryTime;

    /**
     * The name of the durable consumer that this handle belongs too
     */
    private String _consumerName;

    /**
     * The destination that this handle belongs too
     */
    private JmsDestination _destination;


    /**
     * Cache the hashcode for this object
     */
    private transient int _hashCode = -1;


    /**
     * Default constructor
     */
    public PersistentMessageHandle() {
        super();
    }

    /**
     * Create a persistent handle from a message
     *
     * @param message - persistent message
     * @exception JMSException - if the object cannot be constructed
     */
    public PersistentMessageHandle(MessageImpl message)
        throws JMSException {
        super();

        if ((message != null) &&
            (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT)) {
            _id = message.getMessageId();
            _priority = message.getJMSPriority();
            _delivered = message.getJMSRedelivered();
            _destination = (JmsDestination) message.getJMSDestination();
            _acceptedTime = message.getAcceptedTime();
            _expiryTime = message.getJMSExpiration();
            _sequenceNumber = message.getSequenceNumber();
            _clientId = message.getClientId();
        } else {
            throw new JMSException(
                "Cannot create persistent handle from non-persistent message");
        }
    }

    /**
     * Set the identity of the underlying message
     *
     * @param id - the message id
     */
    public void setMessageId(MessageId id) {
        _id = id;
    }

    /**
     * Return the identity of the underlying message
     *
     * @return MessageId
     */
    public MessageId getMessageId() {
        return _id;
    }

    /**
     * Return the associated message or null if it is invalid
     *
     * @return  MessageImpl
     */
    public MessageImpl getMessage() {
        return (MessageImpl) MessageMgr.instance().getMessage(this);
    }

    /**
     * Set the messagee priority
     *
     * @param id the persistent id
     */
    public void setPriority(int priority) {
        _priority = priority;
    }

    /**
     * Return the priority of the corresponding message
     *
     * @return int
     */
    public int getPriority() {
        return _priority;
    }

    /**
     * Set the delivered flag for the underlying message. True if an attempt
     * has been made to deliver the message
     *
     * @param value - true if delivered
     */
    public void setDelivered(boolean value) {
        _delivered = value;
    }

    /**
     * Return the delivered state of the message
     *
     * @return long
     */
    public boolean getDelivered() {
        return _delivered;
    }

    /**
     * Set the time that the message was accepted by the server
     *
     * @param long - time since epoch
     */
    public void setAcceptedTime(long time) {
        _acceptedTime = time;
    }

    /**
     * Return the time that the message was accepted by the server
     *
     * @return long - time in ms since epoch
     */
    public long getAcceptedTime() {
        return _acceptedTime;
    }

    /**
     * Set the message's sequence number
     *
     * @param seq - sequence time
     */
    public void setSequenceNumber(long seq) {
        _sequenceNumber = seq;
    }

    /**
     * Return message's sequence number
     *
     * @return long - the sequence number
     */
    public long getSequenceNumber() {
        return _sequenceNumber;
    }

    /**

⌨️ 快捷键说明

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