001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.admin.cli.commands.monitoring;
006:
007: import javax.management.*;
008: import java.io.IOException;
009: import java.util.Set;
010:
011: public class CommandClient {
012: public void addNotificationListener(ObjectName on,
013: NotificationListener listener, NotificationFilter filter,
014: Object handback) throws ReflectionException, IOException,
015: InstanceNotFoundException, MBeanException {
016: getMBeanServerConnection().invoke(
017: getObjectName(),
018: "addNotificationListener",
019: new Object[] { on, listener, filter, handback },
020: new String[] { ObjectName.class.getName(),
021: NotificationListener.class.getName(),
022: NotificationFilter.class.getName(),
023: Object.class.getName() });
024: }
025:
026: public Object getAttribute(ObjectName on, String attrName)
027: throws ReflectionException, IOException,
028: InstanceNotFoundException, MBeanException {
029: return getMBeanServerConnection().invoke(
030: getObjectName(),
031: "getAttribute",
032: new Object[] { on, attrName },
033: new String[] { ObjectName.class.getName(),
034: String.class.getName() });
035: }
036:
037: public AttributeList getAttributes(ObjectName on, String[] attrNames)
038: throws ReflectionException, IOException,
039: InstanceNotFoundException, MBeanException {
040: return (AttributeList) getMBeanServerConnection().invoke(
041: getObjectName(),
042: "getAttributes",
043: new Object[] { on, attrNames },
044: new String[] { ObjectName.class.getName(),
045: String[].class.getName() });
046: }
047:
048: public String getDefaultDomain() throws ReflectionException,
049: IOException, InstanceNotFoundException, MBeanException,
050: AttributeNotFoundException {
051: return (String) getMBeanServerConnection().getAttribute(
052: getObjectName(), "DefaultDomain");
053: }
054:
055: public Integer getMBeanCount() throws ReflectionException,
056: IOException, InstanceNotFoundException, MBeanException,
057: AttributeNotFoundException {
058: return (Integer) getMBeanServerConnection().getAttribute(
059: getObjectName(), "MBeanCount");
060: }
061:
062: public MBeanInfo getMBeanInfo(ObjectName on)
063: throws ReflectionException, IOException,
064: InstanceNotFoundException, MBeanException {
065: return (MBeanInfo) getMBeanServerConnection().invoke(
066: getObjectName(), "getMBeanInfo", new Object[] { on },
067: new String[] { ObjectName.class.getName() });
068: }
069:
070: public Object invoke(ObjectName on, String operationName,
071: Object[] params, String[] signature)
072: throws ReflectionException, IOException,
073: InstanceNotFoundException, MBeanException {
074: return getMBeanServerConnection().invoke(
075: getObjectName(),
076: "invoke",
077: new Object[] { on, operationName, params, signature },
078: new String[] { ObjectName.class.getName(),
079: String.class.getName(),
080: Object[].class.getName(),
081: String[].class.getName() });
082: }
083:
084: public Boolean isInstanceOf(ObjectName on, String className)
085: throws ReflectionException, IOException,
086: InstanceNotFoundException, MBeanException {
087: return (Boolean) getMBeanServerConnection().invoke(
088: getObjectName(),
089: "isInstanceOf",
090: new Object[] { on, className },
091: new String[] { ObjectName.class.getName(),
092: String.class.getName() });
093: }
094:
095: public Boolean isRegistered(ObjectName on)
096: throws ReflectionException, IOException,
097: InstanceNotFoundException, MBeanException {
098: return (Boolean) getMBeanServerConnection().invoke(
099: getObjectName(), "isRegistered", new Object[] { on },
100: new String[] { ObjectName.class.getName() });
101: }
102:
103: public Set queryNames(ObjectName pattern, QueryExp expr)
104: throws ReflectionException, IOException,
105: InstanceNotFoundException, MBeanException {
106: return (Set) getMBeanServerConnection().invoke(
107: getObjectName(),
108: "queryNames",
109: new Object[] { pattern, expr },
110: new String[] { ObjectName.class.getName(),
111: QueryExp.class.getName() });
112: }
113:
114: public void removeNotificationListener(ObjectName on,
115: NotificationListener listener) throws ReflectionException,
116: IOException, InstanceNotFoundException, MBeanException {
117: getMBeanServerConnection().invoke(
118: getObjectName(),
119: "removeNotificationListener",
120: new Object[] { on, listener },
121: new String[] { ObjectName.class.getName(),
122: NotificationListener.class.getName() });
123: }
124:
125: public void setAttribute(ObjectName on, Attribute attr)
126: throws ReflectionException, IOException,
127: InstanceNotFoundException, MBeanException {
128: getMBeanServerConnection().invoke(
129: getObjectName(),
130: "setAttribute",
131: new Object[] { on, attr },
132: new String[] { ObjectName.class.getName(),
133: Attribute.class.getName() });
134: }
135:
136: public AttributeList setAttributes(ObjectName on,
137: AttributeList attrs) throws ReflectionException,
138: IOException, InstanceNotFoundException, MBeanException {
139: return (AttributeList) getMBeanServerConnection().invoke(
140: getObjectName(),
141: "setAttributes",
142: new Object[] { on, attrs },
143: new String[] { ObjectName.class.getName(),
144: AttributeList.class.getName() });
145: }
146:
147: public void unregisterMBean(ObjectName on)
148: throws ReflectionException, IOException,
149: InstanceNotFoundException, MBeanException {
150: getMBeanServerConnection().invoke(getObjectName(),
151: "unregisterMBean", new Object[] { on },
152: new String[] { ObjectName.class.getName() });
153: }
154:
155: public void disconnect() throws ReflectionException, IOException,
156: InstanceNotFoundException, MBeanException {
157: getMBeanServerConnection().invoke(getObjectName(),
158: "disconnect", null, null);
159: }
160:
161: public void connect() throws ReflectionException, IOException,
162: InstanceNotFoundException, MBeanException {
163: getMBeanServerConnection().invoke(getObjectName(), "connect",
164: null, null);
165: }
166:
167: public MBeanServerConnection getMBeanServerConnection() {
168: return mBeanServerConnection;
169: }
170:
171: public void setMBeanServerConnection(
172: MBeanServerConnection mBeanServerConnection) {
173: this .mBeanServerConnection = mBeanServerConnection;
174: }
175:
176: public ObjectName getObjectName() {
177: return objectName;
178: }
179:
180: public void setObjectName(ObjectName objectName) {
181: this .objectName = objectName;
182: }
183:
184: private MBeanServerConnection mBeanServerConnection;
185: private ObjectName objectName;
186: }
|