Hi Shenglin Sorry for a few days delay in commenting about your test project which you posted to me, I just looked at the code, here are the comments. First of all, it's a good progress, I think you are on the way to completing the 1st phase of the project, we should aim at the end of the next week. The code needs some cleanup and a bit of refactoring, but overall it's not too bad at all.
So here are the comments: - You need to make sure list() function, when called multiple times, returns the same result. What will happen, with the way you wrote it, is that individual MBeans will have different hrefs every time list() is called. That means the ID allocator also has to be a JAX-RS server field. Make sure the ID allocator and Map are thread-safe. - resource methods handling service/{service}, port/{port}, type/{type} and objectname/{objectname} are just duplicating each other - can you please review what we were discussion about having a single resource method which deals with queries where individual attributes such as 'service' or 'port' are provided ? We can have many attributes so we can' allocate a new resource method per every possible attribute a given MBean may have. - list() and resource methods handling service/{service}/etc return different MBean representations, service/{service}/etc methods should also return MBeans with *href* attributes. Basically all JMXServer resource methods returning MBeans should return MBeans with hrefs, and those hrefs should be the same for a particular MBean across multiple calls. The order of calls (ex, list() is called first or service/{service}) must not make any difference as far as creating and locating correct MBean href values is concerned. Just make sure that all of those methods delegate to some common function which checks if an 'id' has already been allocated for a given MBean and if yes then use the existing href. - /mbean handler is correct, as far as using subresource locator is concerned, very good. Note it should only use list() if no mbean with a given id has already been saved in the map before. Another thing is that CxfMBean which is also a JAXB bean is better not to be a subresource. It will be cleaner for our purposes to have a dedicated subresource handler, MBeanResource for ex, because we will need to deal with property updates and handling notification updates, etc. CxfMBean will just grow too large and it may also affect its JAXB serialization/etc - Remove Cxf prefixes from all you domain classes, and instead of adding individual CxfMBeanAttribute setters such as setService, etc, add some Pair class which holds name and value and then add a List<Pair> to CxfMBeanAttribute, this is to make sure new attributes can be handled easily Please focus on the above, once you are done we'll discuss again how to avoid registering lists of JAXWS and JAX-RS endpoints with JAX-RS server, as well as what we can do about dealing with the CXF Mbean dealing with statistics, and how to handle notifications to do with changes of individual CXF MBeans. Thanks, Sergey On Sat, May 21, 2011 at 7:39 PM, Shenglin Qiu <dabaip...@hotmail.com> wrote: > Hi Sergey: > > I am able to use sub-resource locator and @UriInfo and implement: > class JMXServer: > > @Path("/mbean/") > public CxfMBean locateMBean() throws MalformedObjectNameException, > NullPointerException{ > UriBuilder uriBuilder = > uriInfo.getBaseUriBuilder().path(this.getClass(), "list"); > System.out.println("uriInfo.getPath() = "+uriInfo.getPath()); > String key = uriInfo.getPath().substring("mbean/".length()); > System.out.println(key); > CxfMBeanCollection cxfMBeans = list(); > CxfMBean cxfMBean = cxfMBeans.getCxfMBean(key); > return cxfMBean; > } > > class CxfMBeanCollection: > > public CxfMBean getCxfMBean(String key){ > for(CxfMBean cxfMBean : cxfMBeans){ > if(cxfMBean.getId() != null && cxfMBean.getId().equals(key)){ > return cxfMBean; > } > } > return null; > } > > class CxfMBean: > > @GET > @Path("{key}") > public CxfMBean getCxfMBean(@PathParam("key") String key){ > if(id != null && id.equals(key)){ > return this; > }else{ > return null; > } > } > > > Request: > http://localhost:8080/services/jmx/mbean/5 > Response: > <MBean href="http://localhost:8080/services/jmx/mbean/5"> > <attribute> > <busId>cxf32436715</busId> > <port>"UserServiceImpl"</port> > <service>"{http://server.gsoc.apache.org/}UserServiceImpl"</service> > <type>Bus.Service.Endpoint</type> > </attribute> > <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="UserServiceImpl",service="{http://server.gsoc.apache.org/}UserServiceImpl",type=Bus.Service.Endpoint</canonicalName> > <domain>org.apache.cxf</domain> > <id>5</id> > </MBean> > > And so on for other mbean with id 1, 3, 4, 5, 6 and response with the same > format > <MBean href="http://localhost:8080/services/jmx/mbean/3"> > <attribute> > <busId>cxf32436715</busId> > <type>Bus</type> > </attribute> > <canonicalName>org.apache.cxf:bus.id=cxf32436715,type=Bus</canonicalName> > <domain>org.apache.cxf</domain> > <id>3</id> > </MBean> > > > Request: > http://localhost:8080/services/jmx/list > Response: > <MBeans> > <MBean href="http://localhost:8080/services/jmx/mbean/5"> > <attribute> > <busId>cxf32436715</busId> > <port>"UserServiceImpl"</port> > <service>"{http://server.gsoc.apache.org/}UserServiceImpl"</service> > <type>Bus.Service.Endpoint</type> > </attribute> > <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="UserServiceImpl",service="{http://server.gsoc.apache.org/}UserServiceImpl",type=Bus.Service.Endpoint</canonicalName> > <domain>org.apache.cxf</domain> > <id>5</id> > </MBean> > <MBean href="http://localhost:8080/services/jmx/mbean/4"> > <attribute> > <busId>cxf32436715</busId> > <port>"SoapPort"</port> > <service>"{http://org.apache.gsoc.server/Greeter_Soap}SOAPService"</service> > <type>Bus.Service.Endpoint</type> > </attribute> > <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="SoapPort",service="{http://org.apache.gsoc.server/Greeter_Soap}SOAPService",type=Bus.Service.Endpoint</canonicalName> > <domain>org.apache.cxf</domain> > <id>4</id> > </MBean> > <MBean href="http://localhost:8080/services/jmx/mbean/3"> > <attribute> > <busId>cxf32436715</busId> > <type>Bus</type> > </attribute> > <canonicalName>org.apache.cxf:bus.id=cxf32436715,type=Bus</canonicalName> > <domain>org.apache.cxf</domain> > <id>3</id> > </MBean> > <MBean href="http://localhost:8080/services/jmx/mbean/1"> > <attribute> > <busId>cxf32436715</busId> > <port>"CustomerServiceImpl"</port> > <service>"{http://server.gsoc.apache.org/}CustomerServiceImpl"</service> > <type>Bus.Service.Endpoint</type> > </attribute> > <canonicalName>org.apache.cxf:bus.id=cxf32436715,port="CustomerServiceImpl",service="{http://server.gsoc.apache.org/}CustomerServiceImpl",type=Bus.Service.Endpoint</canonicalName> > <domain>org.apache.cxf</domain> > <id>1</id> > </MBean> > <MBean href="http://localhost:8080/services/jmx/mbean/6"> > <attribute> > <type>MBeanServerDelegate</type> > </attribute> > <canonicalName>JMImplementation:type=MBeanServerDelegate</canonicalName> > <domain>JMImplementation</domain> > <id>6</id> > </MBean> > </MBeans> > > > I will clean up my code a little for the next step. > > Thank you. > > Regards: > Shenglin Qiu > > >> Date: Sat, 21 May 2011 16:37:29 +0100 >> Subject: Re: Expose MBeans in CXF >> From: sberyoz...@gmail.com >> To: dev@cxf.apache.org >> >> >> Are you saying that you have to use UriInfo and UriBuilder for >> >> creating hrefs whenever you need to >> >> build an MBean representation ? >> >> >> > >> > After everytime server bounces, I need to at first use this url request: >> > http://localhost:8080/services/jmx/, the good thing is, this request only >> > need once, >> > >> >> What do you mean it is needed only once ? >> >> > Then my JMXServer will save the UriInfo and also all the href values in >> > MBean are fixed, no further change until another server's bounce. >> > >> >> I don't understand - as I said on IRC JMXServer should expect >> endpoints created dynamically >> >> Cheers, Sergey >> >> >> Please have UriInfo injected in one of the JMXServer's fields, remove >> >> NPE declaration >> >> >> > Done. >> > >> > >> > I will do a fewer more rounds of testing, and put up the source code >> > again. >> > >> > >> > >> > Thank you. >> > >> > >> > Regards: >> > Shenglin Qiu >> > >> > >> > >> >> Date: Fri, 20 May 2011 11:39:55 +0100 >> >> Subject: Re: Expose MBeans in CXF >> >> From: sberyoz...@gmail.com >> >> To: dabaip...@hotmail.com >> >> CC: dev@cxf.apache.org >> >> >> >> Hi Shenglin >> >> >> >> I've removed some XML fragments to make it simpler to read... >> >> >> >> > Here is what I have right now: >> >> > >> >> > <MBeans> >> >> > <MBean href="http://localhost:8080/services/jmx/mbean/0"> >> >> > </MBean> >> >> > </MBeans> >> >> > >> >> >> >> OK >> >> >> >> > >> >> > And >> >> > Request: >> >> > http://localhost:8080/services/jmx/mbean/0 >> >> > Response: >> >> > <MBean href="http://localhost:8080/services/jmx/mbean/0"> >> >> > </MBean> >> >> > >> >> > And so on with others. >> >> >> >> Very good. >> >> >> >> > >> >> > However, I have to make http://localhost:8080/services/jmx/ at every >> >> > time I >> >> > am trying to do anything further, because I need to use this >> >> > following >> >> > function to load up all mbeans along with their /mbean/** unique >> >> > identifiers, and I think this may not be what you want. Please >> >> > correct me on >> >> > this. >> >> > >> >> Are you saying that you have to use UriInfo and UriBuilder for >> >> creating hrefs whenever you need to >> >> build an MBean representation ? >> >> >> > >> > >> > >> >> Perhaps, you may want to keep "http://localhost:8080/services/jmx/" >> >> parts of hrefs in the map as well, as you suggested on #cxf. This will >> >> let you avoid recalculating the base values for those MBeans which >> >> have already been retrieved before. These values may not 'survive' the >> >> restarts for ex, say a port may've been changed, etc, but I agree it >> >> may be worth optimizing. I'm not sure if injecting UriInfo via >> >> constructor can provide a way to get to the base address at the >> >> JMXServer initialization time - may be worth trying later on... >> >> >> >> Please don't spend much time on it right now, because it's more >> >> important at the moment to try to build a more or less complete >> >> solution around exposing JMX mbeans over HTTP. >> >> >> >> Have a look at it a bit further, and then start focusing on making sure >> >> >> >> "http://localhost:8080/services/jmx/mbean/0", etc, are handled by >> >> MBeanResource subresource, we can keep adding methods for dealing with >> >> individual MBeans to JMXServer itself, but having a subresource >> >> dealing with such requests may be a bit cleaner... >> >> >> >> >> >> > @GET >> >> > public CxfMBeanCollection traversMBeans(@Context UriInfo uriInfo) >> >> > throws >> >> > MalformedObjectNameException, NullPointerException{ >> >> > .... >> >> > } >> >> > >> >> > >> >> >> >> Please have UriInfo injected in one of the JMXServer's fields, remove >> >> NPE declaration >> >> >> >> Cheers, Sergey >> >> > >> >> > Thank you. >> >> > >> >> > Regards: >> >> > Shenglin Qiu >> >> > >> >> > >> >> >> Date: Thu, 19 May 2011 17:02:36 +0100 >> >> >> Subject: Re: Expose MBeans in CXF >> >> >> From: sberyoz...@gmail.com >> >> >> To: dev@cxf.apache.org >> >> >> >> >> >> Every MBean should have a unique id so that we can work with it >> >> >> later >> >> >> on individually. >> >> >> 0, 1, 2, 3, n, represents the unique part in the otherwise same URI. >> >> >> When working with MBeans (when populating MBeans collections, etc) >> >> >> you >> >> >> need to associate some unique number with every MBean. Have some >> >> >> local >> >> >> AtomicInteger var, have some map there which will keep pairs like >> >> >> id: Mbean ref >> >> >> >> >> >> and generate 'id' dynamically if none already exists in the map for >> >> >> a >> >> >> given MBean >> >> >> >> >> >> may be it should be >> >> >> >> >> >> Map<String, Integer> >> >> >> where String is a canonical name. >> >> >> >> >> >> So when later on you process something like >> >> >> /mbean/234 >> >> >> >> >> >> you can get 234, use it to find the canonical name (or actual JMX >> >> >> MBean reference), and use the latter to init an instance of >> >> >> MBeanResource which will deal with the request >> >> >> >> >> >> Ping me on IRC please if you have any questions >> >> >> Cheers, Sergey >> >> >> >> >> >> On Thu, May 19, 2011 at 4:43 PM, Shenglin Qiu >> >> >> <dabaip...@hotmail.com> >> >> >> wrote: >> >> >> > >> >> >> > Yes, Sergey, >> >> >> > >> >> >> > Should I manually give/define every mbean an indexer which is >> >> >> > accumulated as you mentioned? >> >> >> >> > http://localhost:8080/services/jmx/mbean/0 >> >> >> >> > http://localhost:8080/services/jmx/mbean/1 >> >> >> >> > http://localhost:8080/services/jmx/mbean/2 >> >> >> > ... >> >> >> >> > http://localhost:8080/services/jmx/mbean/*** >> >> >> > Thank you. >> >> >> > >> >> >> > Regards: >> >> >> > Shenglin Qiu >> >> >> > >> >> >> >> Date: Thu, 19 May 2011 15:03:03 +0100 >> >> >> >> Subject: Re: Expose MBeans in CXF >> >> >> >> From: sberyoz...@gmail.com >> >> >> >> To: dev@cxf.apache.org >> >> >> >> >> >> >> >> HI Shenglin >> >> >> >> >> >> >> >> On Thu, May 19, 2011 at 2:54 PM, Shenglin Qiu >> >> >> >> <dabaip...@hotmail.com> >> >> >> >> wrote: >> >> >> >> > >> >> >> >> > Yes Sergey, will have these following pattern: >> >> >> >> > >> >> >> >> > http://localhost:8080/services/jmx/mbean/0 -> CXF Bus >> >> >> >> > >> >> >> >> > http://localhost:8080/services/jmx/mbean/01 -> UserService >> >> >> >> > >> >> >> >> > http://localhost:8080/services/jmx/mbean/0123 -> >> >> >> >> > CustomerService >> >> >> >> > >> >> >> >> > http://localhost:8080/services/jmx/mbean/01234 -> >> >> >> >> > GreeterService >> >> >> >> > (Soap) >> >> >> >> > >> >> >> >> > http://localhost:8080/services/jmx/mbean/012 -> JMXServer >> >> >> >> > will be >> >> >> >> > hidden to user. >> >> >> >> > >> >> >> >> >> >> >> >> That looks better, but do you think it would make sense to avoid >> >> >> >> the >> >> >> >> concatenation ? >> >> >> >> We can get hundreds of CXF MBeans in the production environment, >> >> >> >> so >> >> >> >> IMHO it would be simpler >> >> >> >> to have /mbean/199 identifying a particular MBean, >> >> >> >> >> >> >> >> Cheers, Sergey >> >> >> >> >> >> >> >> > >> >> >> >> > Regards: >> >> >> >> > >> >> >> >> > Shenglin Qiu >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> > >> >> >> >> >> >> >> >> >> >> >> >> -- >> >> >> Sergey Beryozkin >> >> >> >> >> >> Application Integration Division of Talend >> >> >> http://sberyozkin.blogspot.com >> >> > >> >> >> >> >> >> >> >> -- >> >> Sergey Beryozkin >> >> >> >> Application Integration Division of Talend >> >> http://sberyozkin.blogspot.com >> > >> >> >> >> -- >> Sergey Beryozkin >> >> Application Integration Division of Talend >> http://sberyozkin.blogspot.com > -- Sergey Beryozkin Application Integration Division of Talend http://sberyozkin.blogspot.com