KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > MonitorListCommand


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  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.monitor;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.Iterator JavaDoc;
35
36 import javax.management.InstanceNotFoundException JavaDoc;
37 import javax.management.ObjectName JavaDoc;
38
39 /**
40  * List command for monitoring.
41  */

42 public class MonitorListCommand extends MonitorCommand {
43
44     /**
45      * Constant to denote - List types of available MBeans
46      */

47     private static final int LIST_TYPE = 1;
48
49     /**
50      * Constant to denote - List available MBean names.
51      */

52     private static final int LIST_INSTANCE = 3;
53
54     /**
55      * Constant to denote - List available MBean types and names.
56      */

57     private static final int LIST_TYPE_AND_INSTANCE = 5;
58
59     /**
60      * Create a MonitorListCommand to list available MBean types and names. This
61      * command will produce a list of all child MBeans in the form type.name.
62      * @param mbeanName object name of the MBean
63      */

64     MonitorListCommand(ObjectName JavaDoc mbeanName) {
65         this.objectName = mbeanName;
66         this.actionCode = LIST_TYPE_AND_INSTANCE;
67     }
68
69     /**
70      * Create a MonitorListCommand to list available MBean names. This command
71      * will produce a list of names of all child MBeans of specified type.
72      * @param mbeanName object name of the MBean
73      * @param type type of the child MBeans
74      */

75     MonitorListCommand(ObjectName JavaDoc mbeanName, MonitoredObjectType type) {
76         this.objectName = mbeanName;
77         this.actionCode = LIST_INSTANCE;
78         this.monitoredObjectType = type.getTypeName();
79     }
80
81     /**
82      * Run the command to produce a list. The method returns a String[] of
83      * length 0 or more.
84      * @throws InstanceNotFoundException if the MBean is not found.
85      */

86     Object JavaDoc runCommand() throws InstanceNotFoundException JavaDoc {
87         BaseMonitorMBean mbean = MonitoringHelper.getMonitorMBean(objectName);
88         ArrayList JavaDoc childList = null;
89         if (actionCode == LIST_INSTANCE) {
90             childList = mbean.getChildList(
91                     MonitoredObjectType.getMonitoredObjectType(monitoredObjectType));
92         } else {
93             childList = mbean.getChildList();
94         }
95         String JavaDoc[] result = new String JavaDoc[childList.size()];
96         Iterator JavaDoc iter = childList.iterator();
97         int i = 0;
98         while (iter.hasNext()) {
99             BaseMonitorMBean child = (BaseMonitorMBean)iter.next();
100             MonitoredObjectType childType =
101                     MonitoredObjectType.getMonitoredObjectType(child.getNodeType());
102             if (actionCode == LIST_INSTANCE) {
103                 result[i] = child.getNodeName();
104             } else {
105                 if (childType.isSingleton()) {
106                     result[i] = child.getNodeType();
107                 } else {
108                     result[i] = child.getNodeType() + "." + child.getNodeName();
109                 }
110             }
111             i++;
112         }
113         return result;
114     }
115
116 }
117
Popular Tags