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();
}
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;
}
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;
}
}
}
}
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();
}
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;
}
Aggregations