Java 类javax.jms.QueueBrowser 实例源码

项目:pooled-jms    文件:JmsQueueBrowserTest.java   
@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) {
    }
}
项目:pooled-jms    文件:JmsQueueBrowserTest.java   
@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) {
    }
}
项目:pooled-jms    文件:JmsQueueBrowserTest.java   
@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) {
    }
}
项目:jaffa-framework    文件:LockingService.java   
/** 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();
}
项目:spring4-understanding    文件:JmsTemplate.java   
@Override
public <T> T browseSelected(final Queue queue, final String messageSelector, final BrowserCallback<T> action)
        throws JmsException {

    Assert.notNull(action, "Callback object must not be null");
    return execute(new SessionCallback<T>() {
        @Override
        public T doInJms(Session session) throws JMSException {
            QueueBrowser browser = createBrowser(session, queue, messageSelector);
            try {
                return action.doInJms(session, browser);
            }
            finally {
                JmsUtils.closeQueueBrowser(browser);
            }
        }
    }, true);
}
项目:spring4-understanding    文件:JmsTemplate.java   
@Override
public <T> T browseSelected(final String queueName, final String messageSelector, final BrowserCallback<T> action)
        throws JmsException {

    Assert.notNull(action, "Callback object must not be null");
    return execute(new SessionCallback<T>() {
        @Override
        public T doInJms(Session session) throws JMSException {
            Queue queue = (Queue) getDestinationResolver().resolveDestinationName(session, queueName, false);
            QueueBrowser browser = createBrowser(session, queue, messageSelector);
            try {
                return action.doInJms(session, browser);
            }
            finally {
                JmsUtils.closeQueueBrowser(browser);
            }
        }
    }, true);
}
项目:rabbitmq-jms-samples    文件:BrowseConfig.java   
@Profile("browse")
@Bean
public QueueBrowser queueBrowser(Session queueSession, AMQPProperties amqpProperties, JMSProperties jmsProperties) {
    QueueBrowser messageBrowser = null;
    try {
        if(amqpProperties.amqpExchangeName != null && !"".equals(amqpProperties.amqpExchangeName)) {
            log.info("Not a valid option for queue browser");
            messageBrowser = queueSession.createBrowser(queueSession.createQueue(jmsProperties.queueName));
        }
        else {
            log.info("Creating QueueBrowser using JMS Queue obj for queueName="+jmsProperties.queueName);
            messageBrowser = queueSession.createBrowser(queueSession.createQueue(jmsProperties.queueName));
        }
    } catch (JMSException e) {
        e.printStackTrace();
    }
    return messageBrowser;
}
项目:eHMP    文件:JmsSyncErrorDaoTests.java   
@Before
public void setUp() throws Exception {
    mockJmsSession = mock(Session.class);
    mockJmsQueueBrowser = mock(QueueBrowser.class);
    mockJmsTemplate = mock(JmsOperations.class);
    mockConversionService = mock(ConversionService.class);
    mockQueueMBean = mock(QueueViewMBean.class);
    mockErrorDao = mock(IVprSyncErrorDao.class);

    syncService = new SyncService();
    syncService.setConversionService(mockConversionService);
    syncService.setErrorDao(mockErrorDao);
    syncService.setJmsTemplate(mockJmsTemplate);
    syncService.setVprDeadLetterQueueMBean(mockQueueMBean);

    when(mockJmsTemplate.browse(eq(MessageDestinations.DEAD_LETTER_QUEUE), any(BrowserCallback.class))).thenAnswer(new ReturnsBrowserCallbackArgument<Object>(mockJmsSession, mockJmsQueueBrowser));
}
项目:activemq-artemis    文件:JMSUsecaseTest.java   
@Test
public void testQueueBrowser() throws Exception {
   // Send a message to the broker.
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, destinationType);
   MessageProducer producer = session.createProducer(destination);
   producer.setDeliveryMode(this.deliveryMode);
   sendMessages(session, producer, 5);
   producer.close();

   QueueBrowser browser = session.createBrowser((Queue) destination);
   Enumeration<?> enumeration = browser.getEnumeration();
   for (int i = 0; i < 5; i++) {
      Thread.sleep(100);
      assertTrue(enumeration.hasMoreElements());
      Message m = (Message) enumeration.nextElement();
      assertNotNull(m);
      assertEquals("" + i, ((TextMessage) m).getText());
   }
   assertFalse(enumeration.hasMoreElements());
}
项目:activemq-artemis    文件:JMSConnectionWithSecurityTest.java   
@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();
   }
}
项目:activemq-artemis    文件:JMSQueueBrowserTest.java   
@Test(timeout = 40000)
public void testCreateQueueBrowser() 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());
}
项目:activemq-artemis    文件:JMSQueueBrowserTest.java   
@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());
}
项目:activemq-artemis    文件:JMSQueueBrowserTest.java   
@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);
}
项目:activemq-artemis    文件:JMSQueueBrowserTest.java   
@Test(timeout = 60000)
public void testBrowseAllInQueuePrefetchOne() throws Exception {
   Connection connection = createConnection();
   connection.start();

   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   assertNotNull(session);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   sendMessages(name.getMethodName(), 5, false);

   Queue queueView = getProxyToQueue(getQueueName());
   Wait.assertEquals(5, 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(5, count);
}
项目:activemq-artemis    文件:JMSQueueBrowserTest.java   
@Test(timeout = 40000)
public void testBrowseAllInQueueTxSession() throws Exception {
   Connection connection = createConnection();
   connection.start();

   Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
   assertNotNull(session);
   javax.jms.Queue queue = session.createQueue(getQueueName());
   sendMessages(name.getMethodName(), 5, false);

   Queue queueView = getProxyToQueue(getQueueName());
   Wait.assertEquals(5, 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(5, count);
}
项目:activemq-artemis    文件:SecurityJMXTest.java   
public void testBrowseExpiredMessages() throws Exception {
   JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
   JMXConnector connector = JMXConnectorFactory.connect(url, null);
   connector.connect();
   MBeanServerConnection connection = connector.getMBeanServerConnection();
   ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," + "destinationType=Queue,destinationName=TEST.Q");
   QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
   HashMap<String, String> headers = new HashMap<>();
   headers.put("timeToLive", Long.toString(2000));
   headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
   queueMbean.sendTextMessage(headers, "test", "system", "manager");
   // allow message to expire on the queue
   TimeUnit.SECONDS.sleep(4);

   Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
   c.start();

   // browser consumer will force expiration check on addConsumer
   QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
   assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());

   // verify dlq got the message, no security exception as brokers context is now used
   browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
   assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
项目:activemq-artemis    文件:PurgeCommandTest.java   
public void validateCounts(int expectedWithCount,
                           int expectedWithoutCount,
                           int expectedAllCount) throws JMSException {
   QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_WITH_PROPERTY);
   QueueBrowser withoutPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY);
   QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);

   int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
   int withoutCount = getMessageCount(withoutPropertyBrowser, "withoutProperty ");
   int allCount = getMessageCount(allBrowser, "allMessages ");

   withPropertyBrowser.close();
   withoutPropertyBrowser.close();
   allBrowser.close();

   assertEquals("Expected withCount to be " + expectedWithCount + " was " + withCount, expectedWithCount, withCount);
   assertEquals("Expected withoutCount to be " + expectedWithoutCount + " was " + withoutCount, expectedWithoutCount, withoutCount);
   assertEquals("Expected allCount to be " + expectedAllCount + " was " + allCount, expectedAllCount, allCount);
   LOG.info("withCount = " + withCount + "\n withoutCount = " + withoutCount + "\n allCount = " + allCount + "\n  = " + "\n");
}
项目:activemq-artemis    文件:JMSUsecaseTest.java   
public void testQueueBrowser() throws Exception {

      // Send a message to the broker.
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      destination = createDestination(session, destinationType);
      MessageProducer producer = session.createProducer(destination);
      producer.setDeliveryMode(this.deliveryMode);
      sendMessages(session, producer, 5);
      producer.close();

      QueueBrowser browser = session.createBrowser((Queue) destination);
      Enumeration<?> enumeration = browser.getEnumeration();
      for (int i = 0; i < 5; i++) {
         Thread.sleep(100);
         assertTrue(enumeration.hasMoreElements());
         Message m = (Message) enumeration.nextElement();
         assertNotNull(m);
         assertEquals("" + i, ((TextMessage) m).getText());
      }
      assertFalse(enumeration.hasMoreElements());
   }
项目:activemq-artemis    文件:ActiveMQRASession.java   
/**
 * Create a browser
 *
 * @param queue The queue
 * @return The browser
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueBrowser createBrowser(final Queue queue) throws JMSException {
   if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
      throw new IllegalStateException("Cannot create browser for javax.jms.TopicSession");
   }

   Session session = getSessionInternal();

   if (ActiveMQRASession.trace) {
      ActiveMQRALogger.LOGGER.trace("createBrowser " + session + " queue=" + queue);
   }

   QueueBrowser result = session.createBrowser(queue);

   if (ActiveMQRASession.trace) {
      ActiveMQRALogger.LOGGER.trace("createdBrowser " + session + " browser=" + result);
   }

   return result;
}
项目:activemq-artemis    文件:ActiveMQRASession.java   
/**
 * Create a browser
 *
 * @param queue           The queue
 * @param messageSelector The message selector
 * @return The browser
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueBrowser createBrowser(final Queue queue, final String messageSelector) throws JMSException {
   if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
      throw new IllegalStateException("Cannot create browser for javax.jms.TopicSession");
   }

   Session session = getSessionInternal();

   if (ActiveMQRASession.trace) {
      ActiveMQRALogger.LOGGER.trace("createBrowser " + session + " queue=" + queue + " selector=" + messageSelector);
   }

   QueueBrowser result = session.createBrowser(queue, messageSelector);

   if (ActiveMQRASession.trace) {
      ActiveMQRALogger.LOGGER.trace("createdBrowser " + session + " browser=" + result);
   }

   return result;
}
项目:netarchivesuite-svngit-migration    文件:IntegrityTestSuite.java   
/**
 * Checks that the QueueBrowser created by the <code>JMSConnectionMQ</code> class work correctly. 
 * @throws JMSException 
 * @throws InterruptedException 
 * @see JMSConnection#createQueueBrowser(ChannelID)
 */
