Package org.apache.felix.mosgi.jmx.agent.mx4j.log

Examples of org.apache.felix.mosgi.jmx.agent.mx4j.log.Logger


      return true;
   }

   private boolean isMBeanTypeCompliant(MBeanMetaData metadata)
   {
      Logger logger = getLogger();

      if (metadata.standard && metadata.dynamic)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is both standard and dynamic");
         return false;
      }
      if (!metadata.standard && !metadata.dynamic)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not standard nor dynamic");
         return false;
      }

      return true;
   }
View Full Code Here


      return true;
   }

   private boolean isMBeanInfoCompliant(MBeanMetaData metadata)
   {
      Logger logger = getLogger();

      if (metadata.info == null)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBeanInfo is null");
         return false;
      }
      return true;
   }
View Full Code Here

      }
   }

   private MBeanInfo getDynamicMBeanInfo(MBeanMetaData metadata)
   {
      Logger logger = getLogger();

      MBeanInfo info = null;
     
    try {
     info = ((DynamicMBean) metadata.mbean).getMBeanInfo();
    } catch (Exception x) {
       if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("getMBeanInfo threw: " + x.toString());
    }
   
      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Dynamic MBeanInfo is: " + info);

      if (info == null)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBeanInfo cannot be null");
         return null;
      }

      return info;
   }
View Full Code Here

   private MBeanDescription createMBeanDescription(MBeanMetaData metadata)
   {
      // This is a non-standard extension

      Logger logger = getLogger();
      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Looking for standard MBean description...");

      Class mbeanClass = metadata.mbean.getClass();

      for (Class cls = mbeanClass; cls != null; cls = cls.getSuperclass())
      {
         String clsName = cls.getName();
         if (clsName.startsWith("java.")) break;

         // Use full qualified name only
         String descrClassName = clsName + "MBeanDescription";
         // Try to load the class
         try
         {
            Class descrClass = null;
            ClassLoader loader = metadata.classloader;
            if (loader != null)
            {
               // Optimize lookup of the description class in case of MLets: we lookup the description class
               // only in the classloader of the mbean, not in the whole CLR (since MLets delegates to the CLR)
               if (loader.getClass() == MLet.class)
                  descrClass = ((MLet)loader).loadClass(descrClassName, null);
               else
                  descrClass = loader.loadClass(descrClassName);
            }
            else
            {
               descrClass = Class.forName(descrClassName, false, null);
            }

            Object descrInstance = descrClass.newInstance();
            if (descrInstance instanceof MBeanDescription)
            {
               MBeanDescription description = (MBeanDescription)descrInstance;
               if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Found provided standard MBean description: " + description);
               return description;
            }
         }
         catch (ClassNotFoundException ignored)
         {
         }
         catch (InstantiationException ignored)
         {
         }
         catch (IllegalAccessException ignored)
         {
         }
      }

      MBeanDescription description = DEFAULT_DESCRIPTION;
      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Cannot find standard MBean description, using default: " + description);
      return description;
   }
