本文整理汇总了Java中javax.jms.QueueBrowser.close方法的典型用法代码示例。如果您正苦于以下问题:Java QueueBrowser.close方法的具体用法?Java QueueBrowser.close怎么用?Java QueueBrowser.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.QueueBrowser
的用法示例。
在下文中一共展示了QueueBrowser.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetQueue
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test
public void testGetQueue() 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.getQueue());
browser.close();
browser.close();
try {
browser.getQueue();
fail("Should not be able to use a closed browser");
} catch (IllegalStateException ise) {
}
}
示例2: testGetMessageSelector
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test
public void testGetMessageSelector() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueBrowser browser = session.createBrowser(queue, "color = red");
assertNotNull(browser.getMessageSelector());
assertEquals("color = red", browser.getMessageSelector());
browser.close();
try {
browser.getMessageSelector();
fail("Should not be able to use a closed browser");
} catch (IllegalStateException ise) {
}
}
示例3: 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) {
}
}
示例4: testBroseOneInQueue
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout = 30000)
public void testBroseOneInQueue() throws Exception {
Connection connection = createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName());
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: getScannerConfig
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
/**
* Search the scanners configuration json data for a scanner specific configuration that matches this scanners
* hardware mac address. This sets the baseConfig object as a side effect.
*
* @param destinationName
* @param session
* @return
* @throws Exception
*/
Properties getScannerConfig(String destinationName, Session session) throws Exception{
Queue destination = session.createQueue(destinationName);
QueueBrowser browser = session.createBrowser(destination);
Enumeration configs = browser.getEnumeration();
Properties scannerProperties = null;
while (configs.hasMoreElements()) {
Message msg = (Message) configs.nextElement();
if (msg instanceof TextMessage) {
TextMessage tmsg = TextMessage.class.cast(msg);
String json = tmsg.getText();
baseConfig = Utils.parseConfig(json);
log.infof("baseConfig: %s\n", baseConfig);
// Find matching scanner properties
scannerProperties = Utils.findPropertiesByHardwareAddress(baseConfig);
if (scannerProperties != null)
break;
} else {
log.errorf("Skipping non-TextMessage: %s\n", msg);
}
}
browser.close();
return scannerProperties;
}
示例7: closeRemainingBrowsers
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
/**
* Close remaining browsers
*/
private void closeRemainingBrowsers()
{
List<AbstractQueueBrowser> browsersToClose = new ArrayList<>(browsersMap.size());
synchronized (browsersMap)
{
browsersToClose.addAll(browsersMap.values());
}
for (int n = 0 ; n < browsersToClose.size() ; n++)
{
QueueBrowser browser = browsersToClose.get(n);
log.debug("Auto-closing unclosed browser : "+browser);
try
{
browser.close();
}
catch (Exception e)
{
log.error("Could not close browser "+browser,e);
}
}
}
示例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: testCreateQueueBrowserWithoutEnumeration
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test(timeout=30000)
public void testCreateQueueBrowserWithoutEnumeration() throws IOException, Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
connection.start();
testPeer.expectBegin();
testPeer.expectEnd();
testPeer.expectClose();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("myQueue");
// Creating the browser should send nothing until an Enumeration is created.
QueueBrowser browser = session.createBrowser(queue);
browser.close();
session.close();
connection.close();
testPeer.waitForAllHandlersToComplete(3000);
}
}
示例10: 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);
}
示例11: 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);
}
}
}
}
示例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: queueSize
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
public int queueSize(ActiveMQQueue queue) throws JMSException {
QueueBrowser browser = session.createBrowser(queue);
int i = 0;
try {
Enumeration messages = browser.getEnumeration();
while (messages.hasMoreElements()) {
messages.nextElement();
i++;
}
} finally {
browser.close();
}
return i;
}
示例14: testLargeNumberOfMessages
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
@Test
public void testLargeNumberOfMessages() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = (ActiveMQQueue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
connection.start();
MessageProducer producer = session.createProducer(destination);
int numberOfMessages = 4096;
for (int i = 0; i < numberOfMessages; i++) {
producer.send(session.createTextMessage("Message: " + i));
}
QueueBrowser browser = session.createBrowser(destination);
Enumeration<?> enumeration = browser.getEnumeration();
assertTrue(enumeration.hasMoreElements());
int numberBrowsed = 0;
while (enumeration.hasMoreElements()) {
Message browsed = (Message) enumeration.nextElement();
System.out.println("Browsed Message [{}]" + browsed.getJMSMessageID());
numberBrowsed++;
}
System.out.println("Number browsed: " + numberBrowsed);
assertEquals(numberOfMessages, numberBrowsed);
browser.close();
producer.close();
}
示例15: testPurgeCommandComplexSelector
import javax.jms.QueueBrowser; //导入方法依赖的package包/类
public void testPurgeCommandComplexSelector() throws Exception {
try {
PurgeCommand purgeCommand = new PurgeCommand();
CommandContext context = new CommandContext();
context.setFormatter(new CommandShellOutputFormatter(System.out));
purgeCommand.setCommandContext(context);
purgeCommand.setJmxUseLocal(true);
List<String> tokens = new ArrayList<>();
tokens.add("--msgsel");
tokens.add(MSG_SEL_COMPLEX);
addMessages();
validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
purgeCommand.execute(tokens);
QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_COMPLEX);
QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
int allCount = getMessageCount(allBrowser, "allMessages ");
withPropertyBrowser.close();
allBrowser.close();
assertEquals("Expected withCount to be " + "0" + " was " + withCount, 0, withCount);
assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " + allCount, MESSAGE_COUNT, allCount);
LOG.info("withCount = " + withCount + "\n allCount = " +
allCount + "\n = " + "\n");
} finally {
purgeAllMessages();
}
}