📄 queuebrowserendpoint.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 2001-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: QueueBrowserEndpoint.java,v 1.24 2003/08/13 13:30:54 tanderson Exp $
*
* Date Author Changes
* 3/1/2001 jima Created
*/
package org.exolab.jms.messagemgr;
import java.util.Vector;
import javax.jms.InvalidSelectorException;
import javax.jms.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.jms.client.JmsDestination;
import org.exolab.jms.client.JmsQueue;
import org.exolab.jms.message.MessageHandle;
import org.exolab.jms.message.MessageImpl;
import org.exolab.jms.scheduler.Scheduler;
import org.exolab.jms.server.JmsServerSession;
/**
* A QueueBrowserEndpoint is a QueueListener to a QueueDestinationCache. This
* enables it to receive all the messages, which it then feeds down to the
* client side.
*
* @version $Revision: 1.24 $ $Date: 2003/08/13 13:30:54 $
* @author <a href="mailto:jima@exoffice.com">Jim Alateras</a>
*/
public class QueueBrowserEndpoint
extends ConsumerEndpoint
implements QueueListener {
/**
* The destination that this consumer subscribes too
*/
private QueueDestinationCache _cache = null;
/**
* The queue that this endpoint is subscribed too
*/
private JmsQueue _queue = null;
/**
* The logger
*/
private static final Log _log =
LogFactory.getLog(QueueBrowserEndpoint.class);
/**
* Construct a QueueConsumerEndpoint, that extends ConsumerEndpoint and
* is used to manage both synchronous and asynchronous message delivery
* for this consumer.
*
* @param session - the owning session
* @param clientId - uniquely identifies the remote client within session
* @param destination - destination that this object was created for
* @param selector - the selector attached to the consumer, if any.
* @param scheduler - used to schedule async message delivery.
* @throws InvalidSelectorException
*/
QueueBrowserEndpoint(JmsServerSession session, long clientId,
JmsQueue destination, String selector,
Scheduler scheduler)
throws InvalidSelectorException {
super(session, clientId, selector, scheduler);
_cache = (QueueDestinationCache)
DestinationManager.instance().getDestinationCache(destination);
// if a cache is not active then we need to create one.
if (_cache == null) {
_cache = (QueueDestinationCache)
DestinationManager.instance().createDestinationCache(
destination);
}
// cache the destination
_queue = destination;
// set up the message cache and register itself as a listener to the
// cache
_cache.addQueueListener(this);
_cache.playbackMessages(this);
}
/**
* Deliver messages in the cache to the consumer.<p>
* This is not relevant to QueueBrowsers, and thus shouldn't be invoked.
*
* @return <code>false</code>
*/
public boolean deliverMessages() {
_log.error(
"QueueBrowserEndpoint.deliverMessages() should never be called",
new Exception());
return false;
}
// implementation of ConsumerEndpoint.receiveMessage
public synchronized MessageHandle receiveMessage(long wait) {
throw new UnsupportedOperationException(
"Cannot call receiveMessage for QueueBrowser");
}
/**
* Return, at most, count messages from the cache.
*
* @param count - the max number of messages to receive
* @return Vector - number of messages
*/
public synchronized Vector receiveMessages(int count) {
Vector messages = new Vector();
int index = 0;
while (index < count) {
// check if we should exit the loop
if (isStopped() || getMessageCount() == 0) {
break;
}
// remove the first message from the list and check
// that it is not null. Synchronize the removal of
// the message but not the sending to the remote
// consumer
try {
MessageHandle handle = removeFirstMessage();
MessageImpl m = handle.getMessage();
if (m != null) {
// add it to the list of messages to send
// but only deliver messsages that satisfy the
// selection criteria.
if ((_selector == null) ||
(_selector.selects(m))) {
handle.setClientId(getClientId());
messages.addElement(handle);
++index;
} else {
// drop the message
}
} else {
// message may have been consumed in the interim
}
} catch (Exception exception) {
_log.error(exception, exception);
}
}
return messages;
}
// implementation of ConsumerEndpoint.getDestination
public JmsDestination getDestination() {
return _queue;
}
// implementation of ConsumerEndpoint.unregister
public void unregister() {
_cache.unregisterConsumer(this);
}
// override implementation of ConsumerEndpoint.returnMessage
public void returnMessage(MessageHandle handle) {
// no-op at the moment. What happens to a QueueBrowser when
// a transaction aborts.
}
// implementation of QueueListener.onMessage
public void onMessage(MessageImpl message) {
// delegate to message added, regardless of whether or not
// the message is persistent.
messageAdded(message);
}
// override ConsumerEndpoint.setMessageListener
public void setMessageListener(InternalMessageListener listener) {
_log.error(
"QueueBrowserEndpoint.setMessageListener should never be called");
Thread.currentThread().dumpStack();
}
/**
* Closes this endpoint
*/
protected void doClose() {
// unregister from the DestinationCache
_cache.removeQueueListener(this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -