本文整理汇总了Java中javax.jms.QueueBrowser.getEnumeration方法的典型用法代码示例。如果您正苦于以下问题:Java QueueBrowser.getEnumeration方法的具体用法?Java QueueBrowser.getEnumeration怎么用?Java QueueBrowser.getEnumeration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.QueueBrowser
的用法示例。
在下文中一共展示了QueueBrowser.getEnumeration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetEnumeration
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test
public void testGetEnumeration() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser.getEnumeration());
browser.close();
try {
browser.getEnumeration();
fail("Should not be able to use a closed browser");
} catch (IllegalStateException ise) {
}
}
示例2: testBrowserNotAuthorized
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout = 30000)
public void testBrowserNotAuthorized() throws Exception {
Connection connection = createConnection(noprivUser, noprivPass);
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName());
try {
QueueBrowser browser = session.createBrowser(queue);
// Browser is not created until an enumeration is requesteda
browser.getEnumeration();
fail("Should not be able to consume here.");
} catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
}
} finally {
connection.close();
}
}
示例3: testNoMessagesBrowserHasNoElements
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout = 40000)
public void testNoMessagesBrowserHasNoElements() throws Exception {
Connection connection = createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
javax.jms.Queue queue = session.createQueue(getQueueName());
session.createConsumer(queue).close();
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser);
Queue queueView = getProxyToQueue(getQueueName());
assertEquals(0, queueView.getMessageCount());
Enumeration<?> enumeration = browser.getEnumeration();
assertFalse(enumeration.hasMoreElements());
}
示例4: testBroseOneInQueue
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout=30000)
public void testBroseOneInQueue() throws Exception {
connection = createAmqpConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(getDestinationName());
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("hello"));
producer.close();
QueueBrowser browser = session.createBrowser(queue);
Enumeration enumeration = browser.getEnumeration();
while (enumeration.hasMoreElements()) {
Message m = (Message) enumeration.nextElement();
assertTrue(m instanceof TextMessage);
LOG.debug("Browsed message {} from Queue {}", m, queue);
}
browser.close();
MessageConsumer consumer = session.createConsumer(queue);
Message msg = consumer.receive(5000);
assertNotNull(msg);
assertTrue(msg instanceof TextMessage);
}
示例5: browseData
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
private static List<Data<Long, Integer>> browseData(Session session, Queue destination) throws JMSException {
List<Data<Long, Integer>> data = new ArrayList<>();
QueueBrowser browser = session.createBrowser(destination);
Enumeration<Message> msgs = browser.getEnumeration();
Long minTime = Long.MAX_VALUE;
Long maxTime = Long.MIN_VALUE;
while (msgs.hasMoreElements()) {
Message msg = msgs.nextElement();
Integer rssi = msg.getIntProperty("rssi");
Long time = msg.getLongProperty("time");
minTime = Math.min(minTime, time);
maxTime = Math.max(maxTime, time);
data.add(new Data<>(time, rssi));
}
browser.close();
long duration = maxTime - minTime;
long hours = duration / (3600*1000);
double days = hours / 24.0;
System.out.printf("minTime=%s, maxTime=%s, hours=%d, days=%.2f\n", minTime, maxTime, hours, days);
return data;
}
示例6: testNoMessagesBrowserHasNoElements
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test(timeout = 60000)
public void testNoMessagesBrowserHasNoElements() throws Exception {
connection = createAmqpConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
Queue queue = session.createQueue(name.getMethodName());
session.createConsumer(queue).close();
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser);
QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
assertEquals(0, proxy.getQueueSize());
Enumeration enumeration = browser.getEnumeration();
assertFalse(enumeration.hasMoreElements());
}
示例7: testBrowseAllInQueueTxSession
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout = 40000)
public void testBrowseAllInQueueTxSession() throws Exception {
connection = createAmqpConnection();
connection.start();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
assertNotNull(session);
Queue queue = session.createQueue(getDestinationName());
sendToAmqQueue(5);
QueueViewMBean proxy = getProxyToQueue(getDestinationName());
assertEquals(5, proxy.getQueueSize());
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser);
Enumeration enumeration = browser.getEnumeration();
int count = 0;
while (enumeration.hasMoreElements()) {
Message msg = (Message) enumeration.nextElement();
assertNotNull(msg);
LOG.debug("Recv: {}", msg);
count++;
}
assertFalse(enumeration.hasMoreElements());
assertEquals(5, count);
}
示例8: closeBrowserBeforeAfterGetNext
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
protected void closeBrowserBeforeAfterGetNext(int messageCount) throws JMSException
{
QueueBrowser queueBrowser = _clientSession.createBrowser(_queue);
Enumeration msgs = queueBrowser.getEnumeration();
int msgCount = 0;
while (msgs.hasMoreElements() && msgCount < messageCount)
{
msgs.nextElement();
msgCount++;
}
try
{
queueBrowser.close();
}
catch (JMSException e)
{
fail("Close should happen without error:" + e.getMessage());
}
}
示例9: testNoMessagesBrowserHasNoElements
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test(timeout = 60000)
public void testNoMessagesBrowserHasNoElements() throws Exception {
connection = createStompConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
Queue queue = session.createQueue(name.getMethodName());
session.createConsumer(queue).close();
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser);
QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
assertEquals(0, proxy.getQueueSize());
Enumeration enumeration = browser.getEnumeration();
assertFalse(enumeration.hasMoreElements());
}
示例10: getQueueMessageCount
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
protected static long getQueueMessageCount(Session jSession,
String queueName, String messageSelector) throws JMSException {
QueueBrowser queueBrowser = null;
try {
Queue queue = jSession.createQueue(queueName);
if (messageSelector == null) {
queueBrowser = jSession.createBrowser(queue);
} else {
queueBrowser = jSession.createBrowser(queue, messageSelector);
}
int count = 0;
for (Enumeration enm = queueBrowser.getEnumeration(); enm
.hasMoreElements(); enm.nextElement()) {
count++;
}
return count;
} finally {
if (queueBrowser != null) {
try {
queueBrowser.close();
} catch (JMSException e) {
log.warn("Exception on closing queueBrowser", e);
}
}
}
}
示例11: browseMessages
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
/**
* Browse messages using Queue Browser.
* By default, you browse all actual messages in the queue.
* Messages may be arriving and expiring while the scan is done.
*/
void browseMessages() throws Exception {
Connection conn = createConnection(clientOptions);
Session ssn = createSession(clientOptions, conn, transacted);
QueueBrowser qBrowser = ssn.createBrowser((Queue) getDestination(), msgSelector);
conn.start();
Enumeration<?> enumMsgs = qBrowser.getEnumeration();
while (enumMsgs.hasMoreElements()) {
Message msg = (Message) enumMsgs.nextElement();
printMessage(clientOptions, msg);
}
close(conn);
}
示例12: checkOrDeleteLockingPendingMessages
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
/** Browses all pending messages in the input queue looking for the locks, as specified in the input filter.
* Throws an ApplicationException, if any matching message is found, and if the input argument 'deleteLockingMessage' is false.
* Deletes all matching messages, if the input argument 'deleteLockingMessage' is true.
* @param queueName the queue name.
* @param filter the filter for retrieving Lock messages.
* @param deleteLockingMessage determines if the matching messages are to be deleted.
* @param session the JMS session.
* @throws JMSException if any JMS error occurs.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
private static void checkOrDeleteLockingPendingMessages(String queueName, String filter, boolean deleteLockingMessage, Session session)
throws JMSException, ApplicationExceptions, FrameworkException {
// Creates a QueueBrowser from the Session, using the filter
if (log.isDebugEnabled())
log.debug("Checking for locks in pending messages in " + queueName + " with the filter " + filter);
QueueBrowser qb = session.createBrowser(JmsClientHelper.obtainQueue(queueName), filter);
// Throws an ApplicationException if any applicable lock is found
Enumeration e = qb.getEnumeration();
while (e.hasMoreElements()) {
Message message = (Message) e.nextElement();
if (log.isDebugEnabled())
log.debug("Found a blocking pending message in " + queueName + " with the contents " + message);
if (deleteLockingMessage)
JmsBrowser.consumeMessage(session, message, queueName);
else
throw new ApplicationExceptions(new JaffaMessagingApplicationException(JaffaMessagingApplicationException.LOCK_ERROR, new Object[] {queueName, message.getJMSMessageID()}));
}
// Close the QueueBrowser
qb.close();
}
示例13: testBrowseAllInQueueSmallPrefetch
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testBrowseAllInQueueSmallPrefetch() throws Exception {
Connection connection = createConnection();
connection.start();
final int MSG_COUNT = 30;
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
javax.jms.Queue queue = session.createQueue(getQueueName());
sendMessages(name.getMethodName(), MSG_COUNT, false);
Queue queueView = getProxyToQueue(getQueueName());
Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser);
Enumeration<?> enumeration = browser.getEnumeration();
int count = 0;
while (enumeration.hasMoreElements()) {
Message msg = (Message) enumeration.nextElement();
assertNotNull(msg);
LOG.debug("Recv: {}", msg);
count++;
}
assertFalse(enumeration.hasMoreElements());
assertEquals(MSG_COUNT, count);
}
示例14: getMessageCount
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
public int getMessageCount(QueueBrowser browser, String prefix) throws JMSException {
Enumeration<?> e = browser.getEnumeration();
int with = 0;
while (e.hasMoreElements()) {
Object o = e.nextElement();
System.out.println(prefix + o);
with++;
}
return with;
}
示例15: testBrowserAndConsumerSimultaneousDifferentConnections
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test
public void testBrowserAndConsumerSimultaneousDifferentConnections() throws Exception {
((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
conn = cf.createConnection();
Connection connConsumer = cf.createConnection();
Session sessionConsumer = connConsumer.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
MessageConsumer consumer = sessionConsumer.createConsumer(jBossQueue);
int noOfMessages = 1000;
for (int i = 0; i < noOfMessages; i++) {
TextMessage textMessage = session.createTextMessage("m" + i);
textMessage.setIntProperty("i", i);
producer.send(textMessage);
}
connConsumer.start();
QueueBrowser browser = session.createBrowser(jBossQueue);
Enumeration enumMessages = browser.getEnumeration();
for (int i = 0; i < noOfMessages; i++) {
TextMessage msg = (TextMessage) enumMessages.nextElement();
Assert.assertNotNull(msg);
Assert.assertEquals(i, msg.getIntProperty("i"));
TextMessage recvMessage = (TextMessage) consumer.receiveNoWait();
Assert.assertNotNull(recvMessage);
Assert.assertEquals(i, msg.getIntProperty("i"));
}
Message m = consumer.receiveNoWait();
Assert.assertFalse(enumMessages.hasMoreElements());
Assert.assertNull(m);
conn.close();
}