Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.host.controller;
 
 import static java.security.AccessController.doPrivileged;
 import static org.jboss.as.server.ServerLogger.AS_ROOT_LOGGER;
 import static org.jboss.as.server.ServerLogger.CONFIG_LOGGER;
 
 import java.util.List;
 import java.util.Map;
 
The root service for a HostController process.

Author(s):
Brian Stansberry (c) 2011 Red Hat Inc.
 
 public class HostControllerService implements Service<AsyncFuture<ServiceContainer>> {
 
     public static final ServiceName HC_SERVICE_NAME = ..append("host""controller");
     public static final ServiceName HC_EXECUTOR_SERVICE_NAME = .append("executor");
     static final int DEFAULT_POOL_SIZE = 20;
 
     private final HostControllerEnvironment environment;
     private final HostRunningModeControl runningModeControl;
     private final ControlledProcessState processState;
     private final byte[] authCode;
     private volatile FutureServiceContainer futureContainer;
     private volatile long startTime;
 
     HostControllerService(final HostControllerEnvironment environmentfinal HostRunningModeControl runningModeControl,
                           final byte[] authCodefinal ControlledProcessState processState) {
         this. = environment;
         this. = runningModeControl;
         this. = authCode;
         this. = processState;
         this. = Module.getStartTime();
     }
 
     @Override
     public void start(StartContext contextthrows StartException {
 
         .setStarting();
 
         final ProductConfig config = .getProductConfig();
         final String prettyVersion = config.getPrettyVersionString();
         .serverStarting(prettyVersion);
         if (.isDebugEnabled()) {
            final Properties properties = System.getProperties();
            final StringBuilder b = new StringBuilder(8192);
            b.append("Configured system properties:");
            for (String property : new TreeSet<String>(properties.stringPropertyNames())) {
                b.append("\n\t").append(property).append(" = ").append(properties.getProperty(property"<undefined>"));
            }
            .debug(b);
            .debugf("VM Arguments: %s"getVMArguments());
            if (.isTraceEnabled()) {
                b.setLength(0);
                final Map<StringStringenv = System.getenv();
                b.append("Configured system environment:");
                for (String key : new TreeSet<String>(env.keySet())) {
                    b.append("\n\t").append(key).append(" = ").append(env.get(key));
                }
                .trace(b);
            }
        }
        final ServiceTarget serviceTarget = context.getChildTarget();
        final ServiceController<?> myController = context.getController();
        final ServiceContainer serviceContainer = myController.getServiceContainer();
         = new FutureServiceContainer();
        long startTime = this.;
        if (startTime == -1) {
            startTime = System.currentTimeMillis();
        } else {
            this. = -1;
        }
        final BootstrapListener bootstrapListener = new BootstrapListener(serviceContainerstartTimeserviceTarget,  prettyVersion + " (Host Controller)");
        bootstrapListener.getStabilityMonitor().addController(myController);
        // The first default services are registered before the bootstrap operations are executed.
        // Install the process controller client
        final ProcessControllerConnectionService processControllerClient = new ProcessControllerConnectionService();
        serviceTarget.addService(.processControllerClient).install();
        // Executor Services
        final HostControllerExecutorService executorService = new HostControllerExecutorService();
        serviceTarget.addService(executorService)
                .addAliases(.// Use this executor for mgmt shutdown for now
                .install();
        // Install required path services. (Only install those identified as required)
        HostPathManagerService hostPathManagerService = new HostPathManagerService();
        HostPathManagerService.addService(serviceTargethostPathManagerService);
        HttpListenerRegistryService.install(serviceTarget);
        // Add product config service
        final Value<ProductConfigproductConfigValue = new ImmediateValue<ProductConfig>(config);
        serviceTarget.addService(.new ValueService<ProductConfig>(productConfigValue))
                .setInitialMode(..)
                .install();
        DomainModelControllerService.addService(serviceTargetbootstrapListenerhostPathManagerService);
    }
    @Override
    public void stop(StopContext context) {
        String prettyVersion = .getProductConfig().getPrettyVersionString();
        .setStopping();
        .serverStopped(prettyVersion, Integer.valueOf((int) (context.getElapsedTime() / 1000000L)));
    }
    @Override
        return ;
    }
        return ;
    }
    private String getVMArguments() {
        final StringBuilder result = new StringBuilder(1024);
        final RuntimeMXBean rmBean = ManagementFactory.getRuntimeMXBean();
        final List<StringinputArguments = rmBean.getInputArguments();
        for (String arg : inputArguments) {
            result.append(arg).append(" ");
        }
        return result.toString();
    }
    static final class HostControllerExecutorService implements Service<ExecutorService> {
        final ThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("Host Controller Service Threads"), .null"%G - %t"nullnulldoPrivileged(GetAccessControlContextAction.getInstance()));
        private ExecutorService executorService;
        @Override
        public synchronized void start(final StartContext contextthrows StartException {
             = new ThreadPoolExecutor(0, .,
                    5L, .,
                    new SynchronousQueue<Runnable>(),
                    );
        }
        @Override
        public synchronized void stop(final StopContext context) {
            Thread executorShutdown = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        .shutdown();
                    } finally {
                         = null;
                        context.complete();
                    }
                }
            }, "HostController ExecutorService Shutdown Thread");
            executorShutdown.start();
            context.asynchronous();
        }
        @Override
        public synchronized ExecutorService getValue() throws IllegalStateException {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X