KickJava   Java API By Example, From Geeks To Geeks.

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


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.Attribute JavaDoc;
37 import javax.management.AttributeList JavaDoc;
38 import javax.management.InstanceNotFoundException JavaDoc;
39 import javax.management.MBeanException JavaDoc;
40 import javax.management.ReflectionException JavaDoc;
41 import javax.management.MBeanAttributeInfo JavaDoc;
42 import javax.management.MBeanInfo JavaDoc;
43 import javax.management.ObjectName JavaDoc;
44
45 /**
46  *
47  */

48 public class MonitorSetCommand extends MonitorCommand {
49
50     /**
51      *
52      */

53     private String JavaDoc[] params;
54     private static final String JavaDoc WILDCARD = "*";
55     private String JavaDoc operationName;
56
57     /**
58      *
59      */

60     MonitorSetCommand(ObjectName JavaDoc mbeanName, MonitoredObjectType type, String JavaDoc operationName, String JavaDoc[] commandOperands) {
61         this.objectName = mbeanName;
62         if (type != null) {
63             this.monitoredObjectType = type.getTypeName();
64         }
65         this.operationName = operationName;
66     if (commandOperands.length > 0) {
67             params = commandOperands;
68         }
69         
70         if (WILDCARD.equals(operationName)) {
71             throw new UnsupportedOperationException JavaDoc(BaseMonitorMBean.UNSUPPORTED_ERRMSG);
72         }
73     }
74
75     /**
76      *
77      */

78     Object JavaDoc runCommand() throws InstanceNotFoundException JavaDoc,
79             ReflectionException JavaDoc, MBeanException JavaDoc {
80         BaseMonitorMBean mbean = MonitoringHelper.getMonitorMBean(objectName);
81         if (mbean == null) {
82             throw new InstanceNotFoundException JavaDoc();
83         }
84         ArrayList JavaDoc mbeanList = null;
85         
86         if (monitoredObjectType != null) {
87             mbeanList = mbean.getChildList(monitoredObjectType);
88         } else {
89             mbeanList = new ArrayList JavaDoc();
90             mbeanList.add(mbean);
91         }
92         AttributeList JavaDoc result = new AttributeList JavaDoc();
93
94         Object JavaDoc val = mbean.invoke(operationName, params, null);
95         Attribute JavaDoc attr = new Attribute JavaDoc(operationName, val);
96         result.add(attr);
97
98         return result;
99     }
100 }
101
Popular Tags