Search in sources :

Example 6 with QueueBrowser

use of javax.jms.QueueBrowser in project ats-framework by Axway.

the class ManagedSession method close.

@Override
public synchronized void close() throws JMSException {
    for (final QueueBrowser b : browsers) try {
        b.close();
    } catch (final Exception e) {
    }
    browsers.clear();
    for (final MessageConsumer b : consumers) try {
        b.close();
    } catch (final Exception e) {
    }
    for (final MessageProducer b : producers) try {
        b.close();
    } catch (final Exception e) {
    }
    for (final ManagedSession b : sessions) b.shutdown();
    session.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageProducer(javax.jms.MessageProducer) QueueBrowser(javax.jms.QueueBrowser) JMSException(javax.jms.JMSException)

Example 7 with QueueBrowser

use of javax.jms.QueueBrowser in project beam by apache.

the class JmsIOTest method count.

private int count(String queue) throws Exception {
    Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueBrowser browser = session.createBrowser(session.createQueue(queue));
    Enumeration<Message> messages = browser.getEnumeration();
    int count = 0;
    while (messages.hasMoreElements()) {
        messages.nextElement();
        count++;
    }
    return count;
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session)

Example 8 with QueueBrowser

use of javax.jms.QueueBrowser in project karaf by apache.

the class PooledSession method close.

@Override
public void close() throws JMSException {
    if (!ignoreClose) {
        boolean invalidate = false;
        try {
            // lets reset the session
            getInternalSession().setMessageListener(null);
            // Close any consumers and browsers that may have been created.
            for (MessageConsumer consumer : consumers) {
                consumer.close();
            }
            for (QueueBrowser browser : browsers) {
                browser.close();
            }
            if (transactional && !isXa) {
                try {
                    getInternalSession().rollback();
                } catch (JMSException e) {
                    invalidate = true;
                    LOG.warn("Caught exception trying rollback() when putting session back into the pool, will invalidate. " + e, e);
                }
            }
        } catch (JMSException ex) {
            invalidate = true;
            LOG.warn("Caught exception trying close() when putting session back into the pool, will invalidate. " + ex, ex);
        } finally {
            consumers.clear();
            browsers.clear();
            for (PooledSessionEventListener listener : this.sessionEventListeners) {
                listener.onSessionClosed(this);
            }
            sessionEventListeners.clear();
        }
        if (invalidate) {
            // instead invalidate it so the pool can create a new one on demand.
            if (session != null) {
                try {
                    session.close();
                } catch (JMSException e1) {
                    LOG.trace("Ignoring exception on close as discarding session: " + e1, e1);
                }
                session = null;
            }
            try {
                sessionPool.invalidateObject(key, this);
            } catch (Exception e) {
                LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e);
            }
        } else {
            try {
                sessionPool.returnObject(key, this);
            } catch (Exception e) {
                javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString());
                illegalStateException.initCause(e);
                throw illegalStateException;
            }
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JMSException(javax.jms.JMSException) QueueBrowser(javax.jms.QueueBrowser) JMSException(javax.jms.JMSException)

Example 9 with QueueBrowser

use of javax.jms.QueueBrowser in project sling by apache.

the class JMSQueueManagerTest method dumpQueue.

private void dumpQueue(String name) throws JMSException {
    Connection connection = amqConnectionFactoryService.getConnectionFactory().createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Queue queue = session.createQueue(name);
    QueueBrowser browser = session.createBrowser(queue);
    LOGGER.info("Starting to dump queue {} ", name);
    int n = 0;
    for (Enumeration messages = browser.getEnumeration(); messages.hasMoreElements(); ) {
        Message m = (Message) messages.nextElement();
        LOGGER.info("Message at {}  is {} ", n, m);
        n++;
    }
    LOGGER.info("Done dump queue {} ", name);
    browser.close();
    session.close();
    connection.stop();
}
Also used : Enumeration(java.util.Enumeration) Message(javax.jms.Message) Connection(javax.jms.Connection) Queue(javax.jms.Queue) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session)

Example 10 with QueueBrowser

use of javax.jms.QueueBrowser in project javaee7-firstcup by ecabrerar.

the class ReceivePointsBean method getQueueSize.

public int getQueueSize() {
    int count = 0;
    try {
        QueueBrowser browser = context.createBrowser(pointsQueue);
        Enumeration elems = browser.getEnumeration();
        while (elems.hasMoreElements()) {
            elems.nextElement();
            count++;
        }
    } catch (JMSException ex) {
        ex.printStackTrace();
    }
    return count;
}
Also used : Enumeration(java.util.Enumeration) JMSException(javax.jms.JMSException) QueueBrowser(javax.jms.QueueBrowser)

Aggregations

QueueBrowser (javax.jms.QueueBrowser)10 JMSException (javax.jms.JMSException)6 Enumeration (java.util.Enumeration)4 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 Session (javax.jms.Session)4 MessageConsumer (javax.jms.MessageConsumer)3 Queue (javax.jms.Queue)3 MessageProducer (javax.jms.MessageProducer)1 TextMessage (javax.jms.TextMessage)1