当前位置: 首页>>代码示例>>Java>>正文


Java ServerLocator.setConnectionTTL方法代码示例

本文整理汇总了Java中org.apache.activemq.artemis.api.core.client.ServerLocator.setConnectionTTL方法的典型用法代码示例。如果您正苦于以下问题:Java ServerLocator.setConnectionTTL方法的具体用法?Java ServerLocator.setConnectionTTL怎么用?Java ServerLocator.setConnectionTTL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.artemis.api.core.client.ServerLocator的用法示例。


在下文中一共展示了ServerLocator.setConnectionTTL方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
   try {
      CrashClient.log.debug("args = " + Arrays.asList(args));

      ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
      locator.setClientFailureCheckPeriod(ClientCrashTest.PING_PERIOD);
      locator.setConnectionTTL(ClientCrashTest.CONNECTION_TTL);
      ClientSessionFactory sf = locator.createSessionFactory();

      ClientSession session = sf.createSession(false, true, true);
      ClientProducer producer = session.createProducer(ClientCrashTest.QUEUE);

      // it has to be durable otherwise it may race dying before the client is killed
      ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 1);
      message.getBodyBuffer().writeString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);

      producer.send(message);

      // exit without closing the session properly
      System.exit(9);
   } catch (Throwable t) {
      CrashClient.log.error(t.getMessage(), t);
      System.exit(1);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:CrashClient.java

示例2: main

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
   try {
      log.debug("args = " + Arrays.asList(args));

      ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
      locator.setClientFailureCheckPeriod(ClientCrashTest.PING_PERIOD);
      locator.setConnectionTTL(ClientCrashTest.CONNECTION_TTL);
      ClientSessionFactory sf = locator.createSessionFactory();

      ClientSession session = sf.createSession(true, true, 1000000);
      ClientProducer producer = session.createProducer(ClientCrashTest.QUEUE2);

      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);

      producer.send(message);

      //Now consume the message, but don't let ack get to server

      //Consume the message
      ClientConsumer cons = session.createConsumer(ClientCrashTest.QUEUE2);

      session.start();

      ClientMessage msg = cons.receive(10000);

      if (msg == null) {
         log.error("Didn't receive msg");

         System.exit(1);
      }

      // exit without closing the session properly
      System.exit(9);
   } catch (Throwable t) {
      log.error(t.getMessage(), t);
      System.exit(1);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:40,代码来源:CrashClient2.java

示例3: testServerFailureNoPing

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testServerFailureNoPing() throws Exception {
   TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
   ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
   locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD);
   locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2);
   ClientSessionFactoryImpl csf = (ClientSessionFactoryImpl) createSessionFactory(locator);

   Listener clientListener = new Listener();

   ClientSession session = csf.createSession(false, true, true);

   Assert.assertEquals(1, csf.numConnections());

   session.addFailureListener(clientListener);

   // We need to get it to stop pinging after one

   csf.stopPingingAfterOne();

   RemotingConnection serverConn = null;

   while (serverConn == null) {
      Set<RemotingConnection> conns = server.getRemotingService().getConnections();

      if (!conns.isEmpty()) {
         serverConn = server.getRemotingService().getConnections().iterator().next();
      } else {
         // It's async so need to wait a while
         Thread.sleep(10);
      }
   }

   Listener serverListener = new Listener();

   serverConn.addFailureListener(serverListener);

   for (int i = 0; i < 1000; i++) {
      // a few tries to avoid a possible race caused by GCs or similar issues
      if (server.getRemotingService().getConnections().isEmpty() && clientListener.getException() != null) {
         break;
      }

      Thread.sleep(10);
   }

   if (!server.getRemotingService().getConnections().isEmpty()) {
      RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();

      PingTest.log.info("Serverconn2 is " + serverConn2);
   }

   Assert.assertTrue(server.getRemotingService().getConnections().isEmpty());

   // The client listener should be called too since the server will close it from the server side which will result
   // in the
   // netty detecting closure on the client side and then calling failure listener
   Assert.assertNotNull(clientListener.getException());

   Assert.assertNotNull(serverListener.getException());

   session.close();

   csf.close();

   locator.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:68,代码来源:PingTest.java

