Monday, November 30, 2009

Anatomy of a MDB

EJBRuntimeMBean is the base Interface for all EJB-related MBeans.

subinterfaces are:

- MessageDrivenEJBRuntimeMBean, EntityEJBRuntimeMBean and StatelessEJBRuntimeMBean, which all contain a EJBPoolRuntimeMBean:

http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e13945/weblogic/management/runtime/EJBPoolRuntimeMBean.html


with attributes:

AccessTotalCount, BeansInUseCurrentCount, DestroyedTotalCount, MissTotalCount, PooledBeansCurrentCount, TimeoutTotalCount, WaiterCurrentCount

- StatefulEJBRuntimeMBean contains instead a EJBCacheRuntimeMBean (Stateful are cached, not pooled, since they contain stateful info which should not be discarded or shared) and EJBLockingRuntimeMBean

All types of Bean contain a EJBTransactionRuntimeMBean.


How do I retrieve a MDB RuntimeMBean?

From a DomainRuntimeMBean, retrieve a ServerRuntimeMBean, then its ApplicationRuntimeMBean[], then its ComponentRuntimeMBean[], and test if its type is EJBComponentRuntime, in this case you can cast it to EJBComponentRuntimeMBean

Painful, no? Here is the code:


public List getEBJs(String serverName) {
List result = new ArrayList();
ServerRuntimeMBean serverRuntimeMBean = getServerRuntimeMBean(serverName);
if (serverRuntimeMBean != null) {
ApplicationRuntimeMBean[] apps = serverRuntimeMBean.getApplicationRuntimes();
for (ApplicationRuntimeMBean app : apps) {
ComponentRuntimeMBean[] components = app.getComponentRuntimes();
for (ComponentRuntimeMBean bean : components) {
if (bean.getType().equals("EJBComponentRuntime")) {
result.add((EJBComponentRuntimeMBean)bean);
}
}
}
}
return result;
}

No comments: