001: package com.sun.portal.admin.cli.commands.monitoring;
002:
003: import javax.management.*;
004: import java.util.Set;
005: import java.io.IOException;
006:
007: /**
008: * author: Noble Paul
009: * Date: Apr 5, 2005, 5:39:45 PM
010: */
011: public class SRACommandClient extends CommandClient {
012: MonitoringBaseCommand command = null;
013: private static final String STR_CLASS_NAME = String.class.getName();
014:
015: public void addNotificationListener(ObjectName on,
016: NotificationListener listener, NotificationFilter filter,
017: Object handback) throws ReflectionException, IOException,
018: InstanceNotFoundException, MBeanException {
019:
020: invokeMethod("addNotificationListener", new Object[] { on,
021: listener, filter, handback }, new String[] {
022: ObjectName.class.getName(),
023: NotificationListener.class.getName(),
024: NotificationFilter.class.getName(),
025: Object.class.getName() });
026: }
027:
028: public Object getAttribute(ObjectName on, String attrName)
029: throws ReflectionException, IOException,
030: InstanceNotFoundException, MBeanException {
031: return invokeMethod("getAttribute",
032: new Object[] { on, attrName }, new String[] {
033: 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) invokeMethod("getAttributes",
041: new Object[] { on, attrNames }, new String[] {
042: ObjectName.class.getName(),
043: String[].class.getName() });
044: }
045:
046: public String getDefaultDomain() throws ReflectionException,
047: IOException, InstanceNotFoundException, MBeanException,
048: AttributeNotFoundException {//getDefaultDomain
049: return (String) invokeMethod("getDefaultDomain", new Object[0],
050: new String[0]);
051: }
052:
053: public Integer getMBeanCount() throws ReflectionException,
054: IOException, InstanceNotFoundException, MBeanException,
055: AttributeNotFoundException {//getMBeanCount
056: return (Integer) invokeMethod("getMBeanCount", new Object[0],
057: new String[0]);
058: }
059:
060: public MBeanInfo getMBeanInfo(ObjectName on)
061: throws ReflectionException, IOException,
062: InstanceNotFoundException, MBeanException {
063: return (MBeanInfo) invokeMethod("getMBeanInfo",
064: new Object[] { on }, new String[] { ObjectName.class
065: .getName() });
066: }
067:
068: public Boolean isInstanceOf(ObjectName on, String className)
069: throws ReflectionException, IOException,
070: InstanceNotFoundException, MBeanException {
071: return (Boolean) invokeMethod("isInstanceOf", new Object[] {
072: on, className }, new String[] {
073: ObjectName.class.getName(), String.class.getName() });
074: }
075:
076: public Boolean isRegistered(ObjectName on)
077: throws ReflectionException, IOException,
078: InstanceNotFoundException, MBeanException {
079: return (Boolean) invokeMethod("isRegistered",
080: new Object[] { on }, new String[] { ObjectName.class
081: .getName() });
082: }
083:
084: public void removeNotificationListener(ObjectName on,
085: NotificationListener listener) throws ReflectionException,
086: IOException, InstanceNotFoundException, MBeanException {
087: invokeMethod("removeNotificationListener", new Object[] { on,
088: listener }, new String[] { ObjectName.class.getName(),
089: NotificationListener.class.getName() });
090: }
091:
092: public void setAttribute(ObjectName on, Attribute attr)
093: throws ReflectionException, IOException,
094: InstanceNotFoundException, MBeanException {
095: invokeMethod("setAttribute", new Object[] { on, attr },
096: new String[] { ObjectName.class.getName(),
097: Attribute.class.getName() });
098: }
099:
100: public AttributeList setAttributes(ObjectName on,
101: AttributeList attrs) throws ReflectionException,
102: IOException, InstanceNotFoundException, MBeanException {
103: return (AttributeList) invokeMethod("setAttributes",
104: new Object[] { on, attrs }, new String[] {
105: ObjectName.class.getName(),
106: AttributeList.class.getName() });
107: }
108:
109: public void unregisterMBean(ObjectName on)
110: throws ReflectionException, IOException,
111: InstanceNotFoundException, MBeanException {
112: invokeMethod("unregisterMBean", new Object[] { on },
113: new String[] { ObjectName.class.getName() });
114: }
115:
116: public void disconnect() throws ReflectionException, IOException,
117: InstanceNotFoundException, MBeanException {
118: getMBeanServerConnection().invoke(
119: getObjectName(),
120: "disconnect",
121: new Object[] { command.getOption("proxy-type"),
122: command.getOption("instance") },
123: new String[] { STR_CLASS_NAME, STR_CLASS_NAME });
124: }
125:
126: public void connect() throws ReflectionException, IOException,
127: InstanceNotFoundException, MBeanException {
128: getMBeanServerConnection().invoke(
129: getObjectName(),
130: "connect",
131: new Object[] { command.getOption("proxy-type"),
132: command.getOption("instance") },
133: new String[] { STR_CLASS_NAME, STR_CLASS_NAME });
134:
135: }
136:
137: public SRACommandClient(MonitoringBaseCommand command) {
138: this .command = command;
139: }
140:
141: public Set queryNames(ObjectName on, QueryExp expr)
142: throws ReflectionException, IOException,
143: InstanceNotFoundException, MBeanException {
144: return (Set) invokeMethod("queryNames",
145: new Object[] { on, expr }, new String[] {
146: ObjectName.class.getName(),
147: QueryExp.class.getName() });
148: }
149:
150: private Object invokeMethod(String methodName, Object[] params,
151: String[] types) throws ReflectionException,
152: InstanceNotFoundException, IOException, MBeanException {
153: int length = types.length;
154: Object[] newParams = new Object[length + 3];
155: String[] signatures = new String[length + 3];
156: newParams[0] = methodName;
157: newParams[1] = command.getOption("proxy-type");
158: newParams[2] = command.getOption("instance");
159: signatures[0] = signatures[1] = signatures[2] = STR_CLASS_NAME;
160: System.arraycopy(params, 0, newParams, 3, length);
161: System.arraycopy(types, 0, signatures, 3, length);
162: return super.invoke(null, null, newParams, signatures);
163: }
164:
165: }
|