public class AMXImplBase extends MBeanImplBase implements DynamicMBean, NotificationEmitter, AMX_SPI
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.
| Modifier and Type | Field and Description |
|---|---|
protected static ObjectName[] |
EMPTY_OBJECT_NAMES |
protected static String |
GET |
protected static String |
GET_PREFIX |
protected MBeanInfo |
mMBeanInfo |
protected static String |
OBJECT_NAME_SUFFIX |
protected static String |
SET |
EMPTY_STRING_ARRAY, mSelfObjectName, mServer| Constructor and Description |
|---|
AMXImplBase(ObjectName parentObjectName) |
AMXImplBase(ObjectName parentObjectName,
Class<? extends AMX_SPI> intf) |
AMXImplBase(ObjectName parentObjectName,
MBeanInfo mbeanInfo) |
| Modifier and Type | Method and Description |
|---|---|
protected String[] |
attributeNameToType(String attributeName)
Supply possible types to be tried based on attribute name
|
protected boolean |
attributeTypeMatches(String attributeName,
Class<?> clazz) |
protected ObjectName |
child(Class<?> intf) |
protected ObjectName |
child(String type) |
protected ObjectName |
child(String type,
String name) |
protected Method |
findGetter(String name) |
protected Method |
findMethod(String methodName,
Class[] sig)
Find a method.
|
protected Method |
findSetter(Attribute attr)
Find a setXXX() method that matches the Attribute.
|
protected ObjectName |
getAncestorByType(String type) |
Object |
getAttribute(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 Object |
getAttributeByMethod(String attrName,
Method m)
Set an Attribute by invoking the supplied method.
|
protected MBeanAttributeInfo |
getAttributeInfo(String name) |
protected Map<String,MBeanAttributeInfo> |
getAttributeInfos() |
protected Object |
getAttributeInternal(String name) |
protected Object |
getAttributeManually(String attributeName)
Subclasses should override this to handle getAttribute( attrName ).
|
Set<String> |
getAttributeNames() |
protected Object |
getAttributeNoThrow(String name) |
AttributeList |
getAttributes(String[] names)
Bulk get.
|
protected String |
getAttributeType(String attrName) |
ObjectName[] |
getChildren()
If no children are possible (a leaf node), an AttributeNotFoundException should be thrown.
|
ObjectName[] |
getChildren(Class<?> clazz) |
ObjectName[] |
getChildren(Set<String> types) |
ObjectName[] |
getChildren(String type) |
Map<String,ObjectName> |
getChildrenMap(String type) |
ObjectName |
getDomainRoot() |
DomainRoot |
getDomainRootProxy() |
Logger |
getLogger() |
MBeanInfo |
getMBeanInfo() |
MBeanTrackerMBean |
getMBeanTracker() |
String |
getName()
A subclass might need to override this method if its name contains characters
that are illegal for the ObjectName.
|
MBeanNotificationInfo[] |
getNotificationInfo() |
protected ObjectName |
getObjectNameAttribute(String attributeName)
get child ObjectName corresponding to the AttributeName
|
protected ObjectNameBuilder |
getObjectNames() |
protected ObjectName[] |
getObjectNamesForAttribute(String attributeName)
get child ObjectNameBuilder corresponding to the AttributeName
|
ObjectName |
getParent()
Return the ObjectName of the parent.
|
AMXProxy |
getParentProxy() |
protected <T extends AMXProxy> |
getProxy(ObjectName objectName,
Class<T> intf) |
protected ProxyFactory |
getProxyFactory() |
protected AMXProxy |
getSelf() |
protected <T extends AMXProxy> |
getSelf(Class<T> intf) |
protected boolean |
getterNameMatches(String operationName,
String suffix) |
protected void |
handleException(Exception e) |
protected void |
handleGetAttributeException(Exception e) |
protected void |
handleInvokeThrowable(Exception e) |
protected void |
impossible(Throwable t)
The impossible has happened.
|
Object |
invoke(String operationName,
Object[] args,
String[] types)
Generic handling of invoke().
|
protected Object |
invokeManually(String operationName,
Object[] args,
String[] types)
An operation is being invoked manually, meaning that it is missing as a method.
|
protected boolean |
isReadOnlyAttribute(String name) |
protected static boolean |
isUtilityMBean(Class mbeanInterface) |
String |
java() |
protected boolean |
operationNameMatches(String operationName,
String prefix,
String suffix) |
protected void |
postRegisterHook(Boolean registrationSucceeded)
Important: must be synchronized so that preDeregisterHook cannot be called prior to
existing postRegisterHook()
|
protected MBeanInfo |
postRegisterModifyMBeanInfo(MBeanInfo info)
Hook for a subclass when registration is complete
|
protected void |
preDeregisterHook()
Important: must be synchronized so that it cannot be called prior to exiting postRegisterHook()
|
ObjectName |
preRegister(MBeanServer server,
ObjectName nameIn) |
protected void |
preRegisterDone() |
protected ObjectName |
preRegisterHook(MBeanServer server,
ObjectName selfObjectName)
This is an opportunity for a subclass to do initialization
and optionally to modify the ObjectName one last time.
|
protected ObjectName |
preRegisterModifyName(MBeanServer server,
ObjectName nameIn)
O the ObjectName by adding to it:
adding AMX.FULL_TYPE_KEY property
|
protected ObjectName |
registerChild(Object mbean,
ObjectName childObjectName) |
protected void |
registerChildren() |
protected void |
sendAttributeChangeNotification(String msg,
String name,
String attrType,
long when,
Object oldValue,
Object newValue) |
void |
setAttribute(Attribute attr) |
protected void |
setAttributeByMethod(Attribute attr,
Method m) |
protected void |
setAttributeInternal(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 void |
setAttributeManually(Attribute attr)
Subclasses should override this to handle setAttribute( attr ).
|
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.
|
protected boolean |
shouldEmitNotifications() |
protected String |
stringify(Object o) |
protected boolean |
supportsChildren() |
String |
toString() |
protected Object |
unimplementedAttribute(String attrName)
An Attribute has not been implemented.
|
protected void |
unimplementedOperation(String operation)
An operation has not been implemented.
|
protected void |
unregisterChildren() |
_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, traceclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitremoveNotificationListeneraddNotificationListener, removeNotificationListenerprotected static final String GET
protected static final String SET
protected volatile MBeanInfo mMBeanInfo
protected static final ObjectName[] EMPTY_OBJECT_NAMES
protected static final String GET_PREFIX
protected static final String OBJECT_NAME_SUFFIX
public AMXImplBase(ObjectName parentObjectName, Class<? extends AMX_SPI> intf)
public AMXImplBase(ObjectName parentObjectName)
public AMXImplBase(ObjectName parentObjectName, MBeanInfo mbeanInfo)
public MBeanInfo getMBeanInfo()
getMBeanInfo in interface DynamicMBeanprotected final boolean shouldEmitNotifications()
public MBeanNotificationInfo[] getNotificationInfo()
getNotificationInfo in interface NotificationBroadcasterprotected ProxyFactory getProxyFactory()
protected <T extends AMXProxy> T getProxy(ObjectName objectName, Class<T> intf)
protected AMXProxy getSelf()
public final ObjectName getParent()
AMX_SPIprotected ObjectName getAncestorByType(String type)
public final AMXProxy getParentProxy()
public MBeanTrackerMBean getMBeanTracker()
public ObjectName[] getChildren()
AMX_SPIgetChildren in interface AMX_SPIpublic ObjectName[] getChildren(Class<?> clazz)
public ObjectName[] getChildren(String type)
public ObjectName[] getChildren(Set<String> types)
public Map<String,ObjectName> getChildrenMap(String type)
protected boolean supportsChildren()
protected ObjectName child(String type, String name)
protected ObjectName child(String type)
protected ObjectName child(Class<?> intf)
protected static boolean isUtilityMBean(Class mbeanInterface)
protected final void unimplementedOperation(String operation)
protected final Object unimplementedAttribute(String attrName)
protected final void impossible(Throwable t)
protected Map<String,MBeanAttributeInfo> getAttributeInfos()
protected MBeanAttributeInfo getAttributeInfo(String name)
protected boolean isReadOnlyAttribute(String name)
public Logger getLogger()
public final Object getAttribute(String name) throws AttributeNotFoundException
getAttribute in interface DynamicMBeanname - name of the AttributeAttributeNotFoundExceptionprotected Object getAttributeInternal(String name) throws AttributeNotFoundException, ReflectionException, MBeanException
public AttributeList getAttributes(String[] names)
getAttributes in interface DynamicMBeannames - array of Attribute namesprotected Object getAttributeByMethod(String attrName, Method m) throws AttributeNotFoundException
AttributeNotFoundExceptionprotected void setAttributeByMethod(Attribute attr, Method m) throws AttributeNotFoundException, InvalidAttributeValueException
protected String[] attributeNameToType(String attributeName)
protected ObjectName[] getObjectNamesForAttribute(String attributeName)
protected ObjectName getObjectNameAttribute(String attributeName)
protected Object getAttributeManually(String attributeName) throws AttributeNotFoundException, ReflectionException, MBeanException
protected void setAttributeManually(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException
public void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException
setAttribute in interface DynamicMBeanAttributeNotFoundExceptionInvalidAttributeValueExceptionprotected void setAttributeInternal(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException
attr - the AttributeAttributeNotFoundExceptionInvalidAttributeValueExceptionprotected void sendAttributeChangeNotification(String msg, String name, String attrType, long when, Object oldValue, Object newValue)
public AttributeList setAttributes(AttributeList attrs)
setAttributes in interface DynamicMBeanprotected final Method findMethod(String methodName, Class[] sig)
methodName - sig - protected final Method findSetter(Attribute attr)
attr - an Attribute for which a matching setter should be locatedprotected boolean operationNameMatches(String operationName, String prefix, String suffix)
protected void handleException(Exception e) throws MBeanException, ReflectionException
MBeanExceptionReflectionExceptionprotected void handleGetAttributeException(Exception e) throws MBeanException, ReflectionException, AttributeNotFoundException
protected void handleInvokeThrowable(Exception e) throws MBeanException, ReflectionException
MBeanExceptionReflectionExceptionpublic final Object invoke(String operationName, Object[] args, String[] types) throws MBeanException, ReflectionException
invoke in interface DynamicMBeanMBeanExceptionReflectionExceptionprotected Object invokeManually(String operationName, Object[] args, String[] types) throws MBeanException, ReflectionException, NoSuchMethodException, AttributeNotFoundException
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.
public String getName()
protected ObjectName preRegisterModifyName(MBeanServer server, ObjectName nameIn)
public final ObjectName preRegister(MBeanServer server, ObjectName nameIn) throws Exception
preRegister in interface MBeanRegistrationpreRegister in class MBeanImplBaseExceptionprotected ObjectName preRegisterHook(MBeanServer server, ObjectName selfObjectName) throws Exception
Exceptionprotected MBeanInfo postRegisterModifyMBeanInfo(MBeanInfo info)
protected void postRegisterHook(Boolean registrationSucceeded)
postRegisterHook in class MBeanImplBaseprotected void registerChildren()
protected void preDeregisterHook()
throws Exception
preDeregisterHook in class MBeanImplBaseExceptionprotected void unregisterChildren()
public final DomainRoot getDomainRootProxy()
public final ObjectName getDomainRoot()
public String java()
protected ObjectName registerChild(Object mbean, ObjectName childObjectName)
protected ObjectNameBuilder getObjectNames()
Copyright © 2019. All rights reserved.