Class AMXImplBase
- java.lang.Object
-
- org.glassfish.admin.amx.impl.mbean.MBeanImplBase
-
- org.glassfish.admin.amx.impl.mbean.AMXImplBase
-
- All Implemented Interfaces:
DynamicMBean,MBeanRegistration,NotificationBroadcaster,NotificationEmitter,AMX_SPI,NotificationSender
- Direct Known Subclasses:
AMXConfigImpl,BulkAccessImpl,DomainRootImpl,ExtImpl,J2EEManagedObjectImplBase,LoggingImpl,MonitoringRootImpl,PathnamesImpl,QueryMgrImpl,RealmsImpl,RuntimeRootImpl,SampleImpl,ServerMonitoringImpl,ServerRuntimeImpl,SystemInfoImpl,ToolsImpl
public class AMXImplBase extends MBeanImplBase implements DynamicMBean, NotificationEmitter, AMX_SPI
Base class from which all AMX MBeans should derive (but not "must").Note that even though this base class implements a number of interfaces, the actual MBean interface supplied by the subclass construction-time determines which of these is actually exposed in the MBeanInfo.
A subclass should generally not implement get/setAttribute(s) as these calls are processed in this base class--
If a subclass implements a getter or setter Method it will be invoked automatically. If there is no getter or setter Method, then the getAttributeManually() or setAttributeManually() methods will be invoked; the subclass should implement these methods instead.
Method invocation is also handled automatically. If a Method cannot be found, the invokeManually() method is called; the subclass should implement this method.
Note that various optimizations are possible, but not implemented. These include caching Methods for each Attribute and for operations as well. Careful testing should be done before complicating the code with such optimizations.
-
-
Field Summary
Fields Modifier and Type Field Description protected static ObjectName[]EMPTY_OBJECT_NAMESprotected static StringGETprotected static StringGET_PREFIXprotected MBeanInfomMBeanInfoprotected static StringOBJECT_NAME_SUFFIXprotected static StringSET-
Fields inherited from class org.glassfish.admin.amx.impl.mbean.MBeanImplBase
EMPTY_STRING_ARRAY, mSelfObjectName, mServer
-
-
Constructor Summary
Constructors Constructor Description AMXImplBase(ObjectName parentObjectName)AMXImplBase(ObjectName parentObjectName, Class<? extends AMX_SPI> intf)AMXImplBase(ObjectName parentObjectName, MBeanInfo mbeanInfo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String[]attributeNameToType(String attributeName)Supply possible types to be tried based on attribute nameprotected booleanattributeTypeMatches(String attributeName, Class<?> clazz)protected ObjectNamechild(Class<?> intf)protected ObjectNamechild(String type)protected ObjectNamechild(String type, String name)protected MethodfindGetter(String name)protected MethodfindMethod(String methodName, Class[] sig)Find a method.protected MethodfindSetter(Attribute attr)Find a setXXX() method that matches the Attribute.protected ObjectNamegetAncestorByType(String type)ObjectgetAttribute(String name)Get an Attribute value, first by looking for a getter method of the correct name and signature, then by looking for a delegate, and finally by calling getAttributeManually(), which a subclass is expected to override.protected ObjectgetAttributeByMethod(String attrName, Method m)Set an Attribute by invoking the supplied method.protected MBeanAttributeInfogetAttributeInfo(String name)protected Map<String,MBeanAttributeInfo>getAttributeInfos()protected ObjectgetAttributeInternal(String name)protected ObjectgetAttributeManually(String attributeName)Subclasses should override this to handle getAttribute( attrName ).Set<String>getAttributeNames()protected ObjectgetAttributeNoThrow(String name)AttributeListgetAttributes(String[] names)Bulk get.protected StringgetAttributeType(String attrName)ObjectName[]getChildren()If no children are possible (a leaf node), an AttributeNotFoundException should be thrown.ObjectName[]getChildren(Class<?> clazz)ObjectName[]getChildren(String type)ObjectName[]getChildren(Set<String> types)Map<String,ObjectName>getChildrenMap(String type)ObjectNamegetDomainRoot()DomainRootgetDomainRootProxy()LoggergetLogger()MBeanInfogetMBeanInfo()MBeanTrackerMBeangetMBeanTracker()StringgetName()A subclass might need to override this method if its name contains characters that are illegal for the ObjectName.MBeanNotificationInfo[]getNotificationInfo()protected ObjectNamegetObjectNameAttribute(String attributeName)get child ObjectName corresponding to the AttributeNameprotected ObjectNameBuildergetObjectNames()protected ObjectName[]getObjectNamesForAttribute(String attributeName)get child ObjectNameBuilder corresponding to the AttributeNameObjectNamegetParent()Return the ObjectName of the parent.AMXProxygetParentProxy()protected <T extends AMXProxy>
TgetProxy(ObjectName objectName, Class<T> intf)protected ProxyFactorygetProxyFactory()protected AMXProxygetSelf()protected <T extends AMXProxy>
TgetSelf(Class<T> intf)protected booleangetterNameMatches(String operationName, String suffix)protected voidhandleException(Exception e)protected voidhandleGetAttributeException(Exception e)protected voidhandleInvokeThrowable(Exception e)protected voidimpossible(Throwable t)The impossible has happened.Objectinvoke(String operationName, Object[] args, String[] types)Generic handling of invoke().protected ObjectinvokeManually(String operationName, Object[] args, String[] types)An operation is being invoked manually, meaning that it is missing as a method.protected booleanisReadOnlyAttribute(String name)protected static booleanisUtilityMBean(Class mbeanInterface)Stringjava()protected booleanoperationNameMatches(String operationName, String prefix, String suffix)protected voidpostRegisterHook(Boolean registrationSucceeded)Important: must be synchronized so that preDeregisterHook cannot be called prior to existing postRegisterHook()protected MBeanInfopostRegisterModifyMBeanInfo(MBeanInfo info)Hook for a subclass when registration is completeprotected voidpreDeregisterHook()Important: must be synchronized so that it cannot be called prior to exiting postRegisterHook()ObjectNamepreRegister(MBeanServer server, ObjectName nameIn)protected voidpreRegisterDone()protected ObjectNamepreRegisterHook(MBeanServer server, ObjectName selfObjectName)This is an opportunity for a subclass to do initialization and optionally to modify the ObjectName one last time.protected ObjectNamepreRegisterModifyName(MBeanServer server, ObjectName nameIn)O the ObjectName by adding to it: adding AMX.FULL_TYPE_KEY propertyprotected ObjectNameregisterChild(Object mbean, ObjectName childObjectName)protected voidregisterChildren()protected voidsendAttributeChangeNotification(String msg, String name, String attrType, long when, Object oldValue, Object newValue)voidsetAttribute(Attribute attr)protected voidsetAttributeByMethod(Attribute attr, Method m)protected voidsetAttributeInternal(Attribute attr)Set an Attribute value, first by looking for a setter method of the correct name and signature, then by looking for a delegate, and finally by calling setAttributeManually(), which a subclass is expected to override.protected voidsetAttributeManually(Attribute attr)Subclasses should override this to handle setAttribute( attr ).AttributeListsetAttributes(AttributeList attrs)Note that the default implementation sets attributes one at a time, but that MBeans with transactional requirements (eg configuration) may wish to set them as a group.protected booleanshouldEmitNotifications()protected Stringstringify(Object o)protected booleansupportsChildren()StringtoString()protected ObjectunimplementedAttribute(String attrName)An Attribute has not been implemented.protected voidunimplementedOperation(String operation)An operation has not been implemented.protected voidunregisterChildren()-
Methods inherited from class org.glassfish.admin.amx.impl.mbean.MBeanImplBase
_getMBeanLogLevel, addNotificationListener, addNotificationListener, createNotificationBuilder, debug, debug, debugMethod, debugMethod, enableAMXDebug, getAMXDebug, getDebugID, getDebugOutput, getJMXDomain, getListenerCount, getMBeanLogger, getMBeanLoggerName, getMBeanLogLevel, getMBeanLogLevelInt, getMBeanServer, getNotificationBuilder, getNotificationEmitter, getNotificationTypeListenerCount, getObjectName, logFine, logFiner, logFinest, logInfo, logSevere, logWarning, postDeregister, postDeregisterHook, postRegister, preDeregister, quote, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, setAMXDebug, setMBeanLogLevel, shouldOmitObjectNameForDebug, toString, trace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.management.NotificationBroadcaster
addNotificationListener, removeNotificationListener
-
Methods inherited from interface javax.management.NotificationEmitter
removeNotificationListener
-
-
-
-
Field Detail
-
GET
protected static final String GET
- See Also:
- Constant Field Values
-
SET
protected static final String SET
- See Also:
- Constant Field Values
-
mMBeanInfo
protected volatile MBeanInfo mMBeanInfo
-
EMPTY_OBJECT_NAMES
protected static final ObjectName[] EMPTY_OBJECT_NAMES
-
GET_PREFIX
protected static final String GET_PREFIX
- See Also:
- Constant Field Values
-
OBJECT_NAME_SUFFIX
protected static final String OBJECT_NAME_SUFFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AMXImplBase
public AMXImplBase(ObjectName parentObjectName, Class<? extends AMX_SPI> intf)
-
AMXImplBase
public AMXImplBase(ObjectName parentObjectName)
-
AMXImplBase
public AMXImplBase(ObjectName parentObjectName, MBeanInfo mbeanInfo)
-
-
Method Detail
-
getMBeanInfo
public MBeanInfo getMBeanInfo()
- Specified by:
getMBeanInfoin interfaceDynamicMBean
-
shouldEmitNotifications
protected final boolean shouldEmitNotifications()
-
getNotificationInfo
public MBeanNotificationInfo[] getNotificationInfo()
- Specified by:
getNotificationInfoin interfaceNotificationBroadcaster
-
getProxyFactory
protected ProxyFactory getProxyFactory()
-
getProxy
protected <T extends AMXProxy> T getProxy(ObjectName objectName, Class<T> intf)
-
getSelf
protected AMXProxy getSelf()
-
getParent
public final ObjectName getParent()
Description copied from interface:AMX_SPIReturn the ObjectName of the parent. Must not be null (except for DomainRoot)
-
getAncestorByType
protected ObjectName getAncestorByType(String type)
-
getParentProxy
public final AMXProxy getParentProxy()
-
getMBeanTracker
public MBeanTrackerMBean getMBeanTracker()
-
getChildren
public ObjectName[] getChildren()
Description copied from interface:AMX_SPIIf no children are possible (a leaf node), an AttributeNotFoundException should be thrown.- Specified by:
getChildrenin interfaceAMX_SPI
-
getChildren
public ObjectName[] getChildren(Class<?> clazz)
-
getChildren
public ObjectName[] getChildren(String type)
-
getChildren
public ObjectName[] getChildren(Set<String> types)
-
getChildrenMap
public Map<String,ObjectName> getChildrenMap(String type)
-
supportsChildren
protected boolean supportsChildren()
-
child
protected ObjectName child(String type, String name)
-
child
protected ObjectName child(String type)
-
child
protected ObjectName child(Class<?> intf)
-
isUtilityMBean
protected static boolean isUtilityMBean(Class mbeanInterface)
-
unimplementedOperation
protected final void unimplementedOperation(String operation)
An operation has not been implemented. Deal with appropriately.
-
unimplementedAttribute
protected final Object unimplementedAttribute(String attrName)
An Attribute has not been implemented.
-
impossible
protected final void impossible(Throwable t)
The impossible has happened.
-
getAttributeInfos
protected Map<String,MBeanAttributeInfo> getAttributeInfos()
-
getAttributeInfo
protected MBeanAttributeInfo getAttributeInfo(String name)
-
isReadOnlyAttribute
protected boolean isReadOnlyAttribute(String name)
-
getLogger
public Logger getLogger()
-
getAttribute
public final Object getAttribute(String name) throws AttributeNotFoundException
Get an Attribute value, first by looking for a getter method of the correct name and signature, then by looking for a delegate, and finally by calling getAttributeManually(), which a subclass is expected to override.- Specified by:
getAttributein interfaceDynamicMBean- Parameters:
name- name of the Attribute- Returns:
- value of the Attribute
- Throws:
AttributeNotFoundException
-
getAttributeInternal
protected Object getAttributeInternal(String name) throws AttributeNotFoundException, ReflectionException, MBeanException
-
getAttributes
public AttributeList getAttributes(String[] names)
Bulk get. Note that is is important for this implementation to call getAttribute() for each name so that each may be processed appropriately; some Attributes may be in this MBean itself.- Specified by:
getAttributesin interfaceDynamicMBean- Parameters:
names- array of Attribute names- Returns:
- AttributeList of Attributes successfully fetched
-
getAttributeByMethod
protected Object getAttributeByMethod(String attrName, Method m) throws AttributeNotFoundException
Set an Attribute by invoking the supplied method.- Throws:
AttributeNotFoundException
-
setAttributeByMethod
protected void setAttributeByMethod(Attribute attr, Method m) throws AttributeNotFoundException, InvalidAttributeValueException
-
attributeNameToType
protected String[] attributeNameToType(String attributeName)
Supply possible types to be tried based on attribute name
-
getObjectNamesForAttribute
protected ObjectName[] getObjectNamesForAttribute(String attributeName)
get child ObjectNameBuilder corresponding to the AttributeName
-
getObjectNameAttribute
protected ObjectName getObjectNameAttribute(String attributeName)
get child ObjectName corresponding to the AttributeName
-
getAttributeManually
protected Object getAttributeManually(String attributeName) throws AttributeNotFoundException, ReflectionException, MBeanException
Subclasses should override this to handle getAttribute( attrName ). It will be called if no appropriate getter is found.
-
setAttributeManually
protected void setAttributeManually(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException
Subclasses should override this to handle setAttribute( attr ). It will be called if no appropriate setter is found.
-
setAttribute
public void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException
- Specified by:
setAttributein interfaceDynamicMBean- Throws:
AttributeNotFoundExceptionInvalidAttributeValueException
-
setAttributeInternal
protected void setAttributeInternal(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException
Set an Attribute value, first by looking for a setter method of the correct name and signature, then by looking for a delegate, and finally by calling setAttributeManually(), which a subclass is expected to override.- Parameters:
attr- the Attribute- Throws:
AttributeNotFoundExceptionInvalidAttributeValueException
-
sendAttributeChangeNotification
protected void sendAttributeChangeNotification(String msg, String name, String attrType, long when, Object oldValue, Object newValue)
-
setAttributes
public AttributeList setAttributes(AttributeList attrs)
Note that the default implementation sets attributes one at a time, but that MBeans with transactional requirements (eg configuration) may wish to set them as a group.- Specified by:
setAttributesin interfaceDynamicMBean
-
findMethod
protected final Method findMethod(String methodName, Class[] sig)
Find a method.- Parameters:
methodName-sig-- Returns:
- a Method or null if not found
-
findSetter
protected final Method findSetter(Attribute attr)
Find a setXXX() method that matches the Attribute.- Parameters:
attr- an Attribute for which a matching setter should be located- Returns:
- a Method or null if not found
-
operationNameMatches
protected boolean operationNameMatches(String operationName, String prefix, String suffix)
-
handleException
protected void handleException(Exception e) throws MBeanException, ReflectionException
- Throws:
MBeanExceptionReflectionException
-
handleGetAttributeException
protected void handleGetAttributeException(Exception e) throws MBeanException, ReflectionException, AttributeNotFoundException
-
handleInvokeThrowable
protected void handleInvokeThrowable(Exception e) throws MBeanException, ReflectionException
- Throws:
MBeanExceptionReflectionException
-
invoke
public final Object invoke(String operationName, Object[] args, String[] types) throws MBeanException, ReflectionException
Generic handling of invoke(). Converts the types[] to a Class[], then attempts to locate a suitable Method. If a suitable Method is found, it is invoked. If not found the subclass is expected to handle it in invokeManually();- Specified by:
invokein interfaceDynamicMBean- Throws:
MBeanExceptionReflectionException
-
invokeManually
protected Object invokeManually(String operationName, Object[] args, String[] types) throws MBeanException, ReflectionException, NoSuchMethodException, AttributeNotFoundException
An operation is being invoked manually, meaning that it is missing as a method. invokeManually() will be called only if no appropriate Method is found.Subclasses may override this to handle invoke(), though usually it's just easier to write the appropriate method directly, which will be found and called if present.
-
getName
public String getName()
A subclass might need to override this method if its name contains characters that are illegal for the ObjectName.
-
preRegisterModifyName
protected ObjectName preRegisterModifyName(MBeanServer server, ObjectName nameIn)
O the ObjectName by adding to it:- adding AMX.FULL_TYPE_KEY property
-
preRegister
public final ObjectName preRegister(MBeanServer server, ObjectName nameIn) throws Exception
- Specified by:
preRegisterin interfaceMBeanRegistration- Overrides:
preRegisterin classMBeanImplBase- Throws:
Exception
-
preRegisterHook
protected ObjectName preRegisterHook(MBeanServer server, ObjectName selfObjectName) throws Exception
This is an opportunity for a subclass to do initialization and optionally to modify the ObjectName one last time.- Throws:
Exception
-
postRegisterModifyMBeanInfo
protected MBeanInfo postRegisterModifyMBeanInfo(MBeanInfo info)
Hook for a subclass when registration is complete
-
postRegisterHook
protected void postRegisterHook(Boolean registrationSucceeded)
Important: must be synchronized so that preDeregisterHook cannot be called prior to existing postRegisterHook()- Overrides:
postRegisterHookin classMBeanImplBase
-
registerChildren
protected void registerChildren()
-
preDeregisterHook
protected void preDeregisterHook() throws ExceptionImportant: must be synchronized so that it cannot be called prior to exiting postRegisterHook()- Overrides:
preDeregisterHookin classMBeanImplBase- Throws:
Exception
-
unregisterChildren
protected void unregisterChildren()
-
getDomainRootProxy
public final DomainRoot getDomainRootProxy()
-
getDomainRoot
public final ObjectName getDomainRoot()
-
java
public String java()
-
registerChild
protected ObjectName registerChild(Object mbean, ObjectName childObjectName)
-
getObjectNames
protected ObjectNameBuilder getObjectNames()
-
-