コード例 #1
0
ファイル: Main.java プロジェクト: jwulf/jboss-as
  /**
   * The main method.
   *
   * @param args the command-line arguments
   */
  public static void main(String[] args) {

    // Grab copies of our streams.
    final InputStream in = System.in;
    final PrintStream out = System.out;
    final PrintStream err = System.err;

    // Install JBoss Stdio to avoid any nasty crosstalk.
    StdioContext.install();
    final StdioContext context =
        StdioContext.create(
            new NullInputStream(),
            new LoggingOutputStream(Logger.getLogger("stdout"), Level.INFO),
            new LoggingOutputStream(Logger.getLogger("stderr"), Level.ERROR));
    StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));

    create(args, in, out, err);
  }
コード例 #2
0
    private void exit() {

      if (serviceContainer != null) {
        try {
          serviceContainer.shutdown();

          serviceContainer.awaitTermination();
        } catch (RuntimeException rte) {
          throw rte;
        } catch (InterruptedException ite) {
          ite.printStackTrace();
          Thread.currentThread().interrupt();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
      if (controlledProcessStateService != null) {
        controlledProcessStateService.removePropertyChangeListener(processStateListener);
        controlledProcessStateService = null;
      }
      if (executorService != null) {
        try {
          executorService.shutdown();

          // 10 secs is arbitrary, but if the service container is terminated,
          // no good can happen from waiting for ModelControllerClient requests to complete
          executorService.awaitTermination(10, TimeUnit.SECONDS);
        } catch (RuntimeException rte) {
          throw rte;
        } catch (InterruptedException ite) {
          ite.printStackTrace();
          Thread.currentThread().interrupt();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }

      if (uninstallStdIo) {
        try {
          StdioContext.uninstall();
        } catch (IllegalStateException ignored) {
          // something else already did
        }
      }

      SystemExiter.initialize(SystemExiter.Exiter.DEFAULT);
    }
コード例 #3
0
    @Override
    public void start() throws ServerStartException {

      try {

        // Take control of server use of System.exit
        SystemExiter.initialize(
            new SystemExiter.Exiter() {
              @Override
              public void exit(int status) {
                StandaloneServerImpl.this.exit();
              }
            });

        // Take control of stdio
        try {
          StdioContext.install();
          uninstallStdIo = true;
        } catch (IllegalStateException ignored) {
          // already installed
        }

        // Determine the ServerEnvironment
        ServerEnvironment serverEnvironment =
            Main.determineEnvironment(
                cmdargs, systemProps, systemEnv, ServerEnvironment.LaunchType.EMBEDDED);

        Bootstrap bootstrap = Bootstrap.Factory.newInstance();

        Bootstrap.Configuration configuration = new Bootstrap.Configuration(serverEnvironment);

        /*
         * This would setup an {@link TransientConfigurationPersister} which does not persist anything
         *
        final ExtensionRegistry extensionRegistry = configuration.getExtensionRegistry();
        final Bootstrap.ConfigurationPersisterFactory configurationPersisterFactory = new Bootstrap.ConfigurationPersisterFactory() {
            @Override
            public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
                final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "server");
                final StandaloneXml parser = new StandaloneXml(Module.getBootModuleLoader(), executorService, extensionRegistry);
                final File configurationFile = serverEnvironment.getServerConfigurationFile().getBootFile();
                XmlConfigurationPersister persister = new TransientConfigurationPersister(configurationFile, rootElement, parser, parser);
                for (Namespace namespace : Namespace.domainValues()) {
                    if (!namespace.equals(Namespace.CURRENT)) {
                        persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "server"), parser);
                    }
                }
                extensionRegistry.setWriterRegistry(persister);
                return persister;
            }
        };
        configuration.setConfigurationPersisterFactory(configurationPersisterFactory);
        */

        configuration.setModuleLoader(moduleLoader);

        Future<ServiceContainer> future =
            bootstrap.startup(configuration, Collections.<ServiceActivator>emptyList());

        serviceContainer = future.get();

        executorService = Executors.newCachedThreadPool();

        @SuppressWarnings("unchecked")
        final Value<ControlledProcessStateService> processStateServiceValue =
            (Value<ControlledProcessStateService>)
                serviceContainer.getRequiredService(ControlledProcessStateService.SERVICE_NAME);
        controlledProcessStateService = processStateServiceValue.getValue();
        controlledProcessStateService.addPropertyChangeListener(processStateListener);
        establishModelControllerClient(controlledProcessStateService.getCurrentState());

      } catch (RuntimeException rte) {
        throw rte;
      } catch (Exception ex) {
        throw EmbeddedLogger.ROOT_LOGGER.cannotStartEmbeddedServer(ex);
      }
    }