KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > j2ee > J2EEClusterImpl


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  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/j2ee/J2EEClusterImpl.java,v 1.6 2006/03/17 03:34:18 llc Exp $
26  * $Revision: 1.6 $
27  * $Date: 2006/03/17 03:34:18 $
28  */

29  
30 package com.sun.enterprise.management.j2ee;
31
32 import java.util.Set JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.Collections JavaDoc;
37
38 import javax.management.ObjectName JavaDoc;
39
40 import com.sun.appserv.management.base.Util;
41 import com.sun.appserv.management.util.misc.GSetUtil;
42 import com.sun.appserv.management.util.misc.ExceptionUtil;
43
44 import com.sun.appserv.management.j2ee.J2EECluster;
45
46 import com.sun.appserv.management.j2ee.J2EETypes;
47
48 import com.sun.appserv.management.j2ee.StateManageable;
49
50
51 import com.sun.enterprise.management.support.Delegate;
52 import com.sun.enterprise.management.support.oldconfig.OldClusterMBean;
53 import com.sun.enterprise.management.support.oldconfig.OldClustersMBean;
54
55 import com.sun.enterprise.admin.servermgmt.RuntimeStatusList;
56 import com.sun.enterprise.admin.servermgmt.RuntimeStatus;
57
58 /**
59     JSR 77 extension representing an Appserver Cluster
60  */

61 public final class J2EEClusterImpl
62     extends J2EELogicalServerImplBase
63 {
64         public
65     J2EEClusterImpl( final Delegate delegate )
66     {
67         super( J2EETypes.J2EE_CLUSTER, delegate );
68     }
69     
70         public String JavaDoc[]
71     getServerNames()
72     {
73         /*
74             J2EEServer is not a subtype of J2EECluster in the containment hierarchy.
75             So the following doesnot work.
76             return getContaineeNamesOfType( J2EETypes.J2EE_SERVER );
77          */

78         return getOldClusterMBean().listServerInstancesAsString( false );
79     }
80     
81         public Map JavaDoc<String JavaDoc,ObjectName JavaDoc>
82     getServerObjectNameMap()
83     {
84         /*
85             J2EEServer is not a subtype of J2EECluster in the containment hierarchy.
86             So the following does not work.
87             return getContaineeObjectNameMap( J2EETypes.J2EE_SERVER );
88          */

89         final Set JavaDoc<String JavaDoc> serverNamesInCluster = GSetUtil.newStringSet( getServerNames() );
90         if ( serverNamesInCluster.size() == 0 )
91         {
92             return Collections.emptyMap();
93         }
94         final Set JavaDoc<ObjectName JavaDoc> allJ2EEServerObjectNames =
95             getQueryMgr().queryJ2EETypeObjectNameSet( J2EETypes.J2EE_SERVER );
96         final Map JavaDoc<String JavaDoc,ObjectName JavaDoc> objectNameMap = Util.createObjectNameMap( allJ2EEServerObjectNames );
97
98         final Map JavaDoc<String JavaDoc,ObjectName JavaDoc> serverObjectNameMap =
99             new HashMap JavaDoc<String JavaDoc,ObjectName JavaDoc>( serverNamesInCluster.size() );
100
101         for( final String JavaDoc nameKey : serverNamesInCluster )
102         {
103             serverObjectNameMap.put( nameKey, objectNameMap.get( nameKey ) );
104         }
105         return serverObjectNameMap;
106     }
107
108         public boolean
109     isstateManageable()
110     {
111         return true;
112     }
113
114         public void
115     start()
116     {
117         trace( "J2EEClusterImpl.start" );
118         getOldClusterMBean().start();
119         setstartTime( System.currentTimeMillis() );
120     }
121
122         public void
123     startRecursive()
124     {
125         start();
126     }
127
128         public void
129     stop()
130     {
131         trace( "J2EEClusterImpl.start" );
132         getOldClusterMBean().stop();
133         setstartTime( 0 );
134     }
135
136         public int
137     getstate()
138     {
139         final RuntimeStatusList rsl = getRuntimeStatus();
140         int state = rsl.anyRunning() ?
141             StateManageable.STATE_RUNNING : StateManageable.STATE_STOPPED;
142         return state;
143     }
144         private OldClusterMBean
145     getOldClusterMBean()
146     {
147         return( getOldConfigProxies().getOldClusterMBean( getSelfName() ) );
148     }
149
150         private RuntimeStatusList
151     getRuntimeStatus()
152     {
153         /**
154             Should have called OldClusterMBean.getRuntimeStatus() instead.
155             But was getting back AttributeNotFoundException. Maybe bacause
156             RuntimeStatus is not exposed as an attribute of the ClusterConfigMBean.
157          */

158         final OldClustersMBean oldMBean =
159             getOldConfigProxies().getOldClustersMBean();
160         return( ( RuntimeStatusList )oldMBean.getRuntimeStatus( getSelfName() ) );
161     }
162 }
163
Popular Tags