FileDocCategorySizeDatePackage
StatsHolderMBeanImpl.javaAPI DocGlassfish v2 API15653Fri May 04 22:24:20 BST 2007com.sun.enterprise.admin.monitor.registry.spi

StatsHolderMBeanImpl

public class StatsHolderMBeanImpl extends Object implements DynamicMBean, StatsHolderMBean, MBeanRegistration
Provides the implementation for an MBean that represents a node to give statistical data in the form of its attributes.
author
Kedar Mhaswade
since
S1AS8.0
version
$Revision: 1.7 $

Fields Summary
private static Logger
logger
private static com.sun.enterprise.util.i18n.StringManager
sm
private final com.sun.enterprise.admin.monitor.registry.StatsHolder
delegate
private final StatsMediator
mediator
private DottedNameRegistrar
registrar
private MBeanInfo
mi
private int
state
private Object
lock
public static final int
INITIALIZED
public static final int
REGISTERED
public static final int
MBEANINFO_DONE
public static final String
JTA_FREEZE
public static final String
JTA_UNFREEZE
public static final String
JTA_ROLLBACK
public static final String
JTA_ACTIVE_TRANSACTIONS
public static final String
JTA_RUNTIME_RECOVERY_REQUIRED
public static final String
DOTTED_NAME
Constructors Summary
StatsHolderMBeanImpl(com.sun.enterprise.admin.monitor.registry.StatsHolder delegate)


	
	  
		assert (delegate != null);
		this.delegate	= delegate;
		this.mediator	= new StatsMediatorImpl(delegate.getStats(), delegate.getStatsClass());
		changeState(INITIALIZED);
	
Methods Summary
private voidbuild()

		final String			name		= StatsHolderMBeanImpl.class.getName();
		final String			desc		= getDescription();
		final MBeanAttributeInfo[] mais		= mediator.getAttributeInfos();
		final MBeanConstructorInfo[] mcis	= this.getConstructorInfos();
		final MBeanOperationInfo[] mois		= this.getOperationInfos();
		final MBeanNotificationInfo[] mnis	= this.getNotificationInfos();
		mi = new MBeanInfo(name, desc, mais, mcis, mois, mnis);
	
private voidchangeState(int to)

		synchronized(lock) {
			state = to;
		}
	
private booleancheckSerializability(java.lang.Object[] objArray)

		boolean isSerializable = true;
		for(int i = 0; i < objArray.length; i++) {
			isSerializable = (isSerializable) && (objArray[i] instanceof java.io.Serializable);
		}
		return isSerializable;
	
public java.lang.ObjectgetAttribute(java.lang.String name)

        if(name.equals(DOTTED_NAME))
            return delegate.getDottedName();
        else
            return ( mediator.getAttribute(name) );
	
public javax.management.AttributeListgetAttributes(java.lang.String[] names)

		final AttributeList list = new AttributeList();
		for (int i = 0 ; i < names.length ; i++) {
            try {
				final Attribute a = new Attribute(names[i], this.getAttribute(names[i]));
                list.add(a);
			}
            catch(Exception e) {
                if (logger.isLoggable(Level.FINEST)) {
                    logger.finest("Error while accessing an attribute named: " + names[i]);
                }
                //The exception SHOULD BE squelched per the contract of this method
            }
		}
		return ( list );
	
public javax.management.ObjectName[]getChildren()

		final Collection c			= delegate.getAllChildren();
		final ObjectName[] names	= new ObjectName[c.size()];
		final Iterator it			= c.iterator();
		int i = 0;
		while (it.hasNext()) {
			final StatsHolder s = (StatsHolder) it.next();
			names[i++] = s.getObjectName();
		}
		assert (names.length == i) : "Sizes don't match";
		return ( names );
	
private javax.management.MBeanOperationInfogetChildrenInfo()

		final MBeanOperationInfo info = new MBeanOperationInfo(
			"getChildren",
			"Gets the children of this StatsHolder",
			null,
			ObjectName[].class.getName(),
			MBeanOperationInfo.INFO
		);
		return ( info );
	
