@Override
 public void start() {
   if (STARTED.compareAndSet(false, true)) {
     try {
       final DomainCommandBuilder commandBuilder =
           DomainCommandBuilder.of(Environment.WILDFLY_HOME)
               .setBindAddressHint("management", Environment.HOSTNAME)
               .addHostControllerJavaOption("-Djboss.management.http.port=" + Environment.PORT);
       final Process process = Launcher.of(commandBuilder).setRedirectErrorStream(true).launch();
       startConsoleConsumer(process);
       shutdownThread = ProcessHelper.addShutdownHook(process);
       client =
           DomainClient.Factory.create(
               ModelControllerClient.Factory.create(Environment.HOSTNAME, Environment.PORT));
       currentProcess = process;
       final Map<ServerIdentity, ServerStatus> servers = new HashMap<>();
       ServerHelper.waitForDomain(process, client, servers, Environment.TIMEOUT);
       this.servers.putAll(servers);
     } catch (Throwable t) {
       try {
         throw new RuntimeException("Failed to start server", t);
       } finally {
         STARTED.set(false);
         cleanUp();
       }
     }
   }
 }
Ejemplo n.º 2
0
 static boolean waitForStandalone(
     final Process process, final ModelControllerClient client, final long startupTimeout)
     throws InterruptedException, IOException {
   long timeout = startupTimeout * 1000;
   final long sleep = 100L;
   while (timeout > 0) {
     long before = System.currentTimeMillis();
     if (isStandaloneRunning(client)) return true;
     timeout -= (System.currentTimeMillis() - before);
     if (ProcessHelper.processHasDied(process)) {
       return false;
     }
     TimeUnit.MILLISECONDS.sleep(sleep);
     timeout -= sleep;
   }
   return false;
 }
 private void cleanUp() {
   try {
     if (client != null)
       try {
         client.close();
       } catch (Exception ignore) {
       } finally {
         client = null;
       }
     try {
       ProcessHelper.destroyProcess(currentProcess);
     } catch (InterruptedException ignore) {
     }
   } finally {
     servers.clear();
     currentProcess = null;
   }
 }
Ejemplo n.º 4
0
 static boolean waitForDomain(
     final Process process,
     final DomainClient client,
     final Map<ServerIdentity, ServerStatus> servers,
     final long startupTimeout)
     throws InterruptedException, IOException {
   long timeout = startupTimeout * 1000;
   final long sleep = 100;
   while (timeout > 0) {
     long before = System.currentTimeMillis();
     if (isDomainRunning(client, servers)) {
       return true;
     }
     timeout -= (System.currentTimeMillis() - before);
     if (ProcessHelper.processHasDied(process)) {
       return false;
     }
     TimeUnit.MILLISECONDS.sleep(sleep);
     timeout -= sleep;
   }
   return false;
 }