View Full Code Here

      return (MBeanOperationInfo[])operations.toArray(new MBeanOperationInfo[operations.size()]);
   }

   private MBeanAttributeInfo[] createMBeanAttributeInfo(MBeanMetaData metadata, MBeanDescription description)
   {
      Logger logger = getLogger();

      HashMap attributes = new HashMap();
      HashMap getterNames = new HashMap();

      Method[] methods = metadata.management.getMethods();
      for (int j = 0; j < methods.length; ++j)
      {
         Method method = methods[j];
         if (Utils.isAttributeGetter(method))
         {
            String name = method.getName();
            boolean isIs = name.startsWith("is");

            String attribute = null;
            if (isIs)
               attribute = name.substring(2);
            else
               attribute = name.substring(3);

            String descr = description == null ? null : description.getAttributeDescription(attribute);

            MBeanAttributeInfo info = (MBeanAttributeInfo)attributes.get(attribute);

            if (info != null)
            {
               // JMX spec does not allow overloading attributes.
               // If an attribute with the same name already exists the MBean is not compliant
               if (!info.getType().equals(method.getReturnType().getName()))
               {
                  if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not compliant: has overloaded attribute " + attribute);
                  return null;
               }
               else
               {
                  // They return the same value,
                  if (getterNames.get(name) != null)
                  {
                    // This is the case of an attribute being present in multiple interfaces
                    // Ignore all but the first, since they resolve to the same method anyways
                   continue;                    
                  }
                 
          // there is a chance that one is a get-getter and one is a is-getter
          // for a boolean attribute. In this case, the MBean is not compliant.
                  if (info.isReadable())
                  {
                     if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not compliant: has overloaded attribute " + attribute);
                     return null;
                  }

                  // MBeanAttributeInfo is already present due to a setter method, just update its readability
                  info = new MBeanAttributeInfo(attribute, info.getType(), info.getDescription(), true, info.isWritable(), isIs);
               }
            }
            else
            {
               info = new MBeanAttributeInfo(attribute, method.getReturnType().getName(), descr, true, false, isIs);
            }

            // Replace if exists
            attributes.put(attribute, info);
      getterNames.put(name,method);
         }
         else if (Utils.isAttributeSetter(method))
         {
            String name = method.getName();
            String attribute = name.substring(3);

            String descr = description == null ? null : description.getAttributeDescription(attribute);

            MBeanAttributeInfo info = (MBeanAttributeInfo)attributes.get(attribute);

            if (info != null)
            {
               // JMX spec does not allow overloading attributes.
               // If an attribute with the same name already exists the MBean is not compliant
               if (!info.getType().equals(method.getParameterTypes()[0].getName()))
               {
                  if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean is not compliant: has overloaded attribute " + attribute);
                  return null;
               }
               else
               {
                  // MBeanAttributeInfo is already present due to a getter method, just update its writability
View Full Code Here

      return false;
   }

   private MBeanInvoker createInvoker(MBeanMetaData metadata)
   {
      Logger logger = getLogger();

      if (m_customMBeanInvoker != null)
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Custom MBeanInvoker class is: " + m_customMBeanInvoker);
         try
         {
            MBeanInvoker mbeanInvoker = (MBeanInvoker)Thread.currentThread().getContextClassLoader().loadClass(m_customMBeanInvoker).newInstance();
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Using custom MBeanInvoker: " + mbeanInvoker);
            return mbeanInvoker;
         }
         catch (Exception x)
         {
            if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot instantiate custom MBeanInvoker, using default", x);
         }
      }

/* SFR
      if (m_bcelClassesAvailable)
      {
         MBeanInvoker mbeanInvoker = BCELMBeanInvoker.create(metadata);
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Using default BCEL MBeanInvoker for MBean " + metadata.name + ", " + mbeanInvoker);
         return mbeanInvoker;
      }
      else
      {
*/
         MBeanInvoker mbeanInvoker = new ReflectedMBeanInvoker();
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Using default Reflection MBeanInvoker for MBean " + metadata.name + ", " + mbeanInvoker);
         return mbeanInvoker;
/* SFR     } */
   }
View Full Code Here

               Attribute attr = new Attribute(name, value);
               list.add(attr);
            }
            catch (Exception ignored)
            {
               Logger logger = getLogger();
               if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Exception caught from getAttributes(), ignoring attribute " + name);
            }
         }
         return list;
      }
   }
View Full Code Here

               setAttribute(metadata, attr);
               list.add(attr);
            }
            catch (Exception ignored)
            {
               Logger logger = getLogger();
               if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Exception caught from setAttributes(), ignoring attribute " + attr, ignored);
            }
         }
         return list;
      }
   }
