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 org.jboss.as.host.controller.HostControllerLogger.ROOT_LOGGER;
 
 
Service providing the ServerInventory

Author(s):
Emanuel Muckenhuber
David M. Lloyd
 
 
     static final ServiceName SERVICE_NAME = ..append("host""controller""server-inventory");
 
     private final DomainController domainController;
     private final HostControllerEnvironment environment;
     private final HostRunningModeControl runningModeControl;
     private final ExtensionRegistry extensionRegistry;
     private final int port;
 
     private final FutureServerInventory futureInventory = new FutureServerInventory();
 
 
     private ServerInventoryService(final DomainController domainControllerfinal HostRunningModeControl runningModeControl,
                                    final HostControllerEnvironment environmentfinal ExtensionRegistry extensionRegistryfinal int port) {
         this. = extensionRegistry;
         this. = domainController;
         this. = runningModeControl;
         this. = environment;
         this. = port;
     }
 
     static Future<ServerInventoryinstall(final ServiceTarget serviceTargetfinal DomainController domainControllerfinal HostRunningModeControl runningModeControlfinal HostControllerEnvironment environment,
                                            final ExtensionRegistry extensionRegistry,
                                            final String interfaceBindingfinal int port){
 
         final ServerInventoryService inventory = new ServerInventoryService(domainControllerrunningModeControlenvironmentextensionRegistryport);
         serviceTarget.addService(.inventory)
                 .addDependency(.ExecutorService.classinventory.executorService)
                 .addDependency(..append(interfaceBinding), NetworkInterfaceBinding.classinventory.interfaceBinding)
                 .addDependency(.ServerInventoryCallbackService.classinventory.serverCallback)
                 .install();
         return inventory.futureInventory;
     }

    
 
     @Override
     public synchronized void start(StartContext contextthrows StartException {
         .debug("Starting Host Controller Server Inventory");
         try {
             final ProcessControllerConnectionService processControllerConnectionService = .getValue();
            final InetSocketAddress binding = new InetSocketAddress(.getValue().getAddress(), );
             = new ServerInventoryImpl(bindingprocessControllerConnectionService.getClient(), );
            processControllerConnectionService.setServerInventory();
        } catch (Exception e) {
            .setFailure(e);
            throw new StartException(e);
        }
    }

    
Stops all servers.
    @Override
    public synchronized void stop(final StopContext context) {
        final boolean shutdownServers = .getRestartMode() == .;
        if (shutdownServers) {
            Runnable task = new Runnable() {
                @Override
                public void run() {
                    try {
                        .shutdown(true, -1, true); // TODO graceful shutdown
                         = null;
                        // client.getValue().setServerInventory(null);
                    } finally {
                        .getValue().setCallbackHandler(null);
                        context.complete();
                    }
                }
            };
            try {
                .getValue().execute(task);
            } catch (RejectedExecutionException e) {
                task.run();
            } finally {
                context.asynchronous();
            }
        } else {
            // We have to set the shutdown flag in any case
            .shutdown(false, -1, true);
             = null;
        }
    }

    
    @Override
    public synchronized ServerInventory getValue() throws IllegalStateExceptionIllegalArgumentException {
        final ServerInventory serverInventory = this.;
        if(serverInventory == null) {
            throw new IllegalStateException();
        }
        return serverInventory;
    }
        return ;
    }
    private class FutureServerInventory extends AsyncFutureTask<ServerInventory>{
        protected FutureServerInventory() {
            super(null);
        }
        private void setInventory(ServerInventory inventory) {
            super.setResult(inventory);
        }
        private void setFailure(final Throwable t) {
            super.setFailed(t);
        }
    }
New to GrepCode? Check out our FAQ X