public void testQueueBrowsing() throws JMSException, InterruptedException {
    QueueBrowser queueBrowser = conn.createQueueBrowser(Channels.getTheRepos());
    TestMessageConsumer mc = new TestMessageConsumer();
    conn.setListener(Channels.getTheRepos(), mc);        

    assertTrue("Empty queue had size > 0", queueBrowser.getEnumeration().hasMoreElements() == false);

    NetarkivetMessage nMsg = new TestMessage(Channels.getTheRepos(), Channels.getError(), "testQueueSendMessage");

    synchronized (mc) {
        conn.send(nMsg);
        assertTrue("Queue didn't have any messages after dispatching job", queueBrowser.getEnumeration().hasMoreElements() == true);
        mc.wait();
    }        

    assertEquals(
            "Arcrepos queue MessageConsumer should have received message.",
            nMsg.toString(), mc.nMsg.toString());

    assertTrue("Queue not empty after consumation of message", queueBrowser.getEnumeration().hasMoreElements() == false);
}
项目:RaspberryPiBeaconParser    文件:BrowseEvents.java   
static void browseEvents(Session session, Queue queue, long limit) throws JMSException {
   QueueBrowser browser = session.createBrowser(queue);
   Enumeration msgs = browser.getEnumeration();
   int count = 0;
   Message lastMsg = null;
   while(msgs.hasMoreElements()) {
      Message msg = (Message) msgs.nextElement();
      lastMsg = msg;
      displayProperties(msg);
      count ++;
      if(count > limit)
         break;
   }
   System.out.printf("Scanned count: %d, lastMsg=%s\n", count, lastMsg);
   browser.close();

}
项目:RaspberryPiBeaconParser    文件:PlotBatteryRSSI.java   
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;
}
项目:RaspberryPiBeaconParser    文件:TestJmsBridge.java   
@Test
public void testBrowseQueueForHeartbeats() throws Exception {
   Queue queue  = session.createQueue("beaconEvents");
   QueueBrowser browser = session.createBrowser(queue, "messageType = 1");
   Enumeration msgs = browser.getEnumeration();
   HashMap<String, Integer> heartbeatCounts = new HashMap<>();
   while(msgs.hasMoreElements()) {
      Message msg = (Message) msgs.nextElement();
      String scannerID = msg.getStringProperty("scannerID");
      Integer count = heartbeatCounts.get(scannerID);
      if(count == null) {
         count = 0;
      }
      heartbeatCounts.put(scannerID, count + 1);
   }
   System.out.printf("%s\n", heartbeatCounts);
}
项目:RaspberryPiBeaconParser    文件:TestJmsBridge.java   
@Test
public void testBrowseStatusQueue() throws Exception {
   Queue queue  = session.createQueue("scannerHealth");
   QueueBrowser browser = session.createBrowser(queue);
   Enumeration msgs = browser.getEnumeration();
   while(msgs.hasMoreElements()) {
      Message msg = (Message) msgs.nextElement();
      Enumeration names = msg.getPropertyNames();
      System.out.printf("Status: %s\n", msg.getJMSMessageID());
      while(names.hasMoreElements()) {
         String name = (String) names.nextElement();
         String value = msg.getStringProperty(name);
         System.out.printf("\t%s: %s\n", name, value);
      }
   }
}
项目:RaspberryPiBeaconParser    文件:DownloadScannerConfig.java   
/**
 * 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;
}
项目:class-guard    文件:JmsTemplate.java   
public <T> T browseSelected(final Queue queue, final String messageSelector, final BrowserCallback<T> action)
        throws JmsException {

    Assert.notNull(action, "Callback object must not be null");
    return execute(new SessionCallback<T>() {
        public T doInJms(Session session) throws JMSException {
            QueueBrowser browser = createBrowser(session, queue, messageSelector);
            try {
                return action.doInJms(session, browser);
            }
            finally {
                JmsUtils.closeQueueBrowser(browser);
            }
        }
    }, true);
}
项目:class-guard    文件:JmsTemplate.java   
public <T> T browseSelected(final String queueName, final String messageSelector, final BrowserCallback<T> action)
        throws JmsException {

    Assert.notNull(action, "Callback object must not be null");
    return execute(new SessionCallback<T>() {
        public T doInJms(Session session) throws JMSException {
            Queue queue = (Queue) getDestinationResolver().resolveDestinationName(session, queueName, false);
            QueueBrowser browser = createBrowser(session, queue, messageSelector);
            try {
                return action.doInJms(session, browser);
            }
            finally {
                JmsUtils.closeQueueBrowser(browser);
            }
        }
    }, true);
}
项目:ffmq    文件:LocalSession.java   
public QueueBrowser createBrowser(IntegerID browserId,Queue queueRef, String messageSelector) throws JMSException
  {
    externalAccessLock.readLock().lock();
    try
{
       checkNotClosed();
       LocalQueue localQueue = engine.getLocalQueue(queueRef.getQueueName());

       // Check temporary destinations scope (JMS Spec 4.4.3 p2)
       checkTemporaryDestinationScope(localQueue);

       LocalQueueBrowser browser = new LocalQueueBrowser(this,localQueue,messageSelector,browserId);
       registerBrowser(browser);
       return browser;
}
    finally
    {
        externalAccessLock.readLock().unlock();
    }
  }
项目:ffmq    文件:AbstractSession.java   
/**
 * 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);
        }
    }
}
项目:ffmq    文件:RemoteSession.java   
@Override
public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException
   {
    externalAccessLock.readLock().lock();
    try
    {
        checkNotClosed();
        RemoteQueueBrowser browser = new RemoteQueueBrowser(idProvider.createID(),
                                                            this,
                                                            queue,
                                                            messageSelector);
        registerBrowser(browser);
        browser.remoteInit();
        return browser;
    }
    finally
    {
        externalAccessLock.readLock().unlock();
    }
   }
项目:andes    文件:QueueBrowserAutoAckTest.java   
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());
    }
}
项目:qpid-jms    文件:QueueBrowserIntegrationTest.java   
@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);
    }
}
项目:qpid-jms    文件:JmsQueueBrowserTest.java   
@Test(timeout = 40000)
public void testCreateQueueBrowser() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(getDestinationName());
    session.createConsumer(queue).close();

    QueueBrowser browser = session.createBrowser(queue);
    assertNotNull(browser);

    QueueViewMBean proxy = getProxyToQueue(getDestinationName());
    assertEquals(0, proxy.getQueueSize());
}
项目:qpid-jms    文件:JmsQueueBrowserTest.java   
@Test(timeout = 40000)
public void testNoMessagesBrowserHasNoElements() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(getDestinationName());
    session.createConsumer(queue).close();

    QueueBrowser browser = session.createBrowser(queue);
    assertNotNull(browser);

    QueueViewMBean proxy = getProxyToQueue(getDestinationName());
    assertEquals(0, proxy.getQueueSize());

    Enumeration enumeration = browser.getEnumeration();
    assertFalse(enumeration.hasMoreElements());
}
项目:qpid-jms    文件:JmsQueueBrowserTest.java   
@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);
}
项目:qpid-jms    文件:JmsQueueBrowserTest.java   
@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);
}
项目:hawtjms    文件:JmsQueueBrowserTest.java   
@Test(timeout = 60000)
public void testCreateQueueBrowser() 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());
}
项目:hawtjms    文件:JmsQueueBrowserTest.java   
@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());
}
项目:hawtjms    文件:JmsQueueBrowserTest.java   
@Test(timeout = 60000)
public void testCreateQueueBrowser() 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());
}