KickJava   Java API By Example, From Geeks To Geeks.

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


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.MBeanServer JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.MalformedObjectNameException JavaDoc;
29 import javax.management.MBeanServerInvocationHandler JavaDoc;
30
31 import com.sun.enterprise.admin.common.MBeanServerFactory;
32 import com.sun.enterprise.server.ApplicationServer;
33
34 import com.sun.appserv.management.client.ProxyFactory;
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 /**
42  * Helper class for setting server status in DomianStatusMBean
43  *
44  * @author Sreenivas Munnangi
45  */

46
47 public class DomainStatusHelper {
48
49     // vars
50

51     private static final Logger JavaDoc sLogger =
52         Logger.getLogger(AdminConstants.kLoggerName);
53
54     private static final StringManager localStrings =
55         StringManager.getManager( DomainStatusHelper.class );
56
57     private static final Class JavaDoc[] DOMAIN_STATUS_INTERFACES =
58     new Class JavaDoc[] { DomainStatusMBean.class };
59
60
61     // default constructor
62
public DomainStatusHelper() {
63     }
64
65     public DomainStatusHelper(String JavaDoc serverName) {
66     }
67
68     public void setstate (String JavaDoc serverName, int state) {
69     sLogger.log(Level.FINE, "DomainStatusHelper setstate for " + serverName);
70     try {
71         getDomainStatus().setstate(serverName, new Integer JavaDoc(state));
72     } catch (Exception JavaDoc e) {
73         sLogger.log(Level.WARNING,
74             "DomainStatusHelper setstate exception for server " +
75             serverName, e);
76     }
77     }
78
79     public int getstate (String JavaDoc serverName) throws Exception JavaDoc {
80     sLogger.log(Level.FINE, "DomainStatusHelper getstate for " + serverName);
81     return (getDomainStatus().getstate(serverName));
82     }
83
84     protected DomainStatusMBean getDomainStatus() {
85     MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
86     ObjectName JavaDoc on = null;
87     try {
88         on = getDomainStatusObjectName();
89     } catch (MalformedObjectNameException JavaDoc mone) {
90         sLogger.log(Level.WARNING,
91             "DomainStatusHelper getDomainStatus ObjectName exception", mone);
92     }
93     DomainStatusMBean domainStatus = null;
94     try {
95         domainStatus =
96             (DomainStatusMBean)MBeanServerInvocationHandler.newProxyInstance(
97                 mbs, on, DomainStatusMBean.class, false );
98     } catch (Exception JavaDoc e) {
99         sLogger.log(Level.WARNING,
100             "DomainStatusHelper getDomainStatus io exception", e);
101     }
102     return(domainStatus);
103     }
104
105     public static ObjectName JavaDoc getDomainStatusObjectName()
106     throws MalformedObjectNameException JavaDoc {
107
108     ObjectName JavaDoc on = new ObjectName JavaDoc(
109         ApplicationServer.getServerContext().getDefaultDomainName() + ":" +
110         DomainStatusMBean.DOMAIN_STATUS_PROPS);
111     return on;
112     }
113
114     public static ObjectName JavaDoc getServersConfigObjectName()
115     throws MalformedObjectNameException JavaDoc {
116
117     ObjectName JavaDoc on = new ObjectName JavaDoc(
118         ApplicationServer.getServerContext().getDefaultDomainName() + ":" +
119         "type=servers,category=config");
120     return on;
121     }
122
123
124 }
125
Popular Tags