KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > AdminServiceLifeCycle


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 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.server.core;
32
33 import com.sun.appserv.server.ServerLifecycle;
34 import com.sun.appserv.server.ServerLifecycleImpl;
35 import com.sun.appserv.server.ServerLifecycleException;
36
37 import com.sun.enterprise.server.ServerContext;
38
39
40 /**
41  * Lifecycle manager for admin service.
42  */

43 public class AdminServiceLifeCycle extends ServerLifecycleImpl {
44
45     /**
46      * Constant denoting the status of admin service not started
47      */

48     public static final byte STATUS_NOT_STARTED = 0;
49
50     /**
51      * Constant denoting the status of admin service shutdown started
52      */

53     public static final byte STATUS_SHUTDOWN = 1;
54
55     /**
56      * Constant denoting the status of admin service initialized
57      */

58     public static final byte STATUS_INITED = 2;
59
60     /**
61      * Constant denoting the status of admin service started
62      */

63     public static final byte STATUS_STARTED = 4;
64
65     /**
66      * Constant denoting the status of admin service ready
67      */

68     public static final byte STATUS_READY = 8;
69
70     /**
71      * Constant denoting the status of admin service terminated
72      */

73     public static final byte STATUS_TERMINATED = 0;
74
75     private byte serverStatus;
76
77     /**
78      * Default constructor
79      */

80     public AdminServiceLifeCycle() {
81         serverStatus = STATUS_NOT_STARTED;
82     }
83
84     /**
85      * Server is initializing admin server and setting up the runtime environment.
86      * Prepare for the beginning of active use of the public methods of admin
87      * server. This method is called before any of the public methods of
88      * admin server are utilized.
89      *
90      * @param sc ServerContext the server runtime context.
91      *
92      * @exception IllegalStateException if this subsystem has already been
93      * started
94      * @exception ServerLifecycleException if this subsystem detects a fatal
95      * error that prevents this subsystem from being used
96      */

97     public void onInitialization(ServerContext sc)
98             throws ServerLifecycleException {
99         if ((serverStatus & STATUS_INITED) == STATUS_INITED) {
100             throw new IllegalStateException JavaDoc("Admin Server already initialized");
101         }
102         AdminService srv = AdminService.createAdminService(sc);
103         srv.init();
104         serverStatus = STATUS_INITED;
105     }
106
107     /**
108      * Server is starting up applications
109      *
110      * @param sc ServerContext the server runtime context.
111      *
112      * @exception ServerLifecycleException if this subsystem detects a fatal
113      * error that prevents this subsystem from being used
114      */

115     public void onStartup(ServerContext sc)
116             throws ServerLifecycleException {
117         AdminService.getAdminService().start();
118         serverStatus |= STATUS_STARTED;
119     }
120
121     /**
122      * Server has completed loading the services and is ready to serve requests.
123      *
124      * @param sc ServerContext the server runtime context.
125      *
126      * @exception ServerLifecycleException if this subsystem detects a fatal
127      * error that prevents this subsystem from being used
128      */

129     public void onReady(ServerContext sc) throws ServerLifecycleException {
130         AdminService.getAdminService().ready();
131         serverStatus |= STATUS_READY;
132     }
133
134     /**
135      * Server is shutting down applications
136      *
137      * @exception ServerLifecycleException if this subsystem detects a fatal
138      * error that prevents this subsystem from being used
139      */

140     public void onShutdown() throws ServerLifecycleException {
141         serverStatus |= STATUS_SHUTDOWN;
142         AdminService.getAdminService().stop();
143     }
144
145     /**
146      * Server is terminating the subsystems and the runtime environment.
147      * Gracefully terminate the active use of the public methods of this
148      * subsystem. This method should be the last one called on a given
149      * instance of this subsystem.
150      *
151      * @exception ServerLifecycleException if this subsystem detects a fatal
152      * error that prevents this subsystem from being used
153      */

154     public void onTermination() throws ServerLifecycleException {
155         AdminService.getAdminService().destroy();
156         serverStatus = STATUS_TERMINATED;
157     }
158
159 }
160
Popular Tags