示例4: testDeleteTemporaryQueueWhenClientCrash

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testDeleteTemporaryQueueWhenClientCrash() throws Exception {
   session.close();
   sf.close();

   final SimpleString queue = RandomUtil.randomSimpleString();
   SimpleString address = RandomUtil.randomSimpleString();

   // server must received at least one ping from the client to pass
   // so that the server connection TTL is configured with the client value
   final CountDownLatch pingOnServerLatch = new CountDownLatch(1);
   server.getRemotingService().addIncomingInterceptor(new Interceptor() {

      @Override
      public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
         if (packet.getType() == PacketImpl.PING) {
            pingOnServerLatch.countDown();
         }
         return true;
      }
   });

   ServerLocator locator = createInVMNonHALocator();
   locator.setConnectionTTL(TemporaryQueueTest.CONNECTION_TTL);
   sf = addSessionFactory(createSessionFactory(locator));
   session = sf.createSession(false, true, true);

   session.createTemporaryQueue(address, queue);
   assertTrue("server has not received any ping from the client", pingOnServerLatch.await(2 * server.getConfiguration().getConnectionTtlCheckInterval(), TimeUnit.MILLISECONDS));
   assertEquals(1, server.getConnectionCount());

   RemotingConnection remotingConnection = server.getRemotingService().getConnections().iterator().next();
   final CountDownLatch serverCloseLatch = new CountDownLatch(1);
   remotingConnection.addCloseListener(new CloseListener() {
      @Override
      public void connectionClosed() {
         serverCloseLatch.countDown();
      }
   });

   ((ClientSessionInternal) session).getConnection().fail(new ActiveMQInternalErrorException("simulate a client failure"));

   // let some time for the server to clean the connections
   assertTrue("server has not closed the connection", serverCloseLatch.await(2 * server.getConfiguration().getConnectionTtlCheckInterval() + 2 * TemporaryQueueTest.CONNECTION_TTL, TimeUnit.MILLISECONDS));

   // The next getCount will be asynchronously done at the end of failure. We will wait some time until it has reached there.
   for (long timeout = System.currentTimeMillis() + 5000; timeout > System.currentTimeMillis() && server.getConnectionCount() > 0; ) {
      Thread.sleep(1);
   }

   assertEquals(0, server.getConnectionCount());

   session.close();

   sf.close();
   ServerLocator locator2 = createInVMNonHALocator();

   sf = addSessionFactory(createSessionFactory(locator2));
   session = sf.createSession(false, true, true);
   session.start();

   ActiveMQAction activeMQAction = new ActiveMQAction() {
      @Override
      public void run() throws ActiveMQException {
         session.createConsumer(queue);
      }
   };

   ActiveMQTestBase.expectActiveMQException("temp queue must not exist after the server detected the client crash", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, activeMQAction);

   session.close();

   locator2.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:75,代码来源:TemporaryQueueTest.java

示例5: testNoFailureWithPinging

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testNoFailureWithPinging() throws Exception {
   ServerLocator locator = createNettyNonHALocator();

   locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD);
   locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2);

   ClientSessionFactory csf = createSessionFactory(locator);

   ClientSession session = csf.createSession(false, true, true);

   PingTest.log.info("Created session");

   Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());

   Listener clientListener = new Listener();

   session.addFailureListener(clientListener);

   RemotingConnection serverConn = null;
   while (serverConn == null) {
      Set<RemotingConnection> conns = server.getRemotingService().getConnections();

      if (!conns.isEmpty()) {
         serverConn = server.getRemotingService().getConnections().iterator().next();
      } else {
         // It's async so need to wait a while
         Thread.sleep(10);
      }
   }

   Listener serverListener = new Listener();

   serverConn.addFailureListener(serverListener);

   Thread.sleep(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 10);

   Assert.assertNull(clientListener.getException());

   Assert.assertNull(serverListener.getException());

   RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();

   PingTest.log.info("Server conn2 is " + serverConn2);

   Assert.assertTrue(serverConn == serverConn2);

   session.close();

   csf.close();

   locator.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:54,代码来源:PingTest.java

示例6: testNoFailureNoPinging

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testNoFailureNoPinging() throws Exception {
   TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
   ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
   locator.setClientFailureCheckPeriod(-1);
   locator.setConnectionTTL(-1);
   ClientSessionFactory csf = createSessionFactory(locator);

   ClientSession session = csf.createSession(false, true, true);

   Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());

   Listener clientListener = new Listener();

   session.addFailureListener(clientListener);

   RemotingConnection serverConn = null;
   while (serverConn == null) {
      Set<RemotingConnection> conns = server.getRemotingService().getConnections();

      if (!conns.isEmpty()) {
         serverConn = server.getRemotingService().getConnections().iterator().next();
      } else {
         // It's async so need to wait a while
         Thread.sleep(10);
      }
   }

   Listener serverListener = new Listener();

   serverConn.addFailureListener(serverListener);

   Thread.sleep(ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD);

   Assert.assertNull(clientListener.getException());

   Assert.assertNull(serverListener.getException());

   RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();

   PingTest.log.info("Serverconn2 is " + serverConn2);

   Assert.assertTrue(serverConn == serverConn2);

   session.close();

   csf.close();

   locator.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:51,代码来源:PingTest.java


注:本文中的org.apache.activemq.artemis.api.core.client.ServerLocator.setConnectionTTL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。