remoteserversession.java

来自「OpenJMS是一个开源的Java Message Service API 1.」· Java 代码 · 共 473 行 · 第 1/2 页

JAVA
473
字号
/** * 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 2004-2005 (C) Exoffice Technologies Inc. All Rights Reserved. * * $Id: RemoteServerSession.java,v 1.3 2005/08/30 05:24:21 tanderson Exp $ */package org.exolab.jms.server.net;import java.rmi.RemoteException;import java.util.List;import javax.jms.JMSException;import javax.transaction.xa.XAException;import javax.transaction.xa.Xid;import org.exolab.jms.client.JmsDestination;import org.exolab.jms.client.JmsMessageListener;import org.exolab.jms.client.JmsQueue;import org.exolab.jms.client.JmsTopic;import org.exolab.jms.message.MessageImpl;import org.exolab.jms.net.orb.ORB;import org.exolab.jms.net.orb.UnicastObject;import org.exolab.jms.server.ServerSession;/** * Implementation of the {@link ServerSession} interface which wraps an {@link * ServerSession} to make it remotable. * * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> * @version $Revision: 1.3 $ $Date: 2005/08/30 05:24:21 $ */public class RemoteServerSession        extends UnicastObject        implements ServerSession {    /**     * The connection that created this.     */    private RemoteServerConnection _connection;    /**     * The session to delegate calls to.     */    private ServerSession _session;    /**     * Construct a new <code>RemoteServerSession</code>.     *     * @param orb        the ORB to export this with     * @param connection the connection that created this     * @param session    the session to delegate calls to     * @throws RemoteException if this can't be exported     */    public RemoteServerSession(ORB orb, RemoteServerConnection connection,                               ServerSession session)            throws RemoteException {        super(orb, null, true);        if (connection == null) {            throw new IllegalArgumentException("Argument 'connection' is null");        }        if (session == null) {            throw new IllegalArgumentException("Argument 'session' is null");        }        _connection = connection;        _session = session;    }    /**     * Close and release any resource allocated to this session.     *     * @throws JMSException if the session can't be closed     */    public synchronized void close() throws JMSException {        if (_session != null) {            try {                _session.close();            } finally {                try {                    unexportObject();                } catch (RemoteException exception) {                    JMSException error = new JMSException(                            exception.getMessage());                    error.setLinkedException(exception);                    throw error;                } finally {                    _connection.closed(this);                    _connection = null;                    _session = null;                }            }        }    }    /**     * Acknowledge that a message has been processed.     *     * @param consumerId the identity of the consumer performing the ack     * @param messageId  the message identifier     * @throws JMSException for any error     */    public void acknowledgeMessage(long consumerId, String messageId)            throws JMSException {        _session.acknowledgeMessage(consumerId, messageId);    }    /**     * Send a message.     *     * @param message the message to send     * @throws JMSException for any error     */    public void send(MessageImpl message) throws JMSException {        _session.send(message);    }    /**     * Send a set of messages.     *     * @param messages a list of <code>MessageImpl</code> instances     * @throws JMSException for any JMS error     */    public void send(List messages) throws JMSException {        _session.send(messages);    }    /**     * Return the next available mesage to the specified consumer.     * <p/>     * This method is non-blocking. If no messages are available, it will return     * immediately.     *     * @param consumerId the consumer identifier     * @return the next message or <code>null</code> if none is available     * @throws JMSException for any JMS error     */    public MessageImpl receiveNoWait(long consumerId) throws JMSException {        return _session.receiveNoWait(consumerId);    }    /**     * Return the next available message to the specified consumer.     * <p/>     * This method is non-blocking. However, clients can specify a     * <code>wait</code> interval to indicate how long they are prepared to wait     * for a message. If no message is available, and the client indicates that     * it will wait, it will be notified via the registered {@link     * JmsMessageListener} if one subsequently becomes available.     *     * @param consumerId the consumer identifier     * @param wait       number of milliseconds to wait. A value of <code>0     *                   </code> indicates to wait indefinitely     * @return the next message or <code>null</code> if none is available     * @throws JMSException for any JMS error     */    public MessageImpl receive(long consumerId, long wait) throws JMSException {        return _session.receive(consumerId, wait);    }    /**     * Browse up to count messages.     *     * @param consumerId the consumer identifier     * @param count      the maximum number of messages to receive     * @return a list of {@link MessageImpl} instances     * @throws JMSException for any JMS error     */    public List browse(long consumerId, int count) throws JMSException {        return _session.browse(consumerId, count);    }    /**     * Create a new message consumer.     *     * @param destination the destination to consume messages from     * @param selector    the message selector. May be <code>null</code>     * @param noLocal     if true, and the destination is a topic, inhibits the     *                    delivery of messages published by its own connection.     *                    The behavior for <code>noLocal</code> is not specified     *                    if the destination is a queue.     * @return the identifty of the message consumer     * @throws JMSException for any JMS error     */    public long createConsumer(JmsDestination destination, String selector,                               boolean noLocal) throws JMSException {        return _session.createConsumer(destination, selector, noLocal);    }    /**     * Create a new durable consumer. Durable consumers may only consume from     * non-temporary <code>Topic</code> destinations.     *     * @param topic    the non-temporary <code>Topic</code> to subscribe to     * @param name     the name used to identify this subscription     * @param selector only messages with properties matching the message     *                 selector expression are delivered.  A value of null or an     *                 empty string indicates that there is no message selector     *                 for the message consumer.     * @param noLocal  if set, inhibits the delivery of messages published by

⌨️ 快捷键说明

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