Пример #1
0
 private void waitForSpringApplication(long wait, int maxAttempts) throws MojoExecutionException {
   SpringApplicationAdminClient client =
       new SpringApplicationAdminClient(ManagementFactory.getPlatformMBeanServer(), this.jmxName);
   getLog().debug("Waiting for spring application to start...");
   for (int i = 0; i < maxAttempts; i++) {
     if (client.isReady()) {
       return;
     }
     String message =
         "Spring application is not ready yet, waiting " + wait + "ms (attempt " + (i + 1) + ")";
     getLog().debug(message);
     synchronized (this.lock) {
       try {
         this.lock.wait(wait);
       } catch (InterruptedException ex) {
         Thread.currentThread().interrupt();
         throw new IllegalStateException(
             "Interrupted while waiting for Spring Boot app to start.");
       }
     }
   }
   throw new MojoExecutionException(
       "Spring application did not start before the configured timeout ("
           + (wait * maxAttempts)
           + "ms");
 }
Пример #2
0
 @Override
 public JMXConnector call() throws Exception {
   try {
     return SpringApplicationAdminClient.connect(this.port);
   } catch (IOException ex) {
     if (hasCauseWithType(ex, ConnectException.class)) {
       String message = "MBean server at port " + this.port + " is not up yet...";
       getLog().debug(message);
       return null;
     }
     throw ex;
   }
 }