FileDocCategorySizeDatePackage
AMXLoader.javaAPI DocGlassfish v2 API16094Fri May 04 22:23:40 BST 2007com.sun.enterprise.management.offline

AMXLoader

public final class AMXLoader extends Object implements NotificationListener
Loads AMX MBeans based on ConfigBeans.

Fields Summary
private final MBeanServer
mServer
private final String
mJMXDomain
private final ConfigDelegateFactory
mDelegateFactory
private com.sun.enterprise.management.support.ObjectNames
mObjectNames
private final Map
mObjectNameToConfigBean
private static final Class[]
DELEGATE_CONSTRUCTOR_SIG
Constructors Summary
public AMXLoader(MBeanServer server, ConfigDelegateFactory delegateFactory)

        mServer = server;
        
		new AMXDebugSupport( mServer );
		
        mDelegateFactory    = delegateFactory;
        mJMXDomain  = BootUtil.getInstance().getAMXJMXDomainName();
        
	    mObjectNames    = ObjectNames.getInstance( getAMXJMXDomainName() );
	
        mObjectNameToConfigBean  = Collections.synchronizedMap( new HashMap<ObjectName,ConfigBean>() );
        
		loadSystemInfo( server );
			
		final MBeanServerNotificationFilter filter	=
			new MBeanServerNotificationFilter();
        filter.enableAllObjectNames();
		JMXUtil.listenToMBeanServerDelegate( mServer, this, filter, null );
    
Methods Summary
private voidaddBeanHierarchy(java.util.List configBeans, com.sun.enterprise.config.ConfigBean configBean)

        // nulls exist in the array, strange but true
	    if ( configBean != null )
	    {
    	    configBeans.add( configBean );

            final ConfigBean[]  children    = configBean.getAllChildBeans();
            if ( children != null )
            {
                for( final ConfigBean child : children )
                {
                    addBeanHierarchy( configBeans, child );
                }
            }
        }
	
private javax.management.ObjectNameconfigBeanToAMX(com.sun.enterprise.config.ConfigBean configBean)

	    assert( configBean != null );
	    
	    ObjectName    objectName    = null;
	    try
	    {
    	    objectName  = loadAMX( configBean );
	    }
	    catch( Exception e )
	    {
	       final Throwable rootCause    = ExceptionUtil.getRootCause( e );
	       
	       sdebug( "Exception of type " + rootCause.getClass().getName() + 
	       " trying to create AMXConfig for " +
	        configBean.getXPath() +
	        ": " + rootCause.getMessage()  );
	       sdebug( ExceptionUtil.getStackTrace( rootCause ) );
	    }
        
        return objectName;
	
private java.util.ListconfigBeansToAMX(java.util.List configBeans)

        final List<ObjectName> objectNames   = new ArrayList<ObjectName>();
        for( final ConfigBean configBean : configBeans )
        {
            final ObjectName    objectName  = configBeanToAMX( configBean );
            if ( objectName != null )
            {
                objectNames.add( objectName );
            }
        }
        
        return objectNames;
	
private java.lang.StringconfigBeansToString(java.util.List configBeans)

        final String[]  xPaths  = new String[ configBeans.size() ];
        int i = 0;
        for( final ConfigBean configBean : configBeans )
        {
            xPaths[ i ] = "" + configBean.getXPath();
            ++i;
        }
        Arrays.sort( xPaths );
        
        final String NEWLINE    = System.getProperty( "line.separator" );
        return StringUtil.toString( NEWLINE, (Object[])xPaths );
	
private voiddebug(java.lang.Object o)

        AMXDebug.getInstance().getOutput( "AMXLoader" ).println( o );
    
public java.lang.StringgetAMXJMXDomainName()

		return( BootUtil.getInstance().getAMXJMXDomainName() );
	
private java.util.MapgetConfigBeanAttributes(com.sun.enterprise.config.ConfigBean configBean)

	    final Map<String,Object>    pairs   = new HashMap<String,Object>();
	    
        try
        {
            final ConfigDelegate delegate    =
                mDelegateFactory.createConfigDelegate( configBean );
            
            final MBeanAttributeInfo[]  attrInfos   = delegate.getMBeanInfo().getAttributes();
            for( final MBeanAttributeInfo attrInfo : attrInfos )
            {
                final String    name    = attrInfo.getName();
                Object  value   = null;
                try
                {
                    value   = delegate.getAttribute( name );
                }
                catch( AttributeNotFoundException e )
                {
                    value   = "<NOT FOUND>";
                }
                pairs.put( name, value );
            }
        }
        catch( Exception e )
        {
            pairs.put( "EXCEPTION", e.getClass().getName() + ": " + e.getMessage() );
        }
        
        return pairs;
	
private com.sun.enterprise.config.ConfigContextgetConfigContext()

        return mDelegateFactory.getConfigContext();
    
public com.sun.appserv.management.DomainRootgetDomainRoot()

		return( getProxyFactory().getDomainRoot() ); 
	
protected java.lang.ClassgetImplClass(java.lang.String j2eeType)

		final TypeInfo	info	= TypeInfos.getInstance().getInfo( j2eeType );
		assert( info != null );
		
		return( info.getImplClass() );
	
private com.sun.appserv.management.client.ProxyFactorygetProxyFactory()

	    return ProxyFactory.getInstance( mServer );
	
public voidhandleMBeanRegistered(javax.management.ObjectName objectName)

	
public voidhandleMBeanUnregistered(javax.management.ObjectName objectName)

	    mObjectNameToConfigBean.remove( objectName );
	