private javax.management.MBeanConstructorInfo[]getConstructorInfos()

		final MBeanConstructorInfo[] cis = new MBeanConstructorInfo[0];
		return ( cis ); //we don't want management applications to create instances of this MBean
	
private java.lang.StringgetDescription()

		return "StatsHolder MBean for: " + StatsHolderMBeanImpl.class.getName();
	
private javax.management.MBeanOperationInfo[]getJTAOperationInfo(javax.management.MBeanOperationInfo[] mos)

		ArrayList opInfo = new ArrayList();
		for(int i = 0; i < mos.length ; i++)
			opInfo.add(mos[i]);
		// not performing any reflection for now, as it is assumed that 
		// only 3 methods will be added to the MBeanOperationInfo and 
		// their names and signatures are fixed.
		MBeanOperationInfo mInfo = new MBeanOperationInfo(JTA_FREEZE,
		                                                  "Freezes the transaction service",
														  null,
														  void.class.getName(),
														  MBeanOperationInfo.ACTION);
	
		opInfo.add(mInfo);
		
		mInfo = new MBeanOperationInfo(JTA_UNFREEZE,
		                               "Unfreezes the transaction service",
										null,
										void.class.getName(),
										MBeanOperationInfo.ACTION);
		
		opInfo.add(mInfo);
        mInfo = new MBeanOperationInfo(JTA_ROLLBACK,
		                               "Rollsback a given transaction",
										new MBeanParameterInfo[] {
		                                    new MBeanParameterInfo("txnId", 
											                       String.class.getName(), 
																   "Id of the transaction to be rolled back"
																   )},
										void.class.getName(),
										MBeanOperationInfo.ACTION);
        opInfo.add(mInfo);
        mInfo = new MBeanOperationInfo(JTA_ACTIVE_TRANSACTIONS,
		                               "Gets Active Transactions in a Map",
                                        null,
										List.class.getName(),
										MBeanOperationInfo.ACTION_INFO);
        opInfo.add(mInfo);
        mInfo = new MBeanOperationInfo(JTA_RUNTIME_RECOVERY_REQUIRED,
                                       "Returns if the recovery is required",
                                       null,
                                       Boolean.class.getName(),
                                       MBeanOperationInfo.ACTION_INFO);
        opInfo.add(mInfo);
		MBeanOperationInfo[] jtaOpInfo = new MBeanOperationInfo[opInfo.size()];
		return (MBeanOperationInfo[])opInfo.toArray(jtaOpInfo);
		
	
public javax.management.MBeanInfogetMBeanInfo()

		synchronized(lock) {
			if (state == MBEANINFO_DONE) {
				return mi;
			}
		}
		build();
		changeState(MBEANINFO_DONE);
		return ( mi );
	
public java.lang.StringgetName()

		return delegate.getName();
	
private javax.management.MBeanOperationInfogetNameInfo()

		MBeanOperationInfo mInfo = new MBeanOperationInfo("getName",
		                                                  "Gets the name of this StatsHolder",
														  null,
														  String.class.getName(),
														  MBeanOperationInfo.INFO);
		return mInfo;
	
private javax.management.MBeanNotificationInfo[]getNotificationInfos()

		final MBeanNotificationInfo[] mns = new MBeanNotificationInfo[0];
		return ( mns );
	
private javax.management.MBeanOperationInfo[]getOperationInfos()

		
		final ArrayList opInfo = new ArrayList();

		opInfo.add(getChildrenInfo());
		opInfo.add(getNameInfo());
		opInfo.add(getTypeInfo());
		// Add the additional ops only for StatsHolders that have an actual Stats object
		// associated with them
		if(delegate.getStats() != null) {
			opInfo.add(getStatisticNameInfo());
			opInfo.add(getStatsInfo());
		}
		
		MBeanOperationInfo[] mos = new MBeanOperationInfo[opInfo.size()];
		mos = (MBeanOperationInfo[])opInfo.toArray(mos);
		
		// if we are dealing with JTAStats, we need to add the additional
		// operations freeze, unfreeze & rollback to the MBeanOerationInfo
		if(isJta())
			return (getJTAOperationInfo(mos));
		
		return ( mos );
	
