FileDocCategorySizeDatePackage
OnDemandServer.javaAPI DocGlassfish v2 API8755Thu Jun 21 10:40:36 BST 2007com.sun.enterprise.server.ondemand

OnDemandServer

public class OnDemandServer extends ApplicationServer implements EntryPoint
Represents on-demand server. This is the main class that ties ondemand logic with rest of the application server.

Fields Summary
private static boolean
onDemandStartup
private static volatile ServerEntryListener
listener
private static volatile SystemAppLoader
systemAppLoader
private volatile ServiceGroup
sg
Constructors Summary
Methods Summary
public voidgenerateEntryContext(java.lang.Object event)

        ServerEntryHelper.generateStartUpEntryContext((Boolean) event);
    
public static ServerEntryListenergetServerEntryListener()

        return listener;
    
public ServiceGroupgetServiceGroup()

        return sg;
    
public static SystemAppLoadergetSystemAppLoader()

        return systemAppLoader;
    
protected java.util.ListinstantiateRuntimeServices(ServerContext serverContext, java.lang.String[][] defaultServices)

        if (onDemandStartup) {
            InternalServicesList services = serverContext.getPluggableFeatureFactory().getInternalServicesList();
            final InternalServicesList ondemandservices = new OnDemandServices();
            final String[][] servicesByName = services.getServicesByName();
            final String[][] odsByName = ondemandservices.getServicesByName();
            if (servicesByName == null) {
               _logger.log(Level.SEVERE, "services.null");
               throw new ServerLifecycleException();
            }

            final List<ServerLifecycle> serviceList = new ArrayList<ServerLifecycle>();

            // Instantiate service objects
            allServices :
            for (final String[] service : servicesByName) {
               for (final String[] ods : odsByName) {
                    if (service[0].equals(ods[0])) {
                        continue allServices;
                    }
               }
               try {
                   final ServerLifecycle serverLifecycle =
                    super.instantiateOneServerLifecycle( serverContext, service[1] );
                   serviceList.add( serverLifecycle );
               } catch (Exception ex) {
                   _logger.log(Level.SEVERE, "server.exception", ex);
                   throw new ServerLifecycleException(ex.getMessage());
               }
            }
            return serviceList;
        } else {
            return super.instantiateRuntimeServices( serverContext, defaultServices);
        }
    
public static booleanisOnDemandOff()

        return onDemandStartup == false;
    
public static java.nio.channels.SelectionKeykeyFor(java.nio.channels.SelectableChannel channel, java.nio.channels.Selector sel)

        if (onDemandStartup == false) {
            return channel.keyFor(sel);
        }

        return ASSocketService.keyFor(channel, sel);
    
public voidonInitialization(ServerContext context)
Server is initializing subsystems and setting up the runtime environment. Prepare for the beginning of active use of the public methods of this subsystem. This method is called before any of the public methods of this subsystem are utilized.

param
sc ServerContext the server runtime context.
exception
IllegalStateException if this subsystem has already been started
exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used


                                                                                      
        
                          
        listener = new ServerEntryListenerImpl(this);
        ServiceGroupBuilder builder = new ServiceGroupBuilder();
        sg = builder.buildServiceGroup(this);

        // Start the lazy startup framework.
        // This will open up network ports and block any incoming connections
        // till server startup completes.
        try {
            super.setServerContext(context);
            PluggableFeatureFactory pff = context.getPluggableFeatureFactory();
            ASLazyKernel lazyStartupKernel = pff.getASLazyKernel();
            onDemandStartup = lazyStartupKernel.startASSocketServices(context) ;
        } catch (Exception e) {
            onDemandStartup = false;
            // Quick startup is not enabled. Start with normal sequence.
        }
        //ORB is initialized lazily. If this variable is not set, 
        //Naming code somehow initializes ORB.
        com.sun.enterprise.naming.SerialInitContextFactory.
        setInitializeOrbManager(false);
        super.onInitialization(context);
        try {
            systemAppLoader = new SystemAppLoader();
        } catch (Exception e) {
            throw new ServerLifecycleException(e);
        }
    
public voidonShutdown()
Server is shutting down applications

exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used

        super.onShutdown();
        try {
            sg.stop(null);
        } catch (Exception e) {
            throw new ServerLifecycleException(e);
        }
    
public voidonStartup()
Server is starting up applications

param
sc ServerContext the server runtime context.
exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used

        generateEntryContext(new Boolean(onDemandStartup));
        super.onStartup();