1 25 package org.objectweb.jonas.jmx; 26 27 import java.util.HashSet ; 28 import java.util.Properties ; 29 import java.util.Set ; 30 31 import javax.management.Attribute ; 32 import javax.management.AttributeList ; 33 import javax.management.MBeanException ; 34 import javax.management.MBeanInfo ; 35 import javax.management.MBeanServerConnection ; 36 import javax.management.ObjectName ; 37 import javax.management.ReflectionException ; 38 import javax.management.RuntimeErrorException ; 39 import javax.management.RuntimeMBeanException ; 40 import javax.management.RuntimeOperationsException ; 41 import javax.naming.Context ; 42 43 import org.objectweb.jonas.common.Log; 44 import org.objectweb.util.monolog.api.BasicLevel; 45 import org.objectweb.util.monolog.api.Logger; 46 47 51 public class ManagementReprImplJSR160 implements ManagementRepr { 52 53 56 private static Logger logger = null; 57 61 private MBeanServerConnection mbeanServerConnection = null; 62 63 66 protected ManagementReprImplJSR160() { 67 logger = Log.getLogger("org.objectweb.jonas.jmx"); 68 if (logger.isLoggable(BasicLevel.DEBUG)) { 69 logger.log(BasicLevel.DEBUG, "Management Representativ based on JSR160 created for jonasAdmin"); 70 } 71 } 72 73 77 public boolean isRegistered(ObjectName on) { 78 try { 79 return mbeanServerConnection.isRegistered(on); 80 } catch (Exception e) { 81 return false; 82 } 83 } 84 85 91 public Object getAttribute(ObjectName on, String attribute) 92 throws ManagementException { 93 94 try { 95 return mbeanServerConnection.getAttribute(on, attribute); 96 } catch (Exception e) { 97 throw new ManagementException("Error while getting attribute " + attribute + ": " 98 + e.getClass().getName(), e); 99 } 100 } 101 102 108 public AttributeList getAttributes(ObjectName on, String [] attributes) 109 throws ManagementException { 110 111 try { 112 return mbeanServerConnection.getAttributes(on, attributes); 113 } catch (Exception e) { 114 throw new ManagementException("Error while getting attributes: " 115 + e.getClass().getName(), e); 116 } 117 } 118 119 125 public void setAttribute(ObjectName on, String attribute, Object value) 126 throws ManagementException { 127 if(logger.isLoggable(BasicLevel.DEBUG)) { 128 logger.log(BasicLevel.DEBUG 129 , "Set Attribute called, on " + on.toString() + " to change attribute " + attribute 130 + " value to " + (String ) value.toString()); 131 } 132 133 try { 134 mbeanServerConnection.setAttribute(on, new Attribute (attribute, value)); 135 } catch (Exception e) { 136 throw new ManagementException("Error while setting attribute " + attribute + ": " 137 + e.getClass().getName(), e); 138 } 139 } 140 141 147 public AttributeList setAttributes(ObjectName on, AttributeList attributes) 148 throws ManagementException { 149 150 try { 151 return mbeanServerConnection.setAttributes(on, attributes); 152 } catch (Exception e) { 153 throw new ManagementException("Error while setting attributes: " 154 + e.getClass().getName(), e); 155 } 156 } 157 158 162 public Object invoke(ObjectName on, String operation, Object [] param, String [] signature) 163 throws ManagementException { 164 165 try { 166 return mbeanServerConnection.invoke(on, operation, param, signature); 167 } catch (Exception e) { 168 String message = ""; 169 String targetExcName = null; 170 Throwable exc = null; 171 if (e instanceof MBeanException || 172 e instanceof ReflectionException || 173 e instanceof RuntimeMBeanException || 174 e instanceof RuntimeOperationsException || 175 e instanceof RuntimeErrorException ) { 176 177 Exception targetExc = null; 178 if (e instanceof MBeanException ) { 179 targetExc = ((MBeanException ) e).getTargetException(); 180 } 181 else if (e instanceof ReflectionException ) { 182 targetExc = ((ReflectionException ) e).getTargetException(); 183 } 184 else if (e instanceof RuntimeMBeanException ) { 185 targetExc = ((RuntimeMBeanException ) e).getTargetException(); 186 } 187 else if (e instanceof RuntimeOperationsException ) { 188 targetExc = ((RuntimeOperationsException ) e).getTargetException(); 189 } 190 else if (e instanceof RuntimeErrorException ) { 191 Error atargetExc = ((RuntimeErrorException ) e).getTargetError(); 192 targetExc = new Exception (atargetExc.getMessage()); 193 } 194 targetExcName = targetExc.toString(); 195 exc = targetExc; 196 } 197 else { 198 exc = e; 199 } 200 if(logger.isLoggable(BasicLevel.DEBUG)) { 201 logger.log(BasicLevel.DEBUG 202 , "Exception ----[ " + e.toString() + " while invoking operation " + operation + 203 " on MBean " + on.toString() + " ]-------"); 204 if (targetExcName != null) { 205 logger.log(BasicLevel.DEBUG, "-------[ Embedded error : ]-------"); 206 logger.log(BasicLevel.DEBUG, "-------[ " + targetExcName + " ]-------"); 207 } 208 } 209 210 throw new ManagementException(message, exc); 211 } 212 } 213 214 218 public java.util.Set queryNames(ObjectName on) 219 throws ManagementException { 220 try { 221 return (java.util.Set ) mbeanServerConnection.queryNames(on, null); 222 } catch (Exception e) { 223 throw new ManagementException("Error while getting MBeans names: " + e.getClass().getName() 224 , e); 225 } 226 } 227 228 233 public MBeanInfo getMBeanInfo(ObjectName name) 234 throws ManagementException { 235 try { 236 return (MBeanInfo ) mbeanServerConnection.getMBeanInfo(name); 237 } catch (Exception e) { 238 throw new ManagementException("Error while getting MBean info: " + e.getClass().getName() 239 , e); 240 } 241 } 242 243 248 public Context getContext() throws javax.naming.NamingException { 249 return null; 250 } 251 252 256 public String getCurrentRMIConnectorName() { 257 return "jonas"; 258 } 259 260 263 public void setCurrentRMIConnectorName(String name) throws Exception { 264 ; 265 } 266 267 270 public void resetCurrentRMIConnectorName() { 271 ; 272 } 273 274 279 public Set getRMIConnectorsNames() throws javax.naming.NamingException { 280 HashSet res = new HashSet (); 281 res.add("jonas"); 282 return res; 283 } 284 285 289 public String getJonasNamingServiceURL() { 290 return "url"; 291 } 292 293 297 public void setJonasNamingServiceURL(String url) throws javax.naming.NamingException { 298 ; 299 } 300 301 305 public void setNamingEnvCtx(Properties env) throws javax.naming.NamingException { 306 ; 307 } 308 311 public MBeanServerConnection getMBeanServerConnection() { 312 return mbeanServerConnection; 313 } 314 317 public void setMBeanServerConnection( 318 MBeanServerConnection mbeanServerConnection) { 319 this.mbeanServerConnection = mbeanServerConnection; 320 } 321 } 322 | Popular Tags |