private javax.management.MBeanOperationInfogetStatisticNameInfo()

		MBeanOperationInfo mInfo = new MBeanOperationInfo("getStatisticNames",
		                                                  "Gets the names of all the statistics in the given Stats Object", 
														  null, 
														  String[].class.getName(),
														  MBeanOperationInfo.INFO);
		return mInfo;
	
public java.lang.String[]getStatisticNames()

        Stats stats = delegate.getStats();
        if (stats != null) {
            return stats.getStatisticNames();
        } else {
            return null;
        }
	
public javax.management.j2ee.statistics.Statistic[]getStatistics()

        Stats stats = delegate.getStats();
        if (stats == null) {
            return null;
        }

		Statistic[] statArray = stats.getStatistics();
		boolean isSerializable = checkSerializability(statArray);
		if(isSerializable) {
			final Statistic[] hackedArray = StatisticWorkaround.populateDescriptions(statArray);
			return hackedArray;
		}
		else 
			return null;
	
private javax.management.MBeanOperationInfogetStatsInfo()

		MBeanOperationInfo mInfo = new MBeanOperationInfo("getStatistics", 
		                                                  "returns the results of all the getXXX methods, in the given Stats object",
														  null, 
														  Statistic[].class.getName(), 
														  MBeanOperationInfo.INFO);
		return mInfo;
	
public java.lang.StringgetType()

		return delegate.getType().getTypeName();
	
private javax.management.MBeanOperationInfogetTypeInfo()

		MBeanOperationInfo mInfo = new MBeanOperationInfo("getType",
		                                                  "Gets the type of this StatsHolder",
														  null,
														  String.class.getName(),
														  MBeanOperationInfo.INFO);
		return mInfo;
	
public java.lang.Objectinvoke(java.lang.String method, java.lang.Object[] params, java.lang.String[] sign)

		if ("getChildren".equals(method)) {
			return ( this.getChildren() );
		} else if ("getName".equals(method)) {
			return (this.getName());
		} else if ("getType".equals(method)) {
			return (this.getType());
		} else if ("getStatisticNames".equals(method)) {
			return (this.getStatisticNames());
		} else if ("getStatistics".equals(method)) {
			return (this.getStatistics());
		} else if(isJTAMethod(method)) {
			return(mediator.invoke(method, params, sign));
		} else {
			final String msg = sm.getString("smi.no_such_method", method);
                        final Exception ae = new UnsupportedOperationException(msg);
			throw new MBeanException(ae);
		}
	
private booleanisJTAMethod(java.lang.String methodName)

		return ((JTA_FREEZE.equals(methodName)) || 
		       (JTA_UNFREEZE.equals(methodName)) || 
		       (JTA_ACTIVE_TRANSACTIONS.equals(methodName)) || 
		       (JTA_RUNTIME_RECOVERY_REQUIRED.equals(methodName)) || 
			   (JTA_ROLLBACK.equals(methodName))); 
	
private booleanisJta()

		boolean isJta = false;
		final Class cl = delegate.getStatsClass();
		if (cl != null) {
			if (com.sun.enterprise.admin.monitor.stats.JTAStats.class.getName().equals(cl.getName())) {
				isJta = true;
			}
		}
		return ( isJta);
	
public voidpostDeregister()

		
	
public voidpostRegister(java.lang.Boolean registered)

		if (registered.equals(Boolean.TRUE)) {
			registrar.registerDottedName(delegate.getDottedName(),
				delegate.getObjectName());
			changeState(REGISTERED);
		}
	
public voidpreDeregister()

		registrar.unregisterDottedName(delegate.getDottedName());		
	
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer mBeanServer, javax.management.ObjectName objectName)

		this.registrar = new DottedNameRegistrar(mBeanServer);
		return objectName;
	
public voidsetAttribute(javax.management.Attribute attribute)

		throw new UnsupportedOperationException("NYI");
	
public javax.management.AttributeListsetAttributes(javax.management.AttributeList attributes)

		throw new UnsupportedOperationException("NYI");