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


Java ServerLocator.addClusterTopologyListener方法代码示例

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


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

示例1: createConnectionAndWaitForTopology

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static ActiveMQConnection createConnectionAndWaitForTopology(ActiveMQConnectionFactory factory,
                                                                    int topologyMembers,
                                                                    int timeout) throws Exception {
   ActiveMQConnection conn;
   CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);

   ServerLocator locator = factory.getServerLocator();

   locator.addClusterTopologyListener(new FailoverTestBase.LatchClusterTopologyListener(countDownLatch));

   conn = (ActiveMQConnection) factory.createConnection();

   boolean ok = countDownLatch.await(timeout, TimeUnit.SECONDS);
   if (!ok) {
      throw new IllegalStateException("timed out waiting for topology");
   }
   return conn;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:19,代码来源:JMSUtil.java

示例2: createSessionFactoryAndWaitForTopology

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
protected ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator,
                                                                              int topologyMembers,
                                                                              ActiveMQServer server) throws Exception {
   ClientSessionFactoryInternal sf;
   CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);

   FailoverTestBase.LatchClusterTopologyListener topListener = new FailoverTestBase.LatchClusterTopologyListener(countDownLatch);
   locator.addClusterTopologyListener(topListener);

   sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
   addSessionFactory(sf);

   boolean ok = countDownLatch.await(5, TimeUnit.SECONDS);
   locator.removeClusterTopologyListener(topListener);
   if (!ok) {
      if (server != null) {
         log.info("failed topology, Topology on server = " + server.getClusterManager().describe());
      }
   }
   Assert.assertTrue("expected " + topologyMembers + " members", ok);
   return sf;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:23,代码来源:MultipleBackupsFailoverTestBase.java

示例3: createSessionFactoryAndWaitForTopology

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
protected final ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator,
                                                                                    TransportConfiguration transportConfiguration,
                                                                                    int topologyMembers) throws Exception {
   CountDownLatch countDownLatch = new CountDownLatch(topologyMembers * 2);

   locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));

   ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory(transportConfiguration);
   addSessionFactory(sf);

   assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));

   closeSessionFactory(sf);

   sf = (ClientSessionFactoryInternal) locator.createSessionFactory(liveServer.getServer().getNodeID().toString());
   addSessionFactory(sf);

   if (sf2 == null) {
      sf2 = (ClientSessionFactoryInternal) locator.createSessionFactory(backupServer.getServer().getNodeID().toString());

      ClientSession session2 = createSession(sf2, false, false);
      session2.createQueue(ADDRESS, ADDRESS, null, true);
      addSessionFactory(sf2);
   }
   return sf;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:27,代码来源:LiveToLiveFailoverTest.java

示例4: createSessionFactoryAndWaitForTopology

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
protected ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator,
                                                                              int topologyMembers) throws Exception {
   CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);

   locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));

   ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
   addSessionFactory(sf);

   Assert.assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
   return sf;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:FailoverTestBase.java

示例5: testReceiveNotifications

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testReceiveNotifications() throws Throwable {
   startServers(0, 1, 2, 3, 4);
   String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);

   ServerLocator locator = createHAServerLocator();

   waitForClusterConnections(0, 4);
   waitForClusterConnections(1, 4);
   waitForClusterConnections(2, 4);
   waitForClusterConnections(3, 4);
   waitForClusterConnections(4, 4);

   final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
   final CountDownLatch upLatch = new CountDownLatch(5);
   final CountDownLatch downLatch = new CountDownLatch(4);

   locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, downLatch));

   ClientSessionFactory sf = createSessionFactory(locator);

   Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
   checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes);

   ClientSession session = sf.createSession();

   stopServers(0);
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1, 2, 3, 4}, nodeIDs, nodes);

   stopServers(2);
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1, 3, 4}, nodeIDs, nodes);

   stopServers(4);
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1, 3}, nodeIDs, nodes);

   stopServers(3);
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1}, nodeIDs, nodes);

   stopServers(1);

   Assert.assertTrue("Was not notified that all servers are DOWN", downLatch.await(10, SECONDS));
   checkContains(new int[]{}, nodeIDs, nodes);

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

