Package org.apache.log4j.jmx

Examples of org.apache.log4j.jmx.HierarchyDynamicMBean


        {
            mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
            final ObjectName objectName = jmxSupport.getObjectName(JMX_OBJECT_NAME);
            // unregister existing Log4j MBean first if required
            unregisterMBeansIfNecessary();
            mBeanServer.registerMBean(new HierarchyDynamicMBean(), objectName);
        }
        catch (Exception e)
        {
            throw new InitialisationException(CoreMessages.failedToStart("Log4j Agent"), e, this);
        }
View Full Code Here


public class Log4jAgentTestCase extends AbstractMuleJmxTestCase
{
    public void testRedeploy() throws Exception
    {
        mBeanServer.registerMBean(new HierarchyDynamicMBean(),
                                  ObjectName.getInstance(Log4jAgent.JMX_OBJECT_NAME));

        Log4jAgent agent = new Log4jAgent();
        agent.initialise();
    }
View Full Code Here

  }
  public void testHourglassDirectoryManagerFactory() throws IOException, InterruptedException, ZoieException
  {
    File idxDir = getIdxDir();
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    String LOG4J_HIEARCHY_DEFAULT = "log4j:hiearchy=default";
    try
    {
      mbeanServer.registerMBean(hdm, new ObjectName("HouseGlass:name=log4j"));
      // Add the root logger to the Hierarchy MBean
      hdm.addLoggerMBean(Logger.getRootLogger().getName());

      // Get each logger from the Log4J Repository and add it to
      // the Hierarchy MBean created above.
      LoggerRepository r = LogManager.getLoggerRepository();

      java.util.Enumeration loggers = r.getCurrentLoggers();

      int count = 1;
      while (loggers.hasMoreElements())
      {
        String name = ((Logger) loggers.nextElement()).getName();
        if (log.isDebugEnabled())
        {
          log.debug("[contextInitialized]: Registering " + name);
        }
        hdm.addLoggerMBean(name);
        count++;
      }
      if (log.isInfoEnabled())
      {
        log
View Full Code Here

        }

        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        // Create and Register the top level Log4J MBean
        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();

        ObjectName mbo = new ObjectName("log4j:hierarchy=default");
        mbs.registerMBean(hdm, mbo);

        // Add the root logger to the Hierarchy MBean
        Logger rootLogger = Logger.getRootLogger();
        hdm.addLoggerMBean(rootLogger.getName());

        // Get each logger from the Log4J Repository and add it to
        // the Hierarchy MBean created above.
        LoggerRepository r = LogManager.getLoggerRepository();
        Enumeration enumer = r.getCurrentLoggers();
        Logger logger;

        while (enumer.hasMoreElements()) {
            logger = (Logger) enumer.nextElement();
            hdm.addLoggerMBean(logger.getName());
        }
    }
View Full Code Here

        }
       
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        // Create and Register the top level Log4J MBean
        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();

        ObjectName mbo = new ObjectName("log4j:hiearchy=default");
        mbs.registerMBean(hdm, mbo);

        // Add the root logger to the Hierarchy MBean
        Logger rootLogger = Logger.getRootLogger();
        hdm.addLoggerMBean(rootLogger.getName());

        // Get each logger from the Log4J Repository and add it to
        // the Hierarchy MBean created above.
        LoggerRepository r = LogManager.getLoggerRepository();
        Enumeration enumer = r.getCurrentLoggers();
        Logger logger = null;

        while (enumer.hasMoreElements()) {
           logger = (Logger) enumer.nextElement();
           hdm.addLoggerMBean(logger.getName());
        }
    }
