admin@glassfish.java.net

how get get config, runtime info through MBeans

From: Lloyd L Chambers <Lloyd.Chambers_at_Sun.COM>
Date: Mon, 17 Mar 2008 15:07:28 -0700

Anissa,

Regarding today's conversation on geting J2EEModules, their submodules
and config, etc--

This stuff below (JSR 77 MBeans) does not yet exists as MBeans in V3,
but Sreeni and I will fix that soon. All the sample code below is V2
compatible, and will be so for V3 as well.

final DomainRoot = <get the AMX DomainRoot>
final J2EEDomain j2eeDomain = domainRoot.getJ2EEDomain();

final Map<String,J2EEServer> servers = j2eeDomain.getJ2EEServerMap();

final Set<J2EEResource> deployedResources =
j2eeServer.getResourcesSet();
final Set<J2EEDeployedObjects> deployedObjects =
j2eeServer.getDeployedObjectsSet();
final JVM jvm = j2eeServer.getJVM();

for( final J2EEDeployedObject dep : deployedObjects ) {
    final String dd = dep.getdeploymentDescriptor();

    final Map<String,Map<String,J2EEManagedObject>> allItems =
dep.getMultiContaineeMap();
    for( final String j2eeType : items.keySet() ) {
        final Map<String,J2EEManagedObject> itemsOfType =
items.get( j2eeType );
        // all items of type are in the Map
    }

    // specific code can be used eg:
    if ( dep.getJ2EEType().equals( WebModule.J2EE_TYPE ) ) {
        final Map<String,Servlet> servlets = ((WebModule)dep).getServletMap();
        // you now have all Servlets
    }
}

To get configuration MBean for a deployed item (anything implementing
ConfigProvider):

final J2EEManagedObject managed = <...>
final AMXConfig config = managed.getConfigPeer();
// do check for null--not all managed objects have configuration

So for example a WebModule:

WebModule wm = ...;
final WebModuleConfig wmc = (WebModuleConfig)wm.getConfigPeer();

Lloyd

---
Lloyd L Chambers
lloyd.chambers_at_sun.com
Sun Microsystems, Inc