示例6: testStopNodes

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testStopNodes() throws Throwable {
   startServers(0, 1, 2, 3, 4);
   String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);

   ServerLocator locator = createHAServerLocator();

   waitForClusterConnections(0, 4);
   waitForClusterConnections(1, 4);
   waitForClusterConnections(2, 4);
   waitForClusterConnections(3, 4);
   waitForClusterConnections(4, 4);

   final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
   final CountDownLatch upLatch = new CountDownLatch(5);

   locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, new CountDownLatch(0)));
   ClientSessionFactory sf = createSessionFactory(locator);

   Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
   checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes);

   ClientSession session = sf.createSession();

   stopServers(0);
   Assert.assertFalse(servers[0].isStarted());
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1, 2, 3, 4}, nodeIDs, nodes);

   stopServers(2);
   Assert.assertFalse(servers[2].isStarted());
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1, 3, 4}, nodeIDs, nodes);

   stopServers(4);
   Assert.assertFalse(servers[4].isStarted());
   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1, 3}, nodeIDs, nodes);

   stopServers(3);
   Assert.assertFalse(servers[3].isStarted());

   session = checkSessionOrReconnect(session, locator);
   checkContains(new int[]{1}, nodeIDs, nodes);

   stopServers(1);
   Assert.assertFalse(servers[1].isStarted());
   try {
      session = checkSessionOrReconnect(session, locator);
      Assert.fail();
   } catch (ActiveMQException expected) {
      Assert.assertEquals(ActiveMQExceptionType.NOT_CONNECTED, expected.getType());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:55,代码来源:TopologyClusterTestBase.java

示例7: testMultipleClientSessionFactories

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testMultipleClientSessionFactories() throws Throwable {
   startServers(0, 1, 2, 3, 4);
   String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);

   ServerLocator locator = createHAServerLocator();

   waitForClusterConnections(0, 4);
   waitForClusterConnections(1, 4);
   waitForClusterConnections(2, 4);
   waitForClusterConnections(3, 4);
   waitForClusterConnections(4, 4);

   final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
   final CountDownLatch upLatch = new CountDownLatch(5);
   final CountDownLatch downLatch = new CountDownLatch(4);

   locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, downLatch));

   ClientSessionFactory[] sfs = new ClientSessionFactory[]{locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory()};
   Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
   checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes);

   // we can't close all of the servers, we need to leave one up to notify us
   stopServers(4, 2, 3, 1);

   boolean ok = downLatch.await(10, SECONDS);
   if (!ok) {
      log.warn("TopologyClusterTestBase.testMultipleClientSessionFactories will fail");
   }
   Assert.assertTrue("Was not notified that all servers are Down", ok);
   checkContains(new int[]{0}, nodeIDs, nodes);

   for (ClientSessionFactory sf : sfs) {
      sf.close();
   }

   locator.close();

   stopServers(0);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:42,代码来源:TopologyClusterTestBase.java

示例8: testReceiveNotificationsWhenOtherNodesAreStartedAndStopped

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testReceiveNotificationsWhenOtherNodesAreStartedAndStopped() throws Throwable {
   startServers(0);

   ServerLocator locator = createHAServerLocator();

   locator.getTopology().setOwner("testReceive");

   final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
   final CountDownLatch upLatch = new CountDownLatch(5);
   final CountDownLatch downLatch = new CountDownLatch(4);

   locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, downLatch));

   ClientSessionFactory sf = createSessionFactory(locator);

   startServers(1, 4, 3, 2);
   String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);

   Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
   checkContains(new int[]{0, 1, 4, 3, 2}, nodeIDs, nodes);

   waitForClusterConnections(0, 4);
   waitForClusterConnections(1, 4);
   waitForClusterConnections(2, 4);
   waitForClusterConnections(3, 4);
   waitForClusterConnections(4, 4);

   stopServers(2, 3, 1, 4);

   Assert.assertTrue("Was not notified that all servers are DOWN", downLatch.await(10, SECONDS));
   checkContains(new int[]{0}, nodeIDs, nodes);

   sf.close();

   locator.close();

   stopServers(0);

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:41,代码来源:TopologyClusterTestBase.java


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