1 25 package org.objectweb.jonas.jmx; 26 27 import java.util.Properties ; 28 import java.util.Set ; 29 30 import javax.management.Attribute ; 31 import javax.management.AttributeList ; 32 import javax.management.MBeanException ; 33 import javax.management.MBeanInfo ; 34 import javax.management.ObjectName ; 35 import javax.management.ReflectionException ; 36 import javax.management.RuntimeErrorException ; 37 import javax.management.RuntimeMBeanException ; 38 import javax.management.RuntimeOperationsException ; 39 import javax.naming.Context ; 40 41 import org.objectweb.jonas.common.Log; 42 import org.objectweb.util.monolog.api.BasicLevel; 43 import org.objectweb.util.monolog.api.Logger; 44 45 49 public class ManagementReprImpl implements ManagementRepr 50 { 51 52 static private Logger logger = null; 53 54 protected ManagementReprImpl() 55 { 56 logger = Log.getLogger("org.objectweb.jonas.jmx"); 57 if (logger.isLoggable(BasicLevel.DEBUG)) { 58 logger.log(BasicLevel.DEBUG, "Management Representativ created for jonasAdmin"); 59 } 60 } 61 62 65 public boolean isRegistered(ObjectName on) { 66 try { 67 return ConnectorFactory.getRMIConnector().isRegistered(on); 68 } catch (Exception e) { 69 return false; 70 } 71 } 72 73 78 public Object getAttribute(ObjectName on, String attribute) 79 throws ManagementException { 80 81 try { 82 return ConnectorFactory.getRMIConnector().getAttribute(on, attribute); 83 } catch (Exception e) { 84 throw new ManagementException("Error while getting attribute " + attribute + " from " + on + ": " 85 + e.getClass().getName(), e); 86 } 87 } 88 89 94 public AttributeList getAttributes(ObjectName on, String [] attributes) 95 throws ManagementException { 96 97 try { 98 return ConnectorFactory.getRMIConnector().getAttributes(on, attributes); 99 } catch (Exception e) { 100 throw new ManagementException("Error while getting attributes: " 101 + e.getClass().getName(), e); 102 } 103 } 104 105 110 public void setAttribute(ObjectName on, String attribute, Object value) 111 throws ManagementException { 112 113 if(logger.isLoggable(BasicLevel.DEBUG)) 115 logger.log(BasicLevel.DEBUG 116 , "Set Attribute called, on " + on.toString() + " to change attribute " + attribute 117 + " value to " + (String ) value.toString()); 118 try { 119 ConnectorFactory.getRMIConnector().setAttribute(on, new Attribute (attribute, value)); 120 } catch (Exception e) { 121 throw new ManagementException("Error while setting attribute " + attribute + ": " 122 + e.getClass().getName(), e); 123 } 124 } 125 126 131 public AttributeList setAttributes(ObjectName on, AttributeList attributes) 132 throws ManagementException { 133 134 try { 135 return ConnectorFactory.getRMIConnector().setAttributes(on, attributes); 136 } catch (Exception e) { 137 throw new ManagementException("Error while setting attributes: " 138 + e.getClass().getName(), e); 139 } 140 } 141 142 145 public Object invoke(ObjectName on, String operation, Object [] param, String [] signature) 146 throws ManagementException { 147 148 try { 149 return ConnectorFactory.getRMIConnector().invoke(on, operation, param, signature); 150 } 151 catch (Exception e) { 152 String message = ""; 153 String targetExcName = null; 154 Throwable exc = null; 155 if (e instanceof MBeanException || 156 e instanceof ReflectionException || 157 e instanceof RuntimeMBeanException || 158 e instanceof RuntimeOperationsException || 159 e instanceof RuntimeErrorException ) { 160 161 Exception targetExc = null; 162 if (e instanceof MBeanException ) { 163 targetExc = ((MBeanException ) e).getTargetException(); 164 } 165 else if (e instanceof ReflectionException ) { 166 targetExc = ((ReflectionException ) e).getTargetException(); 167 } 168 else if (e instanceof RuntimeMBeanException ) { 169 targetExc = ((RuntimeMBeanException ) e).getTargetException(); 170 } 171 else if (e instanceof RuntimeOperationsException ) { 172 targetExc = ((RuntimeOperationsException ) e).getTargetException(); 173 } 174 else if (e instanceof RuntimeErrorException ) { 175 Error atargetExc = ((RuntimeErrorException ) e).getTargetError(); 176 targetExc = new Exception (atargetExc.getMessage()); 177 } 178 targetExcName = targetExc.toString(); 179 exc = targetExc; 180 } 181 else { 182 exc = e; 183 } 184 if(logger.isLoggable(BasicLevel.DEBUG)) { 185 logger.log(BasicLevel.DEBUG 186 , "Exception ----[ " + e.toString() + " while invoking operation " + operation + 187 " on MBean " + on.toString() + " ]-------"); 188 if (targetExcName != null) { 189 logger.log(BasicLevel.DEBUG, "-------[ Embedded error : ]-------"); 190 logger.log(BasicLevel.DEBUG, "-------[ " + targetExcName + " ]-------"); 191 } 192 } 193 194 throw new ManagementException(message, exc); 195 } 196 } 197 198 201 public java.util.Set queryNames(ObjectName on) 202 throws ManagementException 203 { 204 try 205 { 206 return (java.util.Set ) ConnectorFactory.getRMIConnector().queryNames(on, null); 207 } 208 catch (Exception e) 209 { 210 throw new ManagementException("Error while getting MBeans names: " + e.getClass().getName() 211 , e); 212 } 213 } 214 215 219 public MBeanInfo getMBeanInfo(ObjectName name) 220 throws ManagementException 221 { 222 try 223 { 224 return (MBeanInfo ) ConnectorFactory.getRMIConnector().getMBeanInfo(name); 225 } 226 catch (Exception e) 227 { 228 throw new ManagementException("Error while getting MBean info: " + e.getClass().getName() 229 , e); 230 } 231 } 232 233 237 public Context getContext() 238 throws javax.naming.NamingException 239 { 240 return ConnectorFactory.getContext(); 241 } 242 243 247 public String getCurrentRMIConnectorName() 248 { 249 return ConnectorFactory.getCurrentRMIConnectorName(); 250 } 251 252 255 public void setCurrentRMIConnectorName(String name) 256 throws Exception 257 { 258 ConnectorFactory.setCurrentRMIConnectorName(name); 259 } 260 261 264 public void resetCurrentRMIConnectorName() 265 { 266 ConnectorFactory.resetCurrentRMIConnectorName(); 267 } 268 269 272 public Set getRMIConnectorsNames() 273 throws javax.naming.NamingException 274 { 275 return ConnectorFactory.getRMIConnectorsNames(); 276 } 277 278 281 public String getJonasNamingServiceURL() 282 { 283 return ConnectorFactory.getJonasNamingServiceURL(); 284 } 285 286 289 public void setJonasNamingServiceURL(String url) 290 throws javax.naming.NamingException 291 { 292 ConnectorFactory.setJonasNamingServiceURL(url); 293 } 294 295 299 public void setNamingEnvCtx(Properties env) throws javax.naming.NamingException { 300 ConnectorFactory.setNamingEnvCtx(env); 301 } 302 } 303 | Popular Tags |