KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > BulkAccessImpl


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/support/BulkAccessImpl.java,v 1.3 2005/12/25 03:40:38 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:40:38 $
28  */

29
30 package com.sun.enterprise.management.support;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.management.MBeanInfo JavaDoc;
34 import javax.management.MBeanAttributeInfo JavaDoc;
35 import javax.management.MBeanOperationInfo JavaDoc;
36
37 import javax.management.Attribute JavaDoc;
38 import javax.management.AttributeList JavaDoc;
39
40 import com.sun.appserv.management.base.BulkAccess;
41 import com.sun.appserv.management.base.XTypes;
42 import com.sun.appserv.management.base.AMX;
43 import com.sun.appserv.management.util.jmx.JMXUtil;
44
45
46 /**
47  */

48 public class BulkAccessImpl extends AMXImplBase
49     implements BulkAccess
50 {
51         public
52     BulkAccessImpl()
53     {
54     }
55
56         public String JavaDoc
57     getGroup()
58     {
59         return( AMX.GROUP_UTILITY );
60     }
61     
62         public Object JavaDoc[]
63     bulkGetMBeanInfo( final ObjectName JavaDoc[] objectNames )
64     {
65         final Object JavaDoc[] infos = new Object JavaDoc[ objectNames.length ];
66         
67         for( int i = 0; i < infos.length; ++i )
68         {
69             try
70             {
71                 infos[ i ] = getMBeanServer().getMBeanInfo( objectNames[ i ] );
72             }
73             catch( Throwable JavaDoc t )
74             {
75                 infos[ i ] = t;
76             }
77         }
78         return( infos );
79     }
80     
81         public Object JavaDoc[]
82     bulkGetMBeanAttributeInfo( final ObjectName JavaDoc[] objectNames )
83     {
84         final Object JavaDoc[] results = new Object JavaDoc[objectNames.length];
85         final Object JavaDoc[] mbeanInfos = bulkGetMBeanInfo( objectNames );
86         
87         for( int i = 0; i < results.length; ++i )
88         {
89             if ( mbeanInfos[ i ] instanceof MBeanInfo JavaDoc )
90             {
91                 results[ i ] = ((MBeanInfo JavaDoc)mbeanInfos[ i ]).getAttributes();
92             }
93             else
94             {
95                 results[ i ] = mbeanInfos[ i ];
96             }
97         }
98         return( results );
99     }
100     
101         public Object JavaDoc[]
102     bulkGetAttributeNames( final ObjectName JavaDoc[] objectNames )
103     {
104         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
105         final Object JavaDoc[] mbeanInfos = bulkGetMBeanInfo( objectNames );
106         
107         for( int i = 0; i < results.length; ++i )
108         {
109             if ( mbeanInfos[ i ] instanceof MBeanInfo JavaDoc )
110             {
111                 final MBeanInfo JavaDoc info = (MBeanInfo JavaDoc)mbeanInfos[ i ];
112                 
113                 results[ i ] = JMXUtil.getAttributeNames( info.getAttributes() );
114             }
115             else
116             {
117                 results[ i ] = mbeanInfos[ i ];
118             }
119         }
120         return( results );
121     }
122     
123         public Object JavaDoc[]
124     bulkGetMBeanOperationInfo( final ObjectName JavaDoc[] objectNames )
125     {
126         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
127         final Object JavaDoc[] mbeanInfos = bulkGetMBeanInfo( objectNames );
128         
129         for( int i = 0; i < results.length; ++i )
130         {
131             if ( mbeanInfos[ i ] instanceof MBeanInfo JavaDoc )
132             {
133                 final MBeanInfo JavaDoc info = (MBeanInfo JavaDoc)mbeanInfos[ i ];
134                 
135                 results[ i ] = info.getOperations();
136             }
137             else
138             {
139                 results[ i ] = mbeanInfos[ i ];
140             }
141         }
142         return( results );
143     }
144     
145         public Object JavaDoc[]
146     bulkGetAttribute(
147         final ObjectName JavaDoc[] objectNames,
148         final String JavaDoc attributeName )
149     {
150         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
151         
152         for( int i = 0; i < objectNames.length; ++i )
153         {
154             try
155             {
156                 results[ i ] = getMBeanServer().getAttribute( objectNames[ i ], attributeName );
157             }
158             catch( Throwable JavaDoc t )
159             {
160                 results[ i ] = t;
161             }
162         }
163         return( results );
164     }
165     
166         public Object JavaDoc[]
167     bulkSetAttribute(
168         final ObjectName JavaDoc[] objectNames,
169         final Attribute JavaDoc attr )
170     {
171         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
172         
173         for( int i = 0; i < objectNames.length; ++i )
174         {
175             try
176             {
177                 results[ i ] = null;
178                 getMBeanServer().setAttribute( objectNames[ i ], attr );
179             }
180             catch( Throwable JavaDoc t )
181             {
182                 results[ i ] = t;
183             }
184         }
185         return( results );
186     }
187     
188     
189         public Object JavaDoc[]
190     bulkGetAttributes(
191         final ObjectName JavaDoc[] objectNames,
192         final String JavaDoc[] attributeNames )
193     {
194         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
195         
196         // check for empty list; this occurs occassionally and not all MBeans
197
// are well-behaved if one asks for an empty list
198
if ( attributeNames.length != 0 )
199         {
200             for( int i = 0; i < objectNames.length; ++i )
201             {
202                 // copy names, in case an MBean messes with the array
203
final String JavaDoc[] attributesCopy = (String JavaDoc[])attributeNames.clone();
204                 
205                 try
206                 {
207                     results[ i ] = getMBeanServer().getAttributes( objectNames[ i ], attributesCopy );
208                 }
209                 catch( Throwable JavaDoc t )
210                 {
211                     results[ i ] = t;
212                 }
213             }
214         }
215         return( results );
216     }
217     
218     
219         public Object JavaDoc[]
220     bulkSetAttributes(
221         final ObjectName JavaDoc[] objectNames,
222         final AttributeList JavaDoc attrs )
223     {
224         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
225         
226         for( int i = 0; i < objectNames.length; ++i )
227         {
228             try
229             {
230                 // avoid alterations to original copy
231
final AttributeList JavaDoc attrsCopy = (AttributeList JavaDoc)attrs.clone();
232                 
233                 results[ i ] = getMBeanServer().setAttributes( objectNames[ i ], attrsCopy );
234             }
235             catch( Throwable JavaDoc t )
236             {
237                 results[ i ] = t;
238             }
239         }
240         return( results );
241     }
242     
243     
244         public Object JavaDoc[]
245     bulkInvoke(
246         final ObjectName JavaDoc[] objectNames,
247         final String JavaDoc operationName,
248         final Object JavaDoc[] args,
249         final String JavaDoc[] types )
250     {
251         final Object JavaDoc[] results = new Object JavaDoc[ objectNames.length ];
252         
253         for( int i = 0; i < objectNames.length; ++i )
254         {
255             try
256             {
257                 // hopefully the MBean won't alter the args or types
258
results[ i ] = getMBeanServer().invoke( objectNames[ i ],
259                                     operationName, args, types );
260             }
261             catch( Throwable JavaDoc t )
262             {
263                 results[ i ] = t;
264             }
265         }
266         return( results );
267     }
268 }
269
270
271
272
273
274
275
276
277
278
279
280
Popular Tags