1 8 13 14 package org.webjmx.adapter; 15 16 import java.io.*; 17 import java.util.*; 18 import javax.management.*; 19 20 import mx4j.connector.*; 21 import mx4j.connector.rmi.jrmp.*; 22 23 31 public class RMIAdapter 32 implements JMXServiceAdapter, MBeanServer 33 { 34 protected String jndiName; 35 protected Hashtable environment = new Hashtable(); 36 protected RemoteMBeanServer server; 37 38 39 public void initialize(List params) 40 throws Exception 41 { 42 if(params.size() < 1) 43 throw new Exception ("missing host name"); 44 45 jndiName = (String )params.get(0); 46 47 javax.naming.Context ctx = new javax.naming.InitialContext (); 48 environment.putAll(ctx.getEnvironment()); 49 environment.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory"); 50 51 for(int i = 1; i < params.size(); i += 2) 52 { 53 String name = (String )params.get(i); 54 String value = (String )params.get(i+1); 55 environment.put(name, value); 56 } 57 58 if(Boolean.getBoolean(org.webjmx.tags.JMXTaglibConstants.DEBUG_PROP)) 59 { 60 System.out.println("JRMPConnector environment ..."); 61 Enumeration e = environment.keys(); 62 while(e.hasMoreElements()) 63 { 64 String s = (String )e.nextElement(); 65 System.out.println(s +" : " +environment.get(s)); 66 } 67 System.out.println("end JRMPConnector environment."); 68 System.out.println("InitialContext bindings ..."); 69 javax.naming.NamingEnumeration ne = ctx.listBindings(""); 70 while(ne.hasMore()) 71 { 72 javax.naming.Binding b = (javax.naming.Binding )ne.next(); 73 System.out.println(b.getName() + " : " +b.getObject()); 74 } 75 System.out.println("end InitialContext bindings"); 76 } 77 } 78 79 public void connect() throws Exception 80 { 81 JRMPConnector connector = new JRMPConnector(); 82 connector.connect(jndiName, environment); 83 server = connector.getRemoteMBeanServer(); 84 } 85 86 public Object instantiate(String str, ObjectName objectName) 87 throws ReflectionException, MBeanException, InstanceNotFoundException 88 { 89 throw new MBeanException(null, "not supported for this service"); 90 } 91 92 public boolean isInstanceOf(ObjectName objectName, String str) 93 throws InstanceNotFoundException 94 { 95 return server.isInstanceOf(objectName, str); 96 } 97 98 public ObjectInstance registerMBean(Object obj, ObjectName objectName) 99 throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException 100 { 101 return server.registerMBean(obj, objectName); 102 } 103 104 public String getDefaultDomain() 105 { 106 return server.getDefaultDomain(); 107 } 108 109 public MBeanInfo getMBeanInfo(ObjectName objectName) 110 throws InstanceNotFoundException, IntrospectionException, ReflectionException 111 { 112 return server.getMBeanInfo(objectName); 113 } 114 115 public ObjectInstance getObjectInstance(ObjectName objectName) 116 throws InstanceNotFoundException 117 { 118 return server.getObjectInstance(objectName); 119 } 120 121 public Object instantiate(String str) 122 throws ReflectionException, MBeanException 123 { 124 throw new MBeanException(null, "not supported for this service"); 125 } 126 127 public boolean isRegistered(ObjectName objectName) 128 { 129 return server.isRegistered(objectName); 130 } 131 132 public void addNotificationListener(ObjectName objectName, NotificationListener notificationListener, 133 NotificationFilter notificationFilter, Object obj) 134 throws InstanceNotFoundException 135 { 136 server.addNotificationListener(objectName, notificationListener, notificationFilter, obj); 137 } 138 139 public void addNotificationListener(ObjectName objectName, ObjectName objectName1, 140 NotificationFilter notificationFilter, Object obj) 141 throws InstanceNotFoundException 142 { 143 throw new InstanceNotFoundException("not supported for this service"); 144 } 145 146 public ObjectInstance createMBean(String str, ObjectName objectName, ObjectName objectName2) 147 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException 148 { 149 return server.createMBean(str, objectName, objectName2); 150 } 151 152 public ObjectInstance createMBean(String str, ObjectName objectName) 153 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException 154 { 155 return server.createMBean(str, objectName); 156 } 157 158 public Object getAttribute(ObjectName objectName, String str) 159 throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException 160 { 161 return server.getAttribute(objectName, str); 162 } 163 164 public ObjectInstance createMBean(String str, ObjectName objectName, Object [] obj, String [] str3) 165 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException 166 { 167 return server.createMBean(str, objectName, obj, str3); 168 } 169 170 public ObjectInstance createMBean(String str, ObjectName objectName, ObjectName objectName2, Object [] obj, String [] str4) 171 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException 172 { 173 return server.createMBean(str, objectName, objectName2, obj, str4); 174 } 175 176 public void setAttribute(ObjectName objectName, Attribute attribute) 177 throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException 178 { 179 server.setAttribute(objectName, attribute); 180 } 181 182 public Object instantiate(String str, ObjectName objectName, Object [] obj, String [] str3) 183 throws ReflectionException, MBeanException, InstanceNotFoundException 184 { 185 throw new MBeanException(null, "not supported by this service"); 186 } 187 188 public Object instantiate(String str, Object [] obj, String [] str2) 189 throws ReflectionException, MBeanException 190 { 191 throw new MBeanException(null, "not supported by this service"); 192 } 193 194 public ObjectInputStream deserialize(String str, ObjectName objectName, byte[] values) 195 throws InstanceNotFoundException, OperationsException, ReflectionException 196 { 197 throw new OperationsException("not supported by this service"); 198 } 199 200 public ObjectInputStream deserialize(String str, byte[] values) 201 throws OperationsException, ReflectionException 202 { 203 throw new OperationsException("not supported by this service"); 204 } 205 206 public Set queryMBeans(ObjectName objectName, QueryExp queryExp) 207 { 208 return server.queryMBeans(objectName, queryExp); 209 } 210 211 public AttributeList setAttributes(ObjectName objectName, AttributeList attributeList) 212 throws InstanceNotFoundException, ReflectionException 213 { 214 return server.setAttributes(objectName, attributeList); 215 } 216 217 public Integer getMBeanCount() 218 { 219 return server.getMBeanCount(); 220 } 221 222 public Object invoke(ObjectName objectName, String str, Object [] obj, String [] str3) 223 throws InstanceNotFoundException, MBeanException, ReflectionException 224 { 225 return server.invoke(objectName, str, obj, str3); 226 } 227 228 public ObjectInputStream deserialize(ObjectName objectName, byte[] values) 229 throws InstanceNotFoundException, OperationsException 230 { 231 throw new OperationsException("not supported by this service"); 232 } 233 234 public AttributeList getAttributes(ObjectName objectName, String [] str) 235 throws InstanceNotFoundException, ReflectionException 236 { 237 return server.getAttributes(objectName, str); 238 } 239 240 public Set queryNames(ObjectName objectName, QueryExp queryExp) 241 { 242 return server.queryNames(objectName, queryExp); 243 } 244 245 public void unregisterMBean(ObjectName objectName) 246 throws InstanceNotFoundException, MBeanRegistrationException 247 { 248 server.unregisterMBean(objectName); 249 } 250 251 public void removeNotificationListener(ObjectName objectName, ObjectName objectName1) 252 throws InstanceNotFoundException, ListenerNotFoundException 253 { 254 throw new ListenerNotFoundException("not supported by this service"); 255 } 256 257 public void removeNotificationListener(ObjectName objectName, NotificationListener notificationListener) 258 throws InstanceNotFoundException, ListenerNotFoundException 259 { 260 server.removeNotificationListener(objectName, notificationListener, null, null); 261 } 262 } 263 | Popular Tags |