ManagementReprImpl.java

00001 
00025 package org.objectweb.jonas.jmx;
00026 
00027 import java.util.Properties;
00028 import java.util.Set;
00029 
00030 import javax.management.Attribute;
00031 import javax.management.AttributeList;
00032 import javax.management.MBeanException;
00033 import javax.management.MBeanInfo;
00034 import javax.management.ObjectName;
00035 import javax.management.ReflectionException;
00036 import javax.management.RuntimeErrorException;
00037 import javax.management.RuntimeMBeanException;
00038 import javax.management.RuntimeOperationsException;
00039 import javax.naming.Context;
00040 
00041 import org.objectweb.jonas.common.Log;
00042 import org.objectweb.util.monolog.api.BasicLevel;
00043 import org.objectweb.util.monolog.api.Logger;
00044 
00049 public class ManagementReprImpl implements ManagementRepr
00050 {
00051 
00052     static private Logger logger = null;
00053 
00054     protected ManagementReprImpl()
00055     {
00056         logger = Log.getLogger("org.objectweb.jonas.jmx");
00057         logger.log(BasicLevel.DEBUG, "Management Representativ created for jonasAdmin");
00058     }
00059 
00063     public boolean isRegistered(ObjectName on) {
00064         try {
00065             return ConnectorFactory.getRMIConnector().isRegistered(on);
00066         } catch (Exception e) {
00067             return false;
00068         }
00069     }
00070 
00076     public Object getAttribute(ObjectName on, String attribute)
00077         throws ManagementException {
00078 
00079         try {
00080             return ConnectorFactory.getRMIConnector().getAttribute(on, attribute);
00081         } catch (Exception e) {
00082             throw new ManagementException("Error while getting attribute " + attribute + ": "
00083                                               + e.getClass().getName(), e);
00084         }
00085     }
00086 
00092     public AttributeList getAttributes(ObjectName on, String[] attributes)
00093         throws ManagementException {
00094 
00095         try {
00096             return ConnectorFactory.getRMIConnector().getAttributes(on, attributes);
00097         } catch (Exception e) {
00098             throw new ManagementException("Error while getting attributes: "
00099                                           + e.getClass().getName(), e);
00100         }
00101     }
00102 
00108         public void setAttribute(ObjectName on, String attribute, Object value)
00109             throws ManagementException {
00110 
00111             //Logger logger = Log.getLogger("org.objectweb.jonas.jmx");
00112             if(logger.isLoggable(BasicLevel.DEBUG))
00113                 logger.log(BasicLevel.DEBUG
00114                            , "Set Attribute called, on " + on.toString() + " to change attribute " + attribute
00115                            + " value to " + (String) value.toString());
00116             try {
00117                 ConnectorFactory.getRMIConnector().setAttribute(on, new Attribute(attribute, value));
00118             } catch (Exception e) {
00119                 throw new ManagementException("Error while setting attribute " + attribute + ": "
00120                                                       + e.getClass().getName(), e);
00121             }
00122         }
00123 
00129     public AttributeList setAttributes(ObjectName on, AttributeList attributes)
00130         throws ManagementException {
00131 
00132         try {
00133             return ConnectorFactory.getRMIConnector().setAttributes(on, attributes);
00134         } catch (Exception e) {
00135             throw new ManagementException("Error while setting attributes: "
00136                                           + e.getClass().getName(), e);
00137         }
00138     }
00139 
00143     public Object invoke(ObjectName on, String operation, Object[] param, String[] signature)
00144             throws ManagementException {
00145 
00146         try {
00147             return ConnectorFactory.getRMIConnector().invoke(on, operation, param, signature);
00148         }
00149         catch (Exception e) {
00150             String message = "";
00151             String targetExcName = null;
00152             Throwable exc = null;
00153             if (e instanceof MBeanException ||
00154                 e instanceof ReflectionException ||
00155                 e instanceof RuntimeMBeanException ||
00156                 e instanceof RuntimeOperationsException ||
00157                 e instanceof RuntimeErrorException) {
00158 
00159                 Exception targetExc = null;
00160                 if (e instanceof MBeanException)                {
00161                     targetExc = ((MBeanException) e).getTargetException();
00162                 }
00163                 else if (e instanceof ReflectionException) {
00164                     targetExc = ((ReflectionException) e).getTargetException();
00165                 }
00166                 else if (e instanceof RuntimeMBeanException) {
00167                     targetExc = ((RuntimeMBeanException) e).getTargetException();
00168                 }
00169                 else if (e instanceof RuntimeOperationsException) {
00170                     targetExc = ((RuntimeOperationsException) e).getTargetException();
00171                 }
00172                 else if (e instanceof RuntimeErrorException) {
00173                     Error atargetExc = ((RuntimeErrorException) e).getTargetError();
00174                     targetExc = new Exception(atargetExc.getMessage());
00175                 }
00176                 targetExcName = targetExc.toString();
00177                 exc = targetExc;
00178             }
00179             else {
00180                 exc = e;
00181             }
00182             if(logger.isLoggable(BasicLevel.DEBUG)) {
00183                 logger.log(BasicLevel.DEBUG
00184                     , "Exception ----[ " + e.toString() + " while invoking operation " + operation +
00185                     " on MBean " + on.toString() + " ]-------");
00186                 if (targetExcName != null) {
00187                     logger.log(BasicLevel.DEBUG, "-------[ Embedded error : ]-------");
00188                     logger.log(BasicLevel.DEBUG, "-------[ " + targetExcName + " ]-------");
00189                 }
00190             }
00191 
00192             throw new ManagementException(message, exc);
00193         }
00194     }
00195 
00199         public java.util.Set queryNames(ObjectName on)
00200             throws ManagementException
00201             {
00202                 try
00203                     {
00204                         return (java.util.Set) ConnectorFactory.getRMIConnector().queryNames(on, null);
00205                     }
00206                 catch (Exception e)
00207                     {
00208                         throw new ManagementException("Error while getting MBeans names: " + e.getClass().getName()
00209                                                       , e);
00210                     }
00211             }
00212 
00217         public MBeanInfo getMBeanInfo(ObjectName name)
00218             throws ManagementException
00219             {
00220                 try
00221                     {
00222                         return (MBeanInfo) ConnectorFactory.getRMIConnector().getMBeanInfo(name);
00223                     }
00224                 catch (Exception e)
00225                     {
00226                         throw new ManagementException("Error while getting MBean info: " + e.getClass().getName()
00227                                                       , e);
00228                     }
00229             }
00230 
00235         public Context getContext()
00236             throws javax.naming.NamingException
00237             {
00238                 return ConnectorFactory.getContext();
00239             }
00240 
00245         public String getCurrentRMIConnectorName()
00246             {
00247                 return ConnectorFactory.getCurrentRMIConnectorName();
00248             }
00249 
00253         public void setCurrentRMIConnectorName(String name)
00254             throws Exception
00255             {
00256                 ConnectorFactory.setCurrentRMIConnectorName(name);
00257             }
00258 
00262         public void resetCurrentRMIConnectorName()
00263             {
00264                 ConnectorFactory.resetCurrentRMIConnectorName();
00265             }
00266 
00270         public Set getRMIConnectorsNames()
00271             throws javax.naming.NamingException
00272             {
00273                 return ConnectorFactory.getRMIConnectorsNames();
00274             }
00275 
00279         public String getJonasNamingServiceURL()
00280             {
00281                 return ConnectorFactory.getJonasNamingServiceURL();
00282             }
00283 
00287         public void setJonasNamingServiceURL(String url)
00288             throws javax.naming.NamingException
00289             {
00290                 ConnectorFactory.setJonasNamingServiceURL(url);
00291             }
00292 
00297         public void setNamingEnvCtx(Properties env) throws javax.naming.NamingException {
00298             ConnectorFactory.setNamingEnvCtx(env);
00299         }
00300 }

Generated on Tue Feb 15 15:05:17 2005 for JOnAS by  doxygen 1.3.9.1