3 Replies Latest reply on Dec 22, 2015 10:51 PM by Ben Han

    Starting an embedded server

    ansur Newbie

      I've been trying to start a vanilla Wildfly 10.0.0.CR2 in embedded mode, but rather than going through the jboss-cli.bat, through a separate java programme.

      This fails, see details below. Starting from jboss-cli.bat works fine. Browsing through the client-code I don't immediately see any other option which may be of interest to set, before calling the "embed-server" command.

       

      For now it's just two statements:

              final CommandContext context = CommandContextFactory.getInstance().newCommandContext();
              context.handle(String.format("embed-server --jboss-home=%s --std-out=echo", resolveRoot()));
      

       

      Immediately I get two warnings:

      WARN: can't find jboss-cli.xml. Using default configuration values.
      Cannot not load JBoss LogManager. The LogManager has likely been accessed prior to this initialization.
      

       

      C.f. the stacktrace below. While the error seems clear enough, I'm assuming I'm probably missing something in my caller code?

       

      2015-09-29 17:29:11,305 INFO  [org.jboss.msc] JBoss MSC version 1.2.6.Final
      2015-09-29 17:29:11,573 INFO  [org.jboss.as] WFLYSRV0049: WildFly Full 10.0.0.CR2 (WildFly Core 2.0.0.CR5) starting
      2015-09-29 17:29:12,973 ERROR [org.jboss.as.controller.management-operation] WFLYCTL0013: Operation ("parallel-extension-add") failed - address: ([])
      java.lang.RuntimeException: WFLYCTL0079: Failed initializing module org.jboss.as.logging
        at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:115)
        at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:877)
        at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:651)
        at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:362)
        at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1336)
        at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:458)
        at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:387)
        at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:349)
        at org.jboss.as.server.ServerService.boot(ServerService.java:392)
        at org.jboss.as.server.ServerService.boot(ServerService.java:365)
        at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:299)
        at java.lang.Thread.run(Thread.java:745)
      Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManager. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property "java.util.logging.manager" and set it to "org.jboss.logmanager.LogManager"
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:107)
        ... 11 more
      Caused by: java.lang.IllegalStateException: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManager. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property "java.util.logging.manager" and set it to "org.jboss.logmanager.LogManager"
        at org.jboss.as.logging.LoggingExtension.initialize(LoggingExtension.java:147)
        at org.jboss.as.controller.extension.ExtensionAddHandler.initializeExtension(ExtensionAddHandler.java:131)
        at org.jboss.as.controller.extension.ExtensionAddHandler.initializeExtension(ExtensionAddHandler.java:104)
        at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:144)
        at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:127)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        at org.jboss.threads.JBossThread.run(JBossThread.java:320)
      
        • 1. Re: Starting an embedded server
          James Perkins Master

          As the stack trace indicates you need to ensure the log manager is set correctly before attempt to launch the embedded server.

           

          That said if you're not opposed to a separate process there is a launcher API that will assist with setting up a new server process for you. Here's an example of how you'd use the launcher API.

          final StandaloneCommandBuilder commandBuilder = StandaloneCommandBuilder.of(Paths.get(System.getProperty("user.home"), "servers", "wildfly-10.0.0.CR2"));
          final Process process = Launcher.of(commandBuilder)
                  .inherit()
                  .launch();
          
          
          try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
              // Wait for start
              long timeout = 60000L;
              final long sleep = 100L;
              while (timeout > 0) {
                  long before = System.currentTimeMillis();
                  try {
                      final ModelNode response = client.execute(Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), "server-state"));
                      if (Operations.isSuccessfulOutcome(response)) {
                          final String state = Operations.readResult(response).asString();
                          if (!CONTROLLER_PROCESS_STATE_STARTING.equals(state)
                                  && !CONTROLLER_PROCESS_STATE_STOPPING.equals(state)) {
                              break;
                          }
                      }
                  } catch (RuntimeException | IOException e) {
                      Logger.getLogger("org.jboss.example").debug("Interrupted determining if standalone is running", e);
                  }
                  timeout -= (System.currentTimeMillis() - before);
                  if (ProcessHelper.processHasDied(process)) {
                      throw new RuntimeException("Process has died");
                  }
                  TimeUnit.MILLISECONDS.sleep(sleep);
                  timeout -= sleep;
              }
              
              // Execute an operation
              final ModelNode op = Operations.createOperation("read-resource");
              final ModelNode result = client.execute(op);
              if (Operations.isSuccessfulOutcome(result)) {
                  System.out.println(Operations.readResult(result));
                  client.execute(Operations.createOperation("shutdown"));
              } else {
                  throw new RuntimeException("Failed to list deployments: " + Operations.getFailureDescription(result).asString());
              }
          } finally {
              try {
                  process.waitFor(10, TimeUnit.SECONDS);
              } finally {
                  process.destroy();
              }
          }
          

          --

          James R. Perkins

          • 2. Re: Starting an embedded server
            ansur Newbie

            As could have been expected, setting the logmanager did the trick. While I has it set from the beginning, it was at a point in my code where it was too late - hence the "Cannot not load JBoss LogManager. The LogManager has likely been accessed prior to this initialization." error. Setting this system property really at the beginning of my programme resolved the issue.

            • 3. Re: Starting an embedded server
              Ben Han Newbie

              Hi, but how to set a new system property in your programme?

              Thanks.