List of usage examples for javax.jms QueueBrowser getEnumeration
Enumeration getEnumeration() throws JMSException;
From source file:org.logicblaze.lingo.jms.JmsClient.java
public Message peek() throws JMSException { QueueBrowser browser = createBrowser(); try {// w ww . jav a2s .c o m Enumeration iter = browser.getEnumeration(); if (iter.hasMoreElements()) { return (Message) iter.nextElement(); } return null; } finally { try { browser.close(); } catch (JMSException e) { onBrowserCloseException(e); return null; } } }
From source file:org.symplify.runtime.jms.JMSContextImpl.java
public Message peek(Channel channel) throws Exception { Message ret = null;//from w w w . ja va 2 s . c o m javax.jms.Queue queue = getQueue(channel); if (queue != null) { javax.jms.QueueBrowser browser = m_session.createBrowser(queue); if (browser.getEnumeration().hasMoreElements()) { javax.jms.Message m = (javax.jms.Message) browser.getEnumeration().nextElement(); if (m instanceof javax.jms.ObjectMessage) { ret = (Message) ((javax.jms.ObjectMessage) m).getObject(); } } browser.close(); } else { throw new Exception("Unable to find queue for channel"); } if (logger.isDebugEnabled()) { logger.debug("Peek on channel " + channel + " = " + ret); } return (ret); }
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 {/*w w w .j av a2 s .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(); }