java - Register more than one MBean of same MBean class -


i want register more 1 mbean of same class.

i have hello class implementing hellombean interface.

now in main have 2 object of hello class , want register them both

mbeanserver mbs = managementfactory.getplatformmbeanserver(); objectname name = new objectname("mbeans:type=hello");  hello h1 = new hello(); hello h2 = new hello();  mbs.registermbean(h1, name); mbs.registermbean(h2, name); 

this throws instancealreadyexistsexception .

how can register both h1 , h2, , using jconsole view both of them?


reason of this,

i want change attribute value of both h1 , h2 object through mbean

you need register each mbean unique name. if no longer receive exception when registering second mbean. have manage each bean separately (i.e. attribute on each home object set through individual mbeans).

mbeanserver mbs = managementfactory.getplatformmbeanserver();  hello h1 = new hello(); hello h2 = new hello();  mbs.registermbean(h1, new objectname("mbeans:type=hello-1")); mbs.registermbean(h2, new objectname("mbeans:type=hello-2")); 

if want manage 2 hello objects @ same time through 1 mbean, (i.e change attribute on 1 mbean results in change on both hello objects) try using composite hello object , expose mbean.

common interface:

interface ihello {     void setattribute(int value); } 

single hello object:

class hello implements ihello {     int attribute;      void setattribute(int value) {         attribute = value;     } } 

composite hello object:

class compositehello implements ihello {     ihello[] hellos;      compositehome(ihello...hellos) {         super();         this.hellos = hellos;     }      void setattribute(int value) {         (ihello hello : hello) {             home.setattribute(value);         }     } } 

register composite mbean:

mbeanserver mbs = managementfactory.getplatformmbeanserver();  hello h1 = new hello(); hello h2 = new hello(); compositehello composite = new compositehello(h1, h2); mbs.registermbean(composite, new objectname("mbeans:type=hello")); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -