Example usage for javax.jms QueueBrowser close

List of usage examples for javax.jms QueueBrowser close

Introduction

In this page you can find the example usage for javax.jms QueueBrowser close.

Prototype


void close() throws JMSException;

Source Link

Document

Closes the QueueBrowser .

Usage

From source file:tools.ConsumerTool.java

public void runQueueBrowser(Session session, Queue queue) throws JMSException, InterruptedException {
    QueueBrowser browser = null;
    if (selector != null) {
        browser = session.createBrowser(queue, selector);
    } else {/*from  www  .j a v  a2s . c  o m*/
        browser = session.createBrowser(queue);
    }

    Enumeration messages = browser.getEnumeration();
    int perConsumerReceivedMessages = 0;
    while (perConsumerReceivedMessages < numMessages) {
        if (messages != null) {
            while (messages.hasMoreElements()) {
                Message message = (Message) messages.nextElement();
                if (message != null) {
                    perConsumerReceivedMessages++;
                    handleMessage(session, message, perConsumerReceivedMessages);
                }
            }
        }
        Thread.sleep(receiveTimeoutMS);
        messages = browser.getEnumeration();
    }
    browser.close();

}