在本地或远程 mbean server 中为 mxbean 构造一个代理。
如果 mbean 服务器 mbs 包含 objectname 为 name 的 mxbean,并且如果该 mxbean 的管理接口由 java 接口 mymxbean 所描述,则可以像下面这样为该 mxbean 构造一个代理:
mymxbean proxy = jmx.newmxbeanproxy(mbs, name, mymxbean.class);
例如,假定 mymxbean 如下所示:
public interface mymxbean {
public string getsimpleattribute();
public void setsimpleattribute(string value);
public memoryusage getmappedattribute();
public void setmappedattribute(memoryusage memoryusage);
public memoryusage someoperation(string param1, memoryusage param2);
}
那么:
proxy.getsimpleattribute() 将导致调用 mbs.getattribute(name, "simpleattribute")。
proxy.setsimpleattribute("whatever") 将导致调用 mbs.setattribute(name, new attribute("simpleattribute", "whatever"))。
因为 string 是一个简单类型(即 simpletype),所以不会在 mxbean 的上下文中更改它。mxbean 代理的行为与属性 simpleattribute 的 standard mbean 代理(请参阅 newmbeanproxy)的行为相同。
proxy.getmappedattribute() 将导致调用 mbs.getattribute("mappedattribute")。mxbean 映射规则意味着属性 mappedattribute 的实际类型将是 compositedata,并且这是 mbs.getattribute 调用将返回的内容。该代理然后会使用 mxbean 映射规则将 compositedata 转换回所期望类型的 memoryusage。
类似地,proxy.setmappedattribute(memoryusage) 将在调用 mbs.setattribute 之前将 memoryusage 参数转换为 compositedata。
proxy.someoperation("whatever", memoryusage) 将 memoryusage 参数转换为 compositedata 并调用 mbs.invoke。mbs.invoke 返回的值也将是 compositedata,并且代理会使用 mxbean 映射规则将此值转换为所期望类型的 memoryusage。
此方法返回的对象是一个 invocationhandler 为 mbeanserverinvocationhandler 的 proxy。
此方法等效于 newmxbeanproxy(connection, objectname, interfaceclass, false)。
- 类型参数:
t - 让编译器知道如果 interfaceclass 参数为 mymxbean.class,则返回类型为 mymxbean。- 参数:
connection - 作为转发目的地的目标 mbean 服务器。objectname - 作为转发目的地的 connection 中的 mbean 名。interfaceclass - mxbean 接口,也由返回的代理来实现。
- 返回:
- 新的代理实例。