-
1. Re: how to 'clone' an XMBean
juha Jan 8, 2004 6:10 AM (in response to jj)Where do you set the resource reference your XMBean is supposed to manage?
-
2. Re: how to 'clone' an XMBean
jj Jan 9, 2004 6:34 PM (in response to jj)The following appears to solve this problem. I'd appreciate any comments. Thanks in advance,
jj
// get the ModelMBeanInfo, is there any easier way???
MBeanRegistry registry = (MBeanRegistry) MBeanProxyExt.create(MBeanRegistry.class,
ServerConstants.MBEAN_REGISTRY, server);
MBeanEntry entry = registry.get(this.serviceName);
XMBean myXMBean = (XMBean) entry.getMBean();
ModelMBeanInfo minfo = myXMBean.getModelMBeanInfo();
// create a new instance of the invoking subclass, clone isn't supported
Object newInstance = this.getClass().getConstructor(new Class[] {}).newInstance(new Object[] {});
// create the new XMBean with the newInstance as its resource
XMBean xmb = new XMBean(newInstance, OBJECT_REF);
// clone the ModelMBeanInfo, is this necessary???? It's probably cloned in setModelMBeanInfo below - check
minfo = (ModelMBeanInfo) minfo.clone();
// set the persist name to point to a new file according to 'newName'
minfo.getMBeanDescriptor().setField(ModelMBeanConstants.PERSIST_NAME, newName + ".ser");
// set the management interface
xmb.setModelMBeanInfo(minfo);
// register the new bean with the server
server.registerMBean(xmb, newObjName);