public voidhandleNotification(javax.management.Notification notifIn, java.lang.Object handback)

		final String	type	= notifIn.getType();
		
		if ( notifIn instanceof MBeanServerNotification )
		{
		    final ObjectName    objectName  = ((MBeanServerNotification)notifIn).getMBeanName();
		    
            if ( type.equals( MBeanServerNotification.REGISTRATION_NOTIFICATION  ) )
            {
                handleMBeanRegistered( objectName );
            }
            else if ( type.equals( MBeanServerNotification.UNREGISTRATION_NOTIFICATION  ) )
            {
                handleMBeanUnregistered( objectName );
            }
		}
	
public javax.management.ObjectNameloadAMX(com.sun.enterprise.config.ConfigBean configBean)

        final ConfigBeanHelperFactory   factory =
            ConfigBeanHelperFactory.getInstance( mDelegateFactory.getConfigContext() );
        
        final ConfigBeanHelper  helper    = factory.getHelper( configBean ); 
            
        final String            xPath     = helper.getXPath();
        final List<String[]>    propsList =
            helper.getAllObjectNameProps( OldConfigTypes.getIgnoreTypes() );
        
        final String[]  firstPair   = propsList.iterator().next();
        final String    type      = firstPair[ 0 ];
        final String    foundName = firstPair[ 1 ];
        if ( type == null ||
            OldConfigTypes.getIgnoreTypes().contains( type ) )
        {
            return null;
        }
        
        final String j2eeType   = oldTypeToJ2EEType( type );
        final String name    = foundName == null ?
                        ObjectNames.getSingletonName( j2eeType ) : foundName;
        String  props   = Util.makeRequiredProps( j2eeType, name);
        //debug( type + "=" + name + " => " + props );
        
        for( final String[] pair : propsList )
        {
            final String ancestorType       = pair[ 0 ];
            final String ancestorNameFound  = pair[ 1 ];
            if ( ! OldConfigTypes.getIgnoreTypes().contains( ancestorType ) )
            {
                final String ancestorJ2EEType   = oldTypeToJ2EEType( ancestorType );
                final String ancestorName    = ancestorNameFound == null ?
                                ObjectNames.getSingletonName( j2eeType ) : ancestorNameFound;
                final String prop        = Util.makeProp( ancestorJ2EEType, ancestorName );
                
                props   = Util.concatenateProps( props, prop );
            }
            
        }
        
       // debug( type + "=" + name + " => " + props );
            
        ObjectName  objectName  = Util.newObjectName( mJMXDomain, props );
        
        final ConfigDelegate delegate    =
            mDelegateFactory.createConfigDelegate( configBean );
            
        final AMXConfigImplBase amx = (AMXConfigImplBase)newImpl( j2eeType, delegate );
        
        mObjectNameToConfigBean.put( objectName, configBean );
        objectName  = mServer.registerMBean( amx, objectName ).getObjectName();
        
        return objectName;
    
public voidloadAll()

	    loadDomainRoot();
	    
	    final ConfigContext configContext   = mDelegateFactory.getConfigContext();
	    assert( configContext != null );
	    
        final ConfigBean domainConfigBean = 
            configContext.exactLookup( ServerXPathHelper.XPATH_DOMAIN );
        assert( domainConfigBean != null );
        
        final List<ConfigBean>    configBeans   = new ArrayList<ConfigBean>();
        addBeanHierarchy( configBeans, domainConfigBean );
        debug( configBeansToString( configBeans ) );
        
        // make an AMX MBean for every applicable config bean
        final List<ObjectName> objectNames   = configBeansToAMX( configBeans );
        
        debug( "loadAll: loaded " + objectNames.size() + "MBeans:" );
        debug( CollectionUtil.toString( JMXUtil.objectNamesToStrings( objectNames ), "\n") );
	
private voidloadDomainRoot()

		try
		{
			final TypeInfo	info	=
				TypeInfos.getInstance().getInfo( XTypes.DOMAIN_ROOT );
			final Class			implClass	= info.getImplClass();
				
			final ObjectName	objectName	= mObjectNames.getDomainRootObjectName( );
				
			final Object	impl	= implClass.newInstance();
			mServer.registerMBean( impl, objectName );
		}
		catch( Exception e )
		{
			debug( ExceptionUtil.toString( e ) );
			throw new Error( e );
		}
	
public javax.management.ObjectNameloadSystemInfo(javax.management.MBeanServer server)

		final BootUtil	bootUtil	= BootUtil.getInstance();
		
		final SystemInfoImpl	systemInfo	= new SystemInfoImpl( server, bootUtil );
		
		final ObjectName	tempName	=
		    mObjectNames.getSingletonObjectName( systemInfo.J2EE_TYPE );
		
	    final ObjectName objectName	=
	        mServer.registerMBean( systemInfo, tempName ).getObjectName();
		debug( "loaded SystemInfo as " + objectName );
		return( objectName );
	
protected java.lang.ObjectnewImpl(java.lang.String j2eeType, com.sun.enterprise.management.support.Delegate delegate)

	
		 
	
	         
	        
		 
	
		Object	impl	= null;
		
		final Class implClass	= getImplClass( j2eeType );
		
		try
		{
			Constructor constructor	= implClass.getConstructor( DELEGATE_CONSTRUCTOR_SIG );
			
			if ( constructor != null )
			{
				impl = constructor.newInstance( new Object[] { delegate } );
			}
		}
		catch( Exception e )
		{
		    final Throwable rootCause   = ExceptionUtil.getRootCause( e );
			debug( "newImpl: exception creating new impl: "  + e + "\n" +
			    ExceptionUtil.getStackTrace( rootCause ) );
			throw e;
		}
		
		return( impl );
	
private java.lang.StringoldTypeToJ2EEType(java.lang.String type)

        return OldConfigTypes.getInstance().oldTypeToJ2EEType( type );
    
protected voidsdebug(java.lang.Object o)

	    debug( o );
	    System.out.println( "" + o );