Java Code Examples for org.apache.activemq.artemis.core.server.ActiveMQServer#isStarted()

The following examples show how to use org.apache.activemq.artemis.core.server.ActiveMQServer#isStarted() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void waitForServerToStart(ActiveMQServer server, boolean activation) throws InterruptedException {
   if (server == null)
      return;
   final long wait = 5000;
   long timetowait = System.currentTimeMillis() + wait;
   while (!server.isStarted() && System.currentTimeMillis() < timetowait) {
      Thread.sleep(50);
   }

   if (!server.isStarted()) {
      baseLog.info(threadDump("Server didn't start"));
      fail("server didn't start: " + server);
   }

   if (activation) {
      if (!server.getHAPolicy().isBackup()) {
         if (!server.waitForActivation(wait, TimeUnit.MILLISECONDS))
            fail("Server didn't initialize: " + server);
      }
   }
}
 
Example 2
Source File: IncompatibleVersionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void perform(String startedString) throws Exception {
   Configuration config = new ConfigurationImpl().setSecurityEnabled(false).addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY));
   ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, false);
   server.start();

   while (!server.isStarted()) {
      System.out.println("Still starting");
      Thread.sleep(100);
   }

   System.out.println(WORD_START);

   log.debug("### server: " + startedString);
}
 
Example 3
Source File: JMSUtil.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static void waitForServer(ActiveMQServer server) throws InterruptedException {
   long timetowait = System.currentTimeMillis() + 5000;
   while (!server.isStarted()) {
      Thread.sleep(100);
      if (server.isStarted()) {
         break;
      } else if (System.currentTimeMillis() > timetowait) {
         throw new IllegalStateException("server didn't start");
      }
   }
}
 
Example 4
Source File: MQTTSecurityCRLTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void crlNotRevokedTest() throws Exception {

   ActiveMQServer server1 = initServer();
   BlockingConnection connection1 = null;
   try {
      server1.start();

      while (!server1.isStarted()) {
         Thread.sleep(50);
      }

      connection1 = retrieveMQTTConnection("ssl://localhost:1883", "truststore.jks", "changeit", "client_not_revoked.jks", "changeit");

      // Subscribe to topics
      Topic[] topics = {new Topic("test/+/some/#", QoS.AT_MOST_ONCE)};
      connection1.subscribe(topics);

      // Publish Messages
      String payload1 = "This is message 1";

      connection1.publish("test/1/some/la", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);

      Message message1 = connection1.receive(5, TimeUnit.SECONDS);

      assertEquals(payload1, new String(message1.getPayload()));

   } finally {
      if (connection1 != null) {
         connection1.disconnect();
      }
      if (server1.isStarted()) {
         server1.stop();
      }
   }
}
 
Example 5
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void waitForServerToStop(ActiveMQServer server) throws InterruptedException {
   if (server == null)
      return;
   final long wait = 5000;
   long timetowait = System.currentTimeMillis() + wait;
   while (server.isStarted() && System.currentTimeMillis() < timetowait) {
      Thread.sleep(50);
   }

   if (server.isStarted()) {
      baseLog.info(threadDump("Server didn't start"));
      fail("Server didn't start: " + server);
   }
}
 
Example 6
Source File: ClusterTestBase.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void logTopologyDiagram() {
   try {
      StringBuffer topologyDiagram = new StringBuffer();
      for (ActiveMQServer activeMQServer : servers) {
         if (activeMQServer != null) {
            topologyDiagram.append("\n").append(activeMQServer.getIdentity()).append("\n");
            if (activeMQServer.isStarted()) {
               Set<ClusterConnection> ccs = activeMQServer.getClusterManager().getClusterConnections();

               if (ccs.size() >= 1) {
                  ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
                  Collection<TopologyMemberImpl> members = clusterConnection.getTopology().getMembers();
                  for (TopologyMemberImpl member : members) {
                     String nodeId = member.getNodeId();
                     String liveServer = null;
                     String backupServer = null;
                     for (ActiveMQServer server : servers) {
                        if (server != null && server.getNodeID() != null && server.isActive() && server.getNodeID().toString().equals(nodeId)) {
                           if (server.isActive()) {
                              liveServer = server.getIdentity();
                              if (member.getLive() != null) {
                                 liveServer += "(notified)";
                              } else {
                                 liveServer += "(not notified)";
                              }
                           } else {
                              backupServer = server.getIdentity();
                              if (member.getBackup() != null) {
                                 liveServer += "(notified)";
                              } else {
                                 liveServer += "(not notified)";
                              }
                           }
                        }
                     }

                     topologyDiagram.append("\t").append("|\n").append("\t->").append(liveServer).append("/").append(backupServer).append("\n");
                  }
               } else {
                  topologyDiagram.append("-> no cluster connections\n");
               }
            } else {
               topologyDiagram.append("-> stopped\n");
            }
         }
      }
      topologyDiagram.append("\n");
      log.debug(topologyDiagram.toString());
   } catch (Throwable e) {
      log.warn("error printing the topology::" + e.getMessage(), e);
   }
}