View Full Code Here

    * @param defaultDomain The default domain to be used
    * @throws SecurityException if access is not granted to create an MBeanServer instance
    */
   public MX4JMBeanServer(String defaultDomain, MBeanServer outer, MBeanServerDelegate delegate)
   {
      Logger logger = getLogger();
      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Creating MBeanServer instance...");

      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Checking permission to create MBeanServer...");
         sm.checkPermission(new MBeanServerPermission("newMBeanServer"));
      }

      if (defaultDomain == null) defaultDomain = "";
      this.defaultDomain = defaultDomain;

      if (delegate==null) throw new JMRuntimeException("Delegate can't be null");
      this.delegate = delegate;

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("MBeanServer default domain is: '" + this.defaultDomain + "'");

      mbeanRepository = createMBeanRepository();

      classLoaderRepository = createClassLoaderRepository();
      // JMX 1.2 requires the CLR to have as first entry the classloader of this class
      classLoaderRepository.addClassLoader(getClass().getClassLoader());

      introspector = new MBeanIntrospector();

      // This is the official name of the delegate, it is used as a source for MBeanServerNotifications
      try
      {
         delegateName = new ObjectName("JMImplementation", "type", "MBeanServerDelegate");
      }
      catch (MalformedObjectNameException ignored)
      {
      }

      try
      {
         ObjectName invokerName = new ObjectName(MBeanServerInterceptorConfigurator.OBJECT_NAME);
         invoker = new MBeanServerInterceptorConfigurator(this);

//         ContextClassLoaderMBeanServerInterceptor ccl = new ContextClassLoaderMBeanServerInterceptor();
//         NotificationListenerMBeanServerInterceptor notif = new NotificationListenerMBeanServerInterceptor();
//         SecurityMBeanServerInterceptor sec = new SecurityMBeanServerInterceptor();
         InvokerMBeanServerInterceptor inv = new InvokerMBeanServerInterceptor(outer==null ? this : outer);

//         invoker.addPreInterceptor(ccl);
//         invoker.addPreInterceptor(notif);
//         invoker.addPostInterceptor(sec);
         invoker.addPostInterceptor(inv);

         invoker.start();

         // The interceptor stack is in place, register the configurator and all interceptors
         privilegedRegisterMBean(invoker, invokerName);

//         ObjectName cclName = new ObjectName("JMImplementation", "interceptor", "contextclassloader");
//         ObjectName notifName = new ObjectName("JMImplementation", "interceptor", "notificationwrapper");
//         ObjectName secName = new ObjectName("JMImplementation", "interceptor", "security");
         ObjectName invName = new ObjectName("JMImplementation", "interceptor", "invoker");

//         privilegedRegisterMBean(ccl, cclName);
//         privilegedRegisterMBean(notif, notifName);
//         privilegedRegisterMBean(sec, secName);
         privilegedRegisterMBean(inv, invName);
      }
      catch (Exception x)
      {
         logger.error("MBeanServerInterceptorConfigurator cannot be registered", x);
         throw new ImplementationException();
      }

      // Now register the delegate
      try
      {
         privilegedRegisterMBean(delegate, delegateName);
      }
      catch (Exception x)
      {
         logger.error("MBeanServerDelegate cannot be registered", x);
         throw new ImplementationException(x.toString());
      }

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("MBeanServer instance created successfully");
   }
View Full Code Here

    * In case the system property is not defined or the class is not loadable or instantiable, a default
    * implementation is returned.
    */
   private MBeanRepository createMBeanRepository()
   {
      Logger logger = getLogger();

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Checking for system property " + MX4JSystemKeys.MX4J_MBEANSERVER_REPOSITORY);

      String value = (String)AccessController.doPrivileged(new PrivilegedAction()
      {
         public Object run()
         {
            return System.getProperty(MX4JSystemKeys.MX4J_MBEANSERVER_REPOSITORY);
         }
      });

      if (value != null)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Property found for custom MBeanServer registry; class is: " + value);

         try
         {
            MBeanRepository registry = (MBeanRepository)Thread.currentThread().getContextClassLoader().loadClass(value).newInstance();
            if (logger.isEnabledFor(Logger.TRACE))
            {
               logger.trace("Custom MBeanServer registry created successfully");
            }
            return registry;
         }
         catch (Exception x)
         {
            if (logger.isEnabledFor(Logger.TRACE))
            {
               logger.trace("Custom MBeanServer registry could not be created", x);
            }
         }
      }

      return new DefaultMBeanRepository();
View Full Code Here

TOP

Related Classes of org.apache.felix.mosgi.jmx.agent.mx4j.log.Logger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.