KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > DomainStatus


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.admin.mbeans;
25
26 import javax.management.ObjectName JavaDoc;
27 import javax.management.NotificationBroadcasterSupport JavaDoc;
28 import javax.management.Notification JavaDoc;
29 import javax.management.NotificationListener JavaDoc;
30 import javax.management.MBeanServerConnection JavaDoc;
31
32 import java.util.Map JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Collections JavaDoc;
35
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38 import com.sun.enterprise.util.i18n.StringManager;
39 import com.sun.enterprise.admin.common.constant.AdminConstants;
40
41 import com.sun.enterprise.admin.server.core.AdminService;
42 import com.sun.enterprise.config.serverbeans.ServerHelper;
43 import com.sun.enterprise.config.ConfigContext;
44 import com.sun.enterprise.admin.common.MBeanServerFactory;
45
46 import com.sun.appserv.management.j2ee.StateManageable;
47
48 /**
49  * Provides for determining the state of servers within the
50  * scope of this domain
51  *
52  * @author Sreenivas Munnangi
53  */

54
55 public class DomainStatus extends NotificationBroadcasterSupport JavaDoc
56     implements DomainStatusMBean {
57
58
59     /**
60      * variables
61      */

62     private static final Logger JavaDoc sLogger =
63     Logger.getLogger(AdminConstants.kLoggerName);
64     private static final StringManager localStrings =
65     StringManager.getManager( DomainStatus.class );
66     private Map JavaDoc m;
67
68     /**
69      * default constructor
70      */

71     public DomainStatus() {
72     m = Collections.synchronizedMap(new HashMap JavaDoc());
73     }
74
75     /**
76      * get the current state of the given server
77      * @return int the current value of the state
78      */

79     public int getstate(String JavaDoc serverName) throws Exception JavaDoc {
80     sLogger.log(Level.FINE, "DomainStatus.getstate for " + serverName);
81     // check for server name and return the value
82
if ((serverName != null) && (serverName.length() > 0)) {
83         if (m.containsKey(serverName)) {
84             return ((Integer JavaDoc) m.get(serverName)).intValue();
85         } else {
86             throw new Exception JavaDoc(
87                 localStrings.getString(
88                 "admin.mbeans.domainStatus.serverNotFound",
89                 serverName));
90         }
91     }
92     return StateManageable.STATE_FAILED;
93     }
94     
95     /**
96      * set the current state of the given server
97      */

98     public void setstate(String JavaDoc serverName, Integer JavaDoc state) throws Exception JavaDoc {
99     sLogger.log(Level.FINE, "DomainStatus.setstate for " + serverName);
100     // check for server name and set the value
101
if ((serverName != null) && (serverName.length() > 0)) {
102         m.put(serverName, state);
103         // send notification
104
sendServerStatusChangedNotification(serverName);
105     } else {
106         throw new Exception JavaDoc(
107                 localStrings.getString(
108                 "admin.mbeans.domainStatus.serverNotFound",
109                 serverName));
110     }
111     }
112
113     /**
114      * get the mBean server connection for the given server
115      */

116     public MBeanServerConnection JavaDoc getServerMBeanServerConnection(String JavaDoc serverName)
117     throws Exception JavaDoc {
118
119     sLogger.log(Level.FINE,
120         "DomainStatus.getServerMBeanServerConnection for " + serverName);
121     // vars
122
ConfigContext configContext =
123         AdminService.getAdminService().getAdminContext().getAdminConfigContext();
124     MBeanServerConnection JavaDoc mbsc = null;
125
126     // check if DAS
127
if (ServerHelper.isDAS(configContext, serverName)) {
128         mbsc = MBeanServerFactory.getMBeanServer();
129     } else {
130         mbsc = ServerHelper.connect(configContext, serverName);
131     }
132
133     return mbsc;
134     }
135
136     /**
137      * send status change notification
138      */

139     private void sendServerStatusChangedNotification(final String JavaDoc serverName) {
140
141     sLogger.log(Level.FINE,
142     "DomainStatus.sendServerStatusChangedNotification for " + serverName);
143
144     Map JavaDoc m = Collections.synchronizedMap(new HashMap JavaDoc());
145     m.put(DomainStatusMBean.SERVER_NAME_KEY, serverName);
146     Notification JavaDoc notification = new Notification JavaDoc(
147               DomainStatusMBean.SERVER_STATUS_NOTIFICATION_TYPE,
148               this,
149               0,
150               serverName);
151     notification.setUserData(m);
152     sendNotification(notification);
153     }
154
155 }
156
Popular Tags