当前位置: 首页>>代码示例>>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;未经允许,请勿转载。