當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerSession類代碼示例

本文整理匯總了Java中javax.jms.ServerSession的典型用法代碼示例。如果您正苦於以下問題:Java ServerSession類的具體用法?Java ServerSession怎麽用?Java ServerSession使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServerSession類屬於javax.jms包,在下文中一共展示了ServerSession類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dispatch

import javax.jms.ServerSession; //導入依賴的package包/類
public void dispatch(MessageDispatch messageDispatch) {
    try {
        messageDispatch.setConsumer(this);

        ServerSession serverSession = sessionPool.getServerSession();
        Session s = serverSession.getSession();
        ActiveMQSession session = null;

        if (s instanceof ActiveMQSession) {
            session = (ActiveMQSession)s;
        } else if (s instanceof ActiveMQTopicSession) {
            ActiveMQTopicSession topicSession = (ActiveMQTopicSession)s;
            session = (ActiveMQSession)topicSession.getNext();
        } else if (s instanceof ActiveMQQueueSession) {
            ActiveMQQueueSession queueSession = (ActiveMQQueueSession)s;
            session = (ActiveMQSession)queueSession.getNext();
        } else {
            connection.onClientInternalException(new JMSException("Session pool provided an invalid session type: " + s.getClass()));
            return;
        }

        session.dispatch(messageDispatch);
        serverSession.start();
    } catch (JMSException e) {
        connection.onAsyncException(e);
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:28,代碼來源:ActiveMQConnectionConsumer.java

示例2: getServerSession

import javax.jms.ServerSession; //導入依賴的package包/類
@Override
public ServerSession getServerSession() throws JMSException {
   synchronized (this) {
      if (serverSessionInUse) {
         LOG.info("asked for session while in use, not serialised delivery");
         success.set(false);
         completed.set(true);
      }
      serverSessionInUse = true;
      return serverSession;
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:13,代碼來源:OnePrefetchAsyncConsumerTest.java

示例3: testFailoverWithConnectionConsumer

import javax.jms.ServerSession; //導入依賴的package包/類
@Test
public void testFailoverWithConnectionConsumer() throws Exception {
   LOG.info(this + " running test testFailoverWithConnectionConsumer");
   startCleanBroker();
   ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")");
   configureConnectionFactory(cf);
   Connection connection = cf.createConnection();
   connection.start();
   final CountDownLatch connectionConsumerGotOne = new CountDownLatch(1);

   try {
      Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
      Queue destination = session.createQueue(QUEUE_NAME);

      final Session poolSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      connection.createConnectionConsumer(destination, null, new ServerSessionPool() {
         @Override
         public ServerSession getServerSession() throws JMSException {
            return new ServerSession() {
               @Override
               public Session getSession() throws JMSException {
                  return poolSession;
               }

               @Override
               public void start() throws JMSException {
                  connectionConsumerGotOne.countDown();
                  poolSession.run();
               }
            };
         }
      }, 1);

      MessageConsumer consumer = session.createConsumer(destination);
      MessageProducer producer;
      TextMessage message;
      final int count = 10;
      for (int i = 0; i < count; i++) {
         producer = session.createProducer(destination);
         message = session.createTextMessage("Test message: " + count);
         producer.send(message);
         producer.close();
      }

      // restart to force failover and connection state recovery before the commit
      broker.stop();
      startBroker();

      session.commit();
      for (int i = 0; i < count - 1; i++) {
         Message received = consumer.receive(20000);
         Assert.assertNotNull("Failed to get message: " + count, received);
      }
      session.commit();
   } finally {
      connection.close();
   }

   Assert.assertTrue("connectionconsumer did not get a message", connectionConsumerGotOne.await(10, TimeUnit.SECONDS));
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:61,代碼來源:FailoverTransactionTest.java


注:本文中的javax.jms.ServerSession類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。