View Full Code Here

  {
    shutdown = true;
    killDelayedThread();
   
      MBeanServer server = JmxUtils.locateMBeanServer();
      HierarchyDynamicMBean hdm = hierarchyDynamicMBean.get();
    for (ObjectName registeredName : registeredNames)
    {
      try {
        server.unregisterMBean(registeredName);
       
        // The AbstractDynamicMBean base class of the HierarchyDynamicMBean tracks these names too
        // and will later try to unregister them and throw warning log messages unless we violate its
        // privacy and clean out its internal bookkeeping
        Field fld = ReflectionUtils.findField(hdm.getClass(), "mbeanList", Vector.class);
        fld.setAccessible(true);
        Vector<ObjectName> mbeanList = (Vector<ObjectName>) ReflectionUtils.getField(fld, hdm);
        mbeanList.remove(registeredName);
      }
      catch (Exception e) {
View Full Code Here

      if (shutdown)
        return 0;
     
      MBeanServer server = JmxUtils.locateMBeanServer();
     
      HierarchyDynamicMBean hdm;
      synchronized (this.getClass())
      {
        boolean usedNew = hierarchyDynamicMBean.compareAndSet(null, new HierarchyDynamicMBean());
            hdm = hierarchyDynamicMBean.get();
        if (usedNew)
        {
              try {
          ObjectName mbo = new ObjectName(LOG4J_HIERARCHY_DEFAULT);
          server.registerMBean(hdm, mbo);
          registeredHierarchy = true;
          // Add the root logger to the Hierarchy MBean
          hdm.addLoggerMBean(Logger.getRootLogger().getName());
        }
              catch (Exception e) {
          log.error("Error initializing Log4jMBeanExporter", e);
          return 0;
        }
        }
      }
       
        // Get each logger from the Log4J Repository and add it to
        // the Hierarchy MBean created above.
        LoggerRepository r = LogManager.getLoggerRepository();

        Enumeration<?> loggers = r.getCurrentLoggers();
      int count = 0;
     
        while ( loggers.hasMoreElements() ) {
            String name = ((Logger) loggers.nextElement()).getName();
            // this name definition copied from HierarchyDynamicMBean
            ObjectName objectName;
      try {
        objectName = new ObjectName("log4j", "logger", name);
      }
      catch (Exception e) {
        log.error("Error creating JMX name for " + name, e);
        continue;
      }
     
            if (!server.isRegistered(objectName))
            {
              if (log.isDebugEnabled()) {
                log.debug("[contextInitialized]: Registering " + name);
              }
              registeredNames.add(hdm.addLoggerMBean(name));
              count++;
            }
        }
       
        log.debug("registered " + count + " new Log4j MBeans");
View Full Code Here

        }
       
        MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();

        // Create and Register the top level Log4J MBean
        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();

        ObjectName mbo = new ObjectName("log4j:hiearchy=default");
        mbs.registerMBean(hdm, mbo);

        // Add the root logger to the Hierarchy MBean
        Logger rootLogger = Logger.getRootLogger();
        hdm.addLoggerMBean(rootLogger.getName());

        // Get each logger from the Log4J Repository and add it to
        // the Hierarchy MBean created above.
        LoggerRepository r = LogManager.getLoggerRepository();
        Enumeration enumer = r.getCurrentLoggers();
        Logger logger = null;

        while (enumer.hasMoreElements()) {
           logger = (Logger) enumer.nextElement();
           hdm.addLoggerMBean(logger.getName());
        }
    }
View Full Code Here

        }
       
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        // Create and Register the top level Log4J MBean
        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();

        ObjectName mbo = new ObjectName("log4j:hiearchy=default");
        mbs.registerMBean(hdm, mbo);

        // Add the root logger to the Hierarchy MBean
        Logger rootLogger = Logger.getRootLogger();
        hdm.addLoggerMBean(rootLogger.getName());

        // Get each logger from the Log4J Repository and add it to
        // the Hierarchy MBean created above.
        LoggerRepository r = LogManager.getLoggerRepository();
        Enumeration enumer = r.getCurrentLoggers();
        Logger logger = null;

        while (enumer.hasMoreElements()) {
           logger = (Logger) enumer.nextElement();
           hdm.addLoggerMBean(logger.getName());
        }
    }
View Full Code Here

  @Test
  public void testHourglassDirectoryManagerFactory() throws IOException, InterruptedException,
      ZoieException {
    File idxDir = getIdxDir();
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    try {
      mbeanServer.registerMBean(hdm, new ObjectName("HouseGlass:name=log4j"));
      // Add the root logger to the Hierarchy MBean
      hdm.addLoggerMBean(Logger.getRootLogger().getName());

      // Get each logger from the Log4J Repository and add it to
      // the Hierarchy MBean created above.
      LoggerRepository r = LogManager.getLoggerRepository();

      java.util.Enumeration loggers = r.getCurrentLoggers();

      int count = 1;
      while (loggers.hasMoreElements()) {
        String name = ((Logger) loggers.nextElement()).getName();
        if (log.isDebugEnabled()) {
          log.debug("[contextInitialized]: Registering " + name);
        }
        hdm.addLoggerMBean(name);
        count++;
      }
      if (log.isInfoEnabled()) {
        log.info("[contextInitialized]: " + count + " log4j MBeans registered.");
      }
View Full Code Here

TOP

Related Classes of org.apache.log4j.jmx.HierarchyDynamicMBean

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.