FileDocCategorySizeDatePackage
TestDummy.javaAPI DocGlassfish v2 API10667Fri May 04 22:23:42 BST 2007com.sun.enterprise.management.support

TestDummy

public final class TestDummy extends Object implements DynamicMBean, TestDummyMBean, MBeanRegistration
This MBean is used to test the CustomMBean functionality. It is not an AMX MBean.

Fields Summary
private final NotificationBroadcasterSupport
mBroadcaster
private final Map
mAttributes
private MBeanInfo
mMBeanInfo
private com.sun.appserv.management.util.misc.Output
mDebug
private MBeanServer
mServer
private ObjectName
mSelfObjectName
Constructors Summary
public TestDummy()

		mAttributes	= Collections.synchronizedMap( new HashMap<String,Object>() );
		mMBeanInfo	= null;
		
		mDebug  = AMXDebug.getInstance().getOutput( getDebugID() );
		//AMXDebug.getInstance().setDebug( getDebugID(), true );
		
		mBroadcaster    = new NotificationBroadcasterSupport();
	
Methods Summary
public voidaddAttribute(java.lang.String name, java.lang.Object value)

		if ( name == null || name.length() == 0 )
		{
		    debug( "Illegal Attribute name: " + name );
			throw new IllegalArgumentException( );
		}
		
		mAttributes.put( name, value );
		mMBeanInfo	= null;
		debug( "added Attribute: " + name );
	
public voidaddNotificationListener(javax.management.NotificationListener listener)

		mBroadcaster.addNotificationListener( listener, null, null );
	
public voidaddNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)

		mBroadcaster.addNotificationListener( listener, filter, handback );
	
private synchronized javax.management.MBeanInfocreateMBeanInfo()

		debug( "createMBeanInfo");
		final MBeanInfo	baseMBeanInfo	=
		    MBeanInfoConverter.getInstance().convert( TestDummy.class, null );
		
		final List<MBeanAttributeInfo>	dynamicAttrInfos	= new ArrayList<MBeanAttributeInfo>();

		int	i = 0;
		for( final String name : mAttributes.keySet() )
		{
			final Object	value	= mAttributes.get( name );
			final String	type	= value == null ?
			    String.class.getName() : value.getClass().getName();
			
			final MBeanAttributeInfo info	=
			    new MBeanAttributeInfo( name, type, "dynamically-added Attribute",
										true, true, false );
			dynamicAttrInfos.add( info );
		}
		
		final MBeanAttributeInfo[]  dynInfos    = new MBeanAttributeInfo[ dynamicAttrInfos.size() ];
		dynamicAttrInfos.toArray( dynInfos );
		
		final MBeanAttributeInfo[]	attrInfos	=
			JMXUtil.mergeMBeanAttributeInfos( dynInfos, baseMBeanInfo.getAttributes() );
		
		return( JMXUtil.newMBeanInfo( baseMBeanInfo, attrInfos ) );
	
private voiddebug(java.lang.Object o)

	    mDebug.println( o );
	
public longemitNotifications(java.lang.String notifType, int howMany)

	    final NotificationBuilder builder   =
	        new NotificationBuilder( notifType, mSelfObjectName );
	        
	    final long start    = System.currentTimeMillis();
	    
	    for( int i = 0; i < howMany; ++i )
	    {
	        final Notification  notif = builder.buildNew( "test Notification" );
	        
	        sendNotification( notif );
	    }
	    
	    final long elapsed = System.currentTimeMillis() - start;
	    return elapsed;
	
public java.lang.StringgetAttr1()

	    return (String)mAttributes.get( "Attr1" );
	
public java.lang.StringgetAttr2()

	    return (String)mAttributes.get( "Attr2" );
	
public java.lang.ObjectgetAttribute(java.lang.String name)

	    if ( ! mAttributes.containsKey( name ) )
	    {
	        throw new AttributeNotFoundException( name );
	    }
	    
		return( mAttributes.get( name ) );
	
public javax.management.AttributeListgetAttributes(java.lang.String[] names)

	    final AttributeList attrs   = new AttributeList();
	    
	    if ( names != null )
	    {
    	    for( int i = 0; i < names.length; ++i )
    	    {
    	        try
    	        {
    	            final Object result = getAttribute( names[ i ] );
    	            attrs.add( new Attribute( names[ i ], result ) );
    	        }
    	        catch( AttributeNotFoundException e )
    	        {
    	        }
    	    }
	    }
	    
	    return attrs;
	
private java.lang.StringgetDebugID()

        return this.getClass().getName();
    
public synchronized javax.management.MBeanInfogetMBeanInfo()

		if ( mMBeanInfo == null )
		{
			mMBeanInfo	= createMBeanInfo();
		}
		
		return( mMBeanInfo );
	
public javax.management.MBeanNotificationInfo[]getNotificationInfo()

 	    return new MBeanNotificationInfo[0];
 	
public java.lang.Objectinvoke(java.lang.String methodName, java.lang.Object[] args, java.lang.String[] signature)

	    Object      result  = null;
	    
        if(args == null)
            throw new RuntimeException("internal Error -- no args");

        final int   numArgs = args.length;
	    
        if ( "addAttribute".equals( methodName ) && numArgs == 2 )
	    {
	        addAttribute( (String)args[ 0 ], (Object)args[ 1 ] );
	    }
	    else if ( "removeAttribute".equals( methodName ) && numArgs == 1 )
	    {
	        removeAttribute( (String)args[ 0 ] );
	    }
	    else if ( numArgs == 2 &&
	        "emitNotifications".equals( methodName ) )
	    {
	        final String    type    = (String)args[0];
	        final int       howMany = (Integer)args[1];
	        result  = emitNotifications( type, howMany );
	    }
	    else
	    {
	        throw new RuntimeException( "invoke: no such method " + methodName );
	    }
	    return result;
	
public voidpostDeregister()

	
public voidpostRegister(java.lang.Boolean registrationSucceeded)

	
public voidpreDeregister()

	
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName nameIn)

	    mServer = server;
		mSelfObjectName	= preRegisterModifyName( server, nameIn );
		
		return( mSelfObjectName );
	
protected javax.management.ObjectNamepreRegisterModifyName(javax.management.MBeanServer server, javax.management.ObjectName nameIn)

	    //final String EXTRA  = ",epoch=" + System.currentTimeMillis();
	    final String EXTRA  = "";
	    
		final ObjectName	nameOut	= Util.newObjectName( nameIn.toString() + EXTRA );

		return( nameOut );
	
public voidremoveAttribute(java.lang.String name)

		mAttributes.remove( name );
		mMBeanInfo	= null;
		debug( "removed Attribute: " + name );
	
public voidremoveNotificationListener(javax.management.NotificationListener listener)

 		mBroadcaster.removeNotificationListener( listener );
	
public voidremoveNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)

		mBroadcaster.removeNotificationListener( listener, filter, handback );
	
public voidsendNotification(javax.management.Notification notification)

 		mBroadcaster.sendNotification( notification );
 	
public voidsetAttr1(java.lang.String value)

	    setAttribute( "Attr1", value);
	
public voidsetAttr2(java.lang.String value)

	    setAttribute( "Attr2", value);
	
public voidsetAttribute(java.lang.String name, java.lang.Object value)

		debug( "setAttribute" + name + "=" + value );
		
		addAttribute( name, value );
	
public voidsetAttribute(javax.management.Attribute attr)

		setAttribute( attr.getName(), attr.getValue() );
	
public javax.management.AttributeListsetAttributes(javax.management.AttributeList attrs)

	    throw new RuntimeException(
	        "TestDummy: setAttributes() not yet implemented" );