Spring集成JMX是很简单的,这里通过注解发方式暴露JMX,有的时序我们需要监听JMX属性的改变,下面我们在Spring配置文件中配置监听器。
涉及到三个重要的annotation:@ManagedResource @ManagedAttribute 和 @ManagedOperation。
用途 Commons Attributes属性 JDK 5.0注解 属性/注解类型
将类的所有实例标识为JMX受控资源 | ManagedResource |
@ManagedResource |
Class 类 |
将方法标识为JMX操作 | ManagedOperation |
@ManagedOperation |
Method方法 |
将getter或者setter标识为部分JMX属性 | ManagedAttribute |
@ManagedAttribute |
Method (only getters and setters) 方法(仅getters和setters) |
定义操作参数说明 | ManagedOperationParameter |
@ManagedOperationParameter 和@ManagedOperationParameters |
Method 方法 |
Parameter | Description | Applies to |
---|---|---|
ObjectName | Used by MetadataNamingStrategy to determine the ObjectName of a managed resource | ManagedResource |
description | Sets the friendly description of the resource, attribute or operation | ManagedResource, ManagedAttribute, ManagedOperation, ManagedOperationParameter |
currencyTimeLimit | Sets the value of the currencyTimeLimit descriptor field | ManagedResource, ManagedAttribute |
defaultValue | Sets the value of the defaultValue descriptor field | ManagedAttribute |
log | Sets the value of the log descriptor field | ManagedResource |
logFile | Sets the value of the logFile descriptor field | ManagedResource |
persistPolicy | Sets the value of the persistPolicy descriptor field | ManagedResource |
persistPeriod | Sets the value of the persistPeriod descriptor field | ManagedResource |
persistLocation | Sets the value of the persistLocation descriptor field | ManagedResource |
persistName | Sets the value of the persistName descriptor field | ManagedResource |
name | Sets the display name of an operation parameter | ManagedOperationParameter |
index | Sets the index of an operation parameter | ManagedOperationParameter |
AttributeChangeNotification,这个类是javax.management.Notification的子类,而javax.management.Notification
这个类又是java.util.EventObject的子类,由此可以证实上边所说的,JMX通知机制使用了观察者设计模式.
javax.management