As a bit of background – I’m using JBoss 5.1, for web applications. The applications are vertically deployed so each feature ends up in a separate WAR file. It has a jar file for dao and business logic. This is fine so far however I need to deploy another app which doesn’t have much logic in itself – its basically a view like say dashboard. The dashboard needs to aggregate data from different data providers(usually they are other apps/features). Right now the dashboard knows way too much about other features. So everytime a new feature is added this dashboard gets redeployed as well with relevant code additions.
It would be great if there is a common interface for this dashboard that few other features implement and whenever a new feature(WAR) is deployed the dashboard can dynamically get data from the new provider as well. Is this possible? If not what is the closest I can get to without manipulating classloaders for the apps? It would be good to know if first of all this is possible inside jboss.
Please let me know if you need more info.
There are a couple of ways to do what you’re talking about, so I’ll propose two types of solutions and I can give you more info about whichever fits your needs best.
A relatively quick solution is to use a portal server like GateIn. Your WARs could be displayed on the same page, but they’d be in seperate places and not integrated. You’d have to turn your WAR’s into portlets and have an administrator add them to the portal’s UI, but the portal would be able to scan and detect all available portlets.
A more flexible solution would be to have one of your classes for each deployment implement a common MBean interface. Your dashboard could then use JMX, specifically
javax.management.MBeanServerConnection‘squeryMBeansmethod to obtain all MBeans (or a subset of MBeans belonging to a particular package, which you can specify as a query parameter). Then you can execute interface methods throughjavax.management.MBeanServerConnection‘sinvokemethod. To obtain the MBeanServerConnection with JBoss, callorg.jboss.mx.util.MBeanServerLocator.locateJBoss().Some additional detail as requested (Note, the following is JBoss-specific):
1) Turn your deployments into MBean’s
For each of your JAR files, add a
jboss-service.xmland*-xmbean.xmlfile to theMETA-INFdirectory (where*is a name of your choosing). Follow this example for those files.Implement the MBean at whatever path you specified in the
jboss-service.xmlmbeanelement’scodeattribute (org.jboss.chap2.xmbean.JNDIMapin the example). Specify a consistent namespace and parameter for thejboss-service.xmlmbeanelement’snameattribute (chap2.xmbean:service=in the example). The operations and attributes you specify in the*-xmbean.xmlfile should map exacly to your interface.2) Create the dashboard and in one of it’s classes poll the services (this code hasn’t been tested, but should provide a good outline)