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

📄 abstractconsumermessagehandle.java

📁 一个java方面的消息订阅发送的源码
💻 JAVA
字号:
/**
 * 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 2005 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: AbstractConsumerMessageHandle.java,v 1.1 2005/03/18 03:58:38 tanderson Exp $
 */

package org.exolab.jms.messagemgr;

import java.sql.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;

import org.exolab.jms.client.JmsDestination;
import org.exolab.jms.message.MessageImpl;
import org.exolab.jms.persistence.DatabaseService;
import org.exolab.jms.persistence.PersistenceException;


/**
 * A {@link MessageHandle} for a consumer.
 *
 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
 * @version $Revision: 1.1 $ $Date: 2005/03/18 03:58:38 $
 */
abstract class AbstractConsumerMessageHandle implements MessageHandle {

    /**
     * The underlying handle.
     */
    private final MessageHandle _handle;

    /**
     * The consumer's identity.
     */
    private long _consumerId;

    /**
     * The consumer's persistent identity.
     */
    private final String _persistentId;

    /**
     * Detetmines if this handle is persistent.
     */
    private boolean _persistent;


    /**
     * Construct a new <code>AbstractConsumerMessageHandle</code>.
     *
     * @param handle   the underlying handle
     * @param consumer the consumer of the handle
     * @throws JMSException if the underlying message can't be referenced
     */
    public AbstractConsumerMessageHandle(MessageHandle handle,
                                         ConsumerEndpoint consumer)
            throws JMSException {
        this(handle, consumer.getId(), consumer.getPersistentId());
    }

    /**
     * Construct a new <code>AbstractConsumerMessageHandle</code>.
     *
     * @param handle       the underlying handle
     * @param persistentId the persistent identity of the consumer. May be
     *                     <code>null</code>
     * @throws JMSException if the underlying message can't be referenced
     */
    public AbstractConsumerMessageHandle(MessageHandle handle,
                                         String persistentId)
            throws JMSException {
        this(handle, -1L, persistentId);
    }

    /**
     * Construct a new <code>AbstractConsumerMessageHandle</code>.
     *
     * @param handle       the underlying handle
     * @param consumerId   the consumer identifier
     * @param persistentId the persistent identity of the consumer. May be
     *                     <code>null</code>
     * @throws JMSException if the underlying message can't be referenced
     */
    protected AbstractConsumerMessageHandle(MessageHandle handle, long consumerId,
                                            String persistentId)
            throws JMSException {
        if (handle == null) {
            throw new IllegalArgumentException("Argument 'handle' is null");
        }
        _handle = handle;
        _consumerId = consumerId;
        _persistentId = persistentId;
        _handle.getMessageRef().reference();
    }

    /**
     * Returns the message identifier.
     *
     * @return the message identifier
     */
    public String getMessageId() {
        return _handle.getMessageId();
    }

    /**
     * Indicates if a message has been delivered to a {@link MessageConsumer},
     * but not acknowledged.
     *
     * @param delivered if <code>true</code> indicates that an attempt has been
     *                  made to deliver the message
     */
    public void setDelivered(boolean delivered) {
        _handle.setDelivered(delivered);
    }

    /**
     * Returns if an attempt has already been made to deliver the message.
     *
     * @return <code>true</code> if delivery has been attempted
     */
    public boolean getDelivered() {
        return _handle.getDelivered();
    }

    /**
     * Returns the priority of the message.
     *
     * @return the message priority
     */
    public int getPriority() {
        return _handle.getPriority();
    }

    /**
     * Returns the time that the corresponding message was accepted, in
     * milliseconds.
     *
     * @return the time that the corresponding message was accepted
     */
    public long getAcceptedTime() {
        return _handle.getAcceptedTime();
    }

    /**
     * Returns the time that the message expires.
     *
     * @return the expiry time
     */
    public long getExpiryTime() {
        return _handle.getExpiryTime();
    }

    /**
     * Determines if the message has expired.
     *
     * @return <code>true</code> if the message has expired, otherwise
     *         <code>false</code>
     */
    public boolean hasExpired() {
        return _handle.hasExpired();
    }

    /**
     * Returns the handle's sequence number.
     *
     * @return the sequence number
     */
    public long getSequenceNumber() {
        return _handle.getSequenceNumber();
    }

    /**
     * Returns the message destination.
     *
     * @return the message destination
     */
    public JmsDestination getDestination() {
        return _handle.getDestination();
    }

    /**
     * Returns the consumer identity associated with the message.
     *
     * @return the consumer identity associated with the message, or *
     *         <code>-1</code> if the message isn't associated with a consumer
     */
    public long getConsumerId() {
        return _consumerId;
    }

    /**
     * Returns the name of the consumer endpoint that owns this handle. If it is
     * set, then a consumer owns it exclusively, otherwise the handle may be
     * shared across a number of consumers
     *
     * @return the consumer name, or <code>null</code>
     */
    public String getConsumerPersistentId() {
        return _persistentId;
    }

    /**
     * Returns the connection identity associated with the message.
     *
     * @return the connection identity associated with the message, or
     *         <code>-1</code> if the message isn't associated with a
     *         connection
     */
    public long getConnectionId() {
        return _handle.getConnectionId();
    }

    /**
     * Determines if the handle is persistent.
     *
     * @return <code>true</code> if the handle is persistent; otherwise
     *         <code>false</code>
     */
    public boolean isPersistent() {
        return _persistent;
    }

    /**
     * Returns the message associated with this handle.
     *
     * @return the associated message, or <code>null</code> if the handle is no
     *         longer valid
     * @throws JMSException for any error
     */
    public MessageImpl getMessage() throws JMSException {
        return _handle.getMessage();
    }

    /**
     * Makes the handle persistent.
     *
     * @param connection the connection to use
     * @throws PersistenceException for any persistence error
     */
    public void add(Connection connection) throws PersistenceException {
        DatabaseService.getAdapter().addMessageHandle(connection, this);
        _persistent = true;
    }

    /**
     * Update the persistent handle.
     *
     * @param connection the connection to use
     * @throws PersistenceException for any persistence error
     */
    public void update(Connection connection) throws PersistenceException {
        DatabaseService.getAdapter().updateMessageHandle(connection, this);
    }

    /**
     * Destroy this handle. If this is the last handle to reference the message,
     * also destroys the message
     *
     * @throws JMSException for any error
     */
    public void destroy() throws JMSException {
        _handle.destroy();
    }

    /**
     * Destroy this handle. If this is the last handle to reference the message,
     * also destroys the message
     *
     * @param connection the connection to use
     * @throws JMSException         for any error
     * @throws PersistenceException for any persistence error
     */
    public void destroy(Connection connection) throws JMSException,
            PersistenceException {
        DatabaseService.getAdapter().removeMessageHandle(connection, this);
        _handle.destroy(connection);
        _persistent = false;
    }

    /**
     * Returns the message reference.
     *
     * @return the message reference, or <code>null</code> if none has been set
     */
    public MessageRef getMessageRef() {
        return _handle.getMessageRef();
    }

    /**
     * Set the consumer identifier.
     *
     * @param consumerId the consumer identifier
     */
    protected void setConsumerId(long consumerId) {
        _consumerId = consumerId;
    }

    /**
     * Indicates if the handle is persistent.
     *
     * @param persistent if <code>true</code> indicates the handle is
     *                   persistent
     */
    protected void setPersistent(boolean persistent) {
        _persistent = persistent;
    }

}

⌨️ 快捷键说明

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