FileDocCategorySizeDatePackage
MBeanRegistryFactory.javaAPI DocGlassfish v2 API12992Fri May 04 22:25:36 BST 2007com.sun.enterprise.admin.meta

MBeanRegistryFactory

public class MBeanRegistryFactory extends Object
Provides naming support for Mbeans

Fields Summary
private static MBeanRegistry
adminRegistry
private static MBeanRegistry
runtimeRegistry
private static volatile com.sun.enterprise.admin.AdminContext
adminContext
protected static final Logger
_sLogger
Constructors Summary
Methods Summary
public static com.sun.enterprise.admin.AdminContextgetAdminContext()

        return adminContext;
    
public static synchronized MBeanRegistrygetAdminMBeanRegistry()

        if(adminRegistry != null)
            return adminRegistry;
        try {
            //Dont need to load the static MBeans for non DAS instances
            if ((adminContext != null) && 
                    (!ServerHelper.isDAS(adminContext.getRuntimeConfigContext(), 
                                            adminContext.getServerName())))
            {
	        //Return an empty MBeanRegistry
                adminRegistry = new MBeanRegistry();
                return adminRegistry;
            }
            URL url = null;
            if(adminContext!=null)
                url = adminContext.getAdminMBeanRegistryURL();
            if(url==null)
               url = MBeanRegistry.class.getResource("/admin-mbeans-descriptors.xml"); //standard for pe
            InputStream stream = url.openStream();
            adminRegistry = new MBeanRegistry();
            adminRegistry.loadMBeanRegistry(stream);
            stream.close();
            //printMBeanREgistry
            try {
                String fileName = System.getProperty("adminmbeanregistry.printfile");
                if(fileName!=null)
                {
                    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
                    out.println("MBean REGISTRY (in XPath value order)");
                    adminRegistry.sortRegistryEntries(MBeanRegistry.SORT_BY_XPATH);
                    out.print(adminRegistry.toFormatString());
                    out.println("\n\n\nMBean REGISTRY (in Type value order)");
                    adminRegistry.sortRegistryEntries(MBeanRegistry.SORT_BY_NAME);
                    out.print(adminRegistry.toFormatString());
                    out.close();
                }

            }
            catch (Throwable t)
            {}
             return adminRegistry;
        } catch (Throwable t) {
            _sLogger.log(Level.WARNING, "core.registryfactory_adminregistry_not_found",
                       t);
        }
        return null;
    
public static MBeanRegistrygetMBeanRegistry(java.lang.String fileName)

   
        return getMBeanRegistry(fileName, true);
    
public static synchronized MBeanRegistrygetMBeanRegistry(java.lang.String fileName, boolean bIntrospectMBeans)

        try {
            FileInputStream stream = new FileInputStream(fileName);
            MBeanRegistry myRegistry = new MBeanRegistry();
            myRegistry.loadMBeanRegistry((InputStream)stream, bIntrospectMBeans);
            stream.close();
            return myRegistry;
        } catch (Throwable t) {
            _sLogger.log(Level.WARNING, "core.registryfactory_registry_not_found",
                       t);
        }
        return null;
    
public static synchronized MBeanRegistrygetOfflineAdminMBeanRegistry()

        MBeanRegistry myRegistry;
        URL url = null;
        url = MBeanRegistry.class.getResource("/admin-mbeans-descriptors-ee.xml"); //standard for ee
        InputStream stream = null;
        try {
        stream = url.openStream();
        } catch (Exception e)
        {
        }
        if (stream==null)  
        {
           url = MBeanRegistry.class.getResource("/admin-mbeans-descriptors.xml"); //standard for pe
           stream = url.openStream();
        }
        if (stream==null)  
            return null;
        myRegistry = new MBeanRegistry();
        myRegistry.loadMBeanRegistry(stream, false);
        stream.close();
        return myRegistry;
    
public static synchronized MBeanRegistrygetRuntimeMBeanRegistry()

        if(runtimeRegistry != null)
            return runtimeRegistry;
        try {
            URL url = null;
            if(adminContext!=null)
                url = adminContext.getRuntimeMBeanRegistryURL();
            if(url==null)
                url = MBeanRegistry.class.getResource("/runtime-mbeans-descriptors.xml");  //standard for pe
            InputStream stream = url.openStream();
            runtimeRegistry = new MBeanRegistry();
            runtimeRegistry.loadMBeanRegistry(stream);
            stream.close();
            return runtimeRegistry;
        } catch (Throwable t) {
            _sLogger.log(Level.WARNING, "core.registryfactory_adminregistry_not_found",
                       t);
        }
        return null;
    
public static voidsetAdminContext(com.sun.enterprise.admin.AdminContext ctx)

    
        
    
        adminContext = ctx;
    
public static synchronized voidsetAdminMBeanRegistry(MBeanRegistry registry)

 //for tester purposes
        adminRegistry = registry;