KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > model > J2EEDeployedObjectMdl


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.management.model;
25
26 import java.util.*;
27 import javax.management.*;
28
29 import com.sun.enterprise.management.util.J2EEModuleCallBack;
30
31 public abstract class J2EEDeployedObjectMdl extends J2EEEventProviderMOMdl {
32
33     public static int STARTING_STATE = 0;
34     public static int RUNNING_STATE = 1;
35     public static int STOPPING_STATE = 2;
36     public static int STOPPED_STATE = 3;
37     public static int FAILED_STATE = 4;
38
39     private J2EEModuleCallBack module;
40     private int state = this.RUNNING_STATE;
41     private long startTime = System.currentTimeMillis();
42     
43     private long sequenceNo = 0;
44     
45     //private com.sun.enterprise.tools.deployment.backend.DeploymentContext userData = null;
46

47     private String JavaDoc [] eventTypes = new String JavaDoc [] {"j2ee.state.starting","j2ee.state.running","j2ee.state.stopping","j2ee.state.stopped","j2ee.state.failed"};
48
49     J2EEDeployedObjectMdl(J2EEModuleCallBack m) {
50     super(m.getName(), m.getServerName(), false, false);
51     module = m;
52     }
53
54     /**
55     * The deploymentDescriptor string must contain the original XML deployment descriptor that was created for this module during the deployment process.
56     */

57     public String JavaDoc getdeploymentDescriptor() {
58         return module.getDeploymentDescriptor();
59     }
60
61     /** returns the OBJECT_NAME of the J2EEServer this module is deployed on. */
62     public String JavaDoc getserver() {
63         String JavaDoc qs = "name=" + getJ2EEServer() + ",j2eeType=J2EEServer";
64         Set s = findNames(qs);
65         ObjectName[] sa = (ObjectName[]) s.toArray(
66             new ObjectName[s.size()]);
67         if (sa.length > 0) {
68             return sa[0].toString();
69         }
70         return "Failed to find the server ObjectName";
71     }
72
73     public String JavaDoc[] geteventTypes(){
74         return eventTypes;
75     }
76
77     public int getstate(){
78         return this.state;
79     }
80
81     public void setstate(int st){
82         this.state = st;
83         this.stateChanged(eventTypes[st]);
84     }
85     
86     public long getstartTime(){
87         return this.startTime;
88     }
89     public void start() {
90
91     if ((this.state == this.STARTING_STATE) ||
92         (this.state == this.RUNNING_STATE) ||
93         (this.state == this.STOPPING_STATE)) {
94             throw new RuntimeException JavaDoc(
95           new Exception JavaDoc ("cannot start because the current state is " + this.state));
96     }
97
98         try{
99             this.state = this.STARTING_STATE;
100             this.stateChanged("j2ee.state.starting");
101         module.start(this);
102             this.state = this.RUNNING_STATE;
103             this.startTime = System.currentTimeMillis();
104             this.stateChanged("j2ee.state.running");
105         }catch(Exception JavaDoc ex){
106             this.state = this.FAILED_STATE;
107             this.stateChanged("j2ee.state.failed");
108         if(ex instanceof RuntimeException JavaDoc)
109                 throw (RuntimeException JavaDoc)ex;
110             throw new RuntimeException JavaDoc(ex);
111         }
112     }
113
114     public void stop() throws MBeanException {
115
116     if ((this.state == this.STOPPED_STATE) ||
117         (this.state == this.STOPPING_STATE)) {
118             throw new RuntimeException JavaDoc(
119         new Exception JavaDoc("cannot stop because the current state is " + this.state));
120     }
121
122         try{
123             this.state = this.STOPPING_STATE;
124             this.stateChanged("j2ee.state.stopping");
125         module.stop(this);
126             this.state = this.STOPPED_STATE;
127             this.stateChanged("j2ee.state.stopped");
128         }catch(Exception JavaDoc ex){
129             this.state = this.FAILED_STATE;
130             this.stateChanged("j2ee.state.failed");
131         if(ex instanceof RuntimeException JavaDoc)
132                 throw (RuntimeException JavaDoc)ex;
133             throw new RuntimeException JavaDoc(ex);
134         }
135     }
136
137     public void startRecursive() throws MBeanException {
138         start();
139     }
140
141     private void stateChanged(String JavaDoc state){
142        // Send notification to all the listeners
143
if(this.getobjectName() == null){
144             System.out.println("WARNING !!!!!!!! Could not send state notification event from the managed object because managed object does not exist bug # 4756051");
145             return;
146         }
147        javax.management.Notification JavaDoc notification = new javax.management.Notification JavaDoc(state,this.getobjectName(),sequenceNo++);
148        this.sendNotification(notification);
149     }
150     
151     /** Getter for property userData.
152      * @return Value of property userData.
153      */

154     //public com.sun.enterprise.tools.deployment.backend.DeploymentContext getUserData() {
155
//return userData;
156
//}
157

158     /** Setter for property userData.
159      * @param userData New value of property userData.
160      */

161     //public void setUserData(com.sun.enterprise.tools.deployment.backend.DeploymentContext userData) {
162
//this.userData = userData;
163
//}
164
}
165
Popular Tags