Package mx4j.log

Examples of mx4j.log.Logger


    *      <p>The impmentation does nothing but log registration of the relation service</p>
    * @see javax.management.MBeanRegistrationException or a @see RuntimeMBeanException
    */
   public void preDeregister() throws Exception
   {
      Logger logger = getLogger();
      if (logger.isEnabledFor(Logger.DEBUG))
      {
         logger.debug("Relation service preDeregistered");
      }
   }
View Full Code Here


    * <p> logs nothing but log postRegisration</p>
    * <p> Implementation of MBeanRegistration</p>
    */
   public void postDeregister()
   {
      Logger logger = getLogger();
      if (logger.isEnabledFor(Logger.DEBUG))
      {
         logger.debug("Relation service postDeregistered");
      }
   }
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 = "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());
      // The system classloader must be there as well, in case this class is in the bootclasspath
      classLoaderRepository.addClassLoader(ClassLoader.getSystemClassLoader());

      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.addPreInterceptor(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

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

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

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

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

         try
         {
            ModifiableClassLoaderRepository repository = (ModifiableClassLoaderRepository)Thread.currentThread().getContextClassLoader().loadClass(value).newInstance();
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Custom ClassLoaderRepository created successfully " + repository);
            return repository;
         }
         catch (Exception x)
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Custom ClassLoaderRepository could not be created", x);
         }
      }
      return new DefaultClassLoaderRepository();
   }
View Full Code Here

   private boolean isMBeanClassCompliant(MBeanMetaData metadata)
   {
      // No requirements on the implementation (can be abstract, non public and no accessible constructors)
      // but the management interface must be public
      Logger logger = getLogger();
      if (metadata.getMBeanInterface() != null)
      {
         boolean isPublic = Modifier.isPublic(metadata.getMBeanInterface().getModifiers());
         if (!isPublic && logger.isEnabledFor(Logger.DEBUG)) logger.debug("MBean interface is not public");
         return isPublic;
      }
      return true;
   }
View Full Code Here

      return true;
   }

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

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

      return true;
   }
View Full Code Here

      }
   }

   private Subject authenticate(Map env, final Object credentials) throws SecurityException
   {
      Logger logger = getLogger();

      Subject subject = null;
      final JMXAuthenticator authenticator = (JMXAuthenticator)env.get(JMXConnectorServer.AUTHENTICATOR);
      if (authenticator != null)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Authenticating new client using JMXAuthenticator " + authenticator);
         try
         {
            // We must check that the code that provided the JMXAuthenticator
            // has the permission to create a Subject
            subject = (Subject)AccessController.doPrivileged(new PrivilegedAction()
            {
               public Object run()
               {
                  return authenticator.authenticate(credentials);
               }
            }, getContext());
            if (subject == null) throw new SecurityException("JMXAuthenticator returned null Subject");
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Authentication successful");
         }
         catch (SecurityException x)
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Authentication failed", x);
            throw x;
         }
         catch (Throwable x)
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Authentication failed", x);
            throw new SecurityException(x.toString());
         }
      }
      return subject;
   }
View Full Code Here

      return Log.getLogger(getClass().getName());
   }

   public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
   {
      Logger logger = getLogger();

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Adding notification listener: " + listener + ", filter: " + filter + ", handback: " + handback + " to " + this);

      if (listener == null) throw new IllegalArgumentException("Notification listener cannot be null");

      // Normalize the arguments
      if (filter == null) filter = NULL_FILTER;
      if (handback == null) handback = NULL_HANDBACK;

      FilterHandbackPair pair = new FilterHandbackPair(filter, handback);

      synchronized (this)
      {
         ArrayList pairs = (ArrayList)m_listeners.get(listener);

         if (pairs == null)
         {
            // A new listener, register it
            pairs = new ArrayList();
            pairs.add(pair);
            m_listeners.put(listener, pairs);
         }
         else
         {
            // Check that the same triple (listener, filter, handback) is not already registered
            for (int i = 0; i < pairs.size(); ++i)
            {
               FilterHandbackPair other = (FilterHandbackPair)pairs.get(i);
               if (pair.filter.equals(other.filter) && pair.handback.equals(other.handback))
               {
                  // Same filter and same handback for the same listener, it's already registered
                  throw new RuntimeOperationsException(new IllegalArgumentException("Notification listener is already registered"));
               }
            }
            // Not yet registered, register.
            // Do not merge this call with the one in the if branch: like this is easier to debug
            // (I know the if-else branch from where I'm coming)
            pairs.add(pair);
         }

         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Filters - Handbacks for this listener: " + pairs);
      }

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Notification listener added successfully to " + this);
   }
View Full Code Here

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Notification listener added successfully to " + this);
   }

   public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
   {
      Logger logger = getLogger();
      if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Removing notification listener: " + listener);

      int removed = removeNotificationListenerImpl(listener, null, null);

      if (logger.isEnabledFor(Logger.TRACE)) logger.trace(removed + " notification listener(s) removed successfully from " + this);
   }
View Full Code Here

TOP

Related Classes of 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.