KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ondemand > OnDemandServer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.server.ondemand;
25
26 import java.util.*;
27 import java.util.logging.*;
28 import com.sun.logging.LogDomains;
29 import com.sun.enterprise.server.*;
30 import com.sun.enterprise.server.ss.*;
31 import com.sun.enterprise.server.ondemand.entry.*;
32
33 import com.sun.appserv.server.ServerLifecycle;
34 import com.sun.appserv.server.LifecycleEvent;
35 import com.sun.appserv.server.ServerLifecycleException;
36 import com.sun.enterprise.server.pluggable.PluggableFeatureFactory;
37 import com.sun.enterprise.server.pluggable.PluggableFeatureFactoryImpl;
38 import com.sun.enterprise.server.pluggable.InternalServicesList;
39
40
41
42 /**
43  * Represents on-demand server. This is the main class that ties ondemand logic
44  * with rest of the application server.
45  */

46 public class OnDemandServer extends ApplicationServer implements EntryPoint{
47
48     private static boolean onDemandStartup = true;
49
50     private static ServerEntryListener listener = null;
51     private static SystemAppLoader systemAppLoader = null;
52     private ServiceGroup sg = null;
53
54    /** server logger */
55     static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
56
57
58     /**
59      * Server is initializing subsystems and setting up the runtime environment.
60      * Prepare for the beginning of active use of the public methods of this
61      * subsystem. This method is called before any of the public methods of
62      * this subsystem are utilized.
63      *
64      * @param sc ServerContext the server runtime context.
65      *
66      * @exception IllegalStateException if this subsystem has already been
67      * started
68      * @exception ServerLifecycleException if this subsystem detects a fatal
69      * error that prevents this subsystem from being used
70      */

71     public void onInitialization(ServerContext context)
72                         throws ServerLifecycleException {
73         listener = new ServerEntryListenerImpl(this);
74         ServiceGroupBuilder builder = new ServiceGroupBuilder();
75         sg = builder.buildServiceGroup(this);
76
77         // Start the lazy startup framework.
78
// This will open up network ports and block any incoming connections
79
// till server startup completes.
80
try {
81             super.setServerContext(context);
82             PluggableFeatureFactory pff = context.getPluggableFeatureFactory();
83             ASLazyKernel lazyStartupKernel = pff.getASLazyKernel();
84             onDemandStartup = lazyStartupKernel.startASSocketServices(context) ;
85         } catch (Exception JavaDoc e) {
86             onDemandStartup = false;
87             // Quick startup is not enabled. Start with normal sequence.
88
}
89         //ORB is initialized lazily. If this variable is not set,
90
//Naming code somehow initializes ORB.
91
com.sun.enterprise.naming.SerialInitContextFactory.
92         setInitializeOrbManager(false);
93         super.onInitialization(context);
94         try {
95             systemAppLoader = new SystemAppLoader();
96         } catch (Exception JavaDoc e) {
97             throw new ServerLifecycleException(e);
98         }
99     }
100
101     /**
102      * Server is starting up applications
103      *
104      * @param sc ServerContext the server runtime context.
105      *
106      * @exception ServerLifecycleException if this subsystem detects a fatal
107      * error that prevents this subsystem from being used
108      */

109     public void onStartup()
110                         throws ServerLifecycleException {
111         generateEntryContext(new Boolean JavaDoc(onDemandStartup));
112         super.onStartup();
113     }
114
115     /**
116      * Server is shutting down applications
117      *
118      * @exception ServerLifecycleException if this subsystem detects a fatal
119      * error that prevents this subsystem from being used
120      */

121     public void onShutdown()
122                         throws ServerLifecycleException {
123         super.onShutdown();
124         try {
125             sg.stop(null);
126         } catch (Exception JavaDoc e) {
127             throw new ServerLifecycleException(e);
128         }
129     }
130
131     public void generateEntryContext(Object JavaDoc event) {
132         ServerEntryHelper.generateStartUpEntryContext((Boolean JavaDoc) event);
133     }
134
135     protected ArrayList instantiateRuntimeServices() throws ServerLifecycleException {
136         if (onDemandStartup) {
137             InternalServicesList services = new TomcatServices();
138             InternalServicesList ondemandservices = new OnDemandServices();
139             String JavaDoc[][] servicesByName = services.getServicesByName();
140             String JavaDoc[][] odsByName = ondemandservices.getServicesByName();
141             if (servicesByName == null) {
142                _logger.log(Level.SEVERE, "services.null");
143                throw new ServerLifecycleException();
144             }
145
146             ArrayList serviceList = new ArrayList();
147
148             // Instantiate service objects
149
allServices :
150             for (String JavaDoc[] service : servicesByName) {
151                for (String JavaDoc[] ods : odsByName) {
152                     if (service[0].equals(ods[0])) {
153                         continue allServices;
154                     }
155                }
156                try {
157                    //String[] def = servicesByName[i];
158
Class JavaDoc c = java.lang.Class.forName(service[1]);
159                    Object JavaDoc o = c.newInstance();
160                    serviceList.add(o);
161                } catch (Exception JavaDoc ex) {
162                    _logger.log(Level.SEVERE, "server.exception", ex);
163                    throw new ServerLifecycleException(ex.getMessage());
164                }
165             }
166             return serviceList;
167         } else {
168             return super.instantiateRuntimeServices();
169         }
170     }
171
172     // Return the server entry listener.
173
public static ServerEntryListener getServerEntryListener() {
174         return listener;
175     }
176
177     // Return the system apploader.
178
public static SystemAppLoader getSystemAppLoader() {
179         return systemAppLoader;
180     }
181
182     // Return the main service group.
183
public ServiceGroup getServiceGroup() {
184         return sg;
185     }
186
187     public static boolean isOnDemandOff() {
188         return onDemandStartup == false;
189     }
190     
191 }
192
Popular Tags