-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

  haven't got any response to the below pasted mail, so I assumed that JSR-77 
is not in place yet and tried with JBoss for testing. After reading the 
JSR-77 specs I put together a small program to try it out.

  I wonder if somebody could help me up to speed?

  There is lots of things I don't really understand. For example I wonder how 
to properly traverse the managed objects hierarchy. What I've implemented 
below is to start with the J2EE Domain and traverse all attributes of types 
ObjectName and ObjectName[]. That seems to work, still I am not sure, if that 
is the right way of doing it.

  Anyway, I got lots of Exceptions (see log) and wonder if these Exceptions 
are alright.  I don't see how I can check these conditions before hand, i.e. 
I don't see any methods in the APIs to check for that. 

  Furthermore I am wondering how to determine the name of a J2EE 
ManagedObject?! Some have the attribute "name", some don't. 

  My first understanding was, that there is a generic way of doing *most* 
things (like traversal etc.) with J2EE Managed Objects, but meanwhile I came 
to believe that all the typed of J2EE Managed Objects need to be actually  
implemented by the client. Is that true?

  I would really appreciate if somebody could have a look at the code and the 
log?! If you want to run it yourself, it should work against JBoss 3.2.2 out 
of the box with the only exception that the jboss-3.2.2/docs/examples/jmx/
ejb-management.jar needs to be deployed first.

  Btw. I am aware of the potential danger of cyclic references; just haven't 
cared for that in the test-code..

  This is preliminary to building an eclipse plug-in.

Cheers,
Mariano

On Wednesday 12 November 2003 19:45, Mariano Kamp wrote:
> Hi,
>
>   I am wondering what the current state of the JSR-77 implementation is?
>
> http://wiki.apache.org/geronimo/Architecture/
> Management#head-61be967c1fa052eacfa2a377e50e8b70a3e9b31c says: "NOTE: It
> appears from a later comment that the JSR-77 objects may all appear in
> geronimo.j2ee.management".
>
>   When looking at at the web-console built from yesterdays cvs I can "only"
> see g.boot, g.remoting, g.system, jetty and JMImplementation.
>
>   I found a javax.management.j2ee.ManagementHome and Management, but they
> were empty.
>
>   I am new to JMX/JSR-77. Maybe I am just looking for the wrong thing?
>
>   Is there already any JSR-77 aware client available? I've also seen that
> the development of an according eclipse plugin was mentioned in the
> archives and in the wiki. Still I haven't been able to figure out what the
> status is. Is somebody working on that?
>
>   Btw. In modules/console-web/src/webapp/index.jsp "/console/faq.jsp" is
> referenced, but should be "./faq.jsp" or "/geronimo-web-console/faq.jsp".
> Otherwise at least the default deployment wouldn't work (for me).
>
> Cheers,
> Mariano

- -- 
Get public key from
http://blackhole.pca.dfn.de:11371/pks/lookup?op=get&search=0xE4AC1483
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/tpIoSraqt+SsFIMRAnkPAJ4zmCHO3aJlVb5NAFsUi8+54A4xSgCfXd5o
a/nBzHbC597ah3gOufw4Pqk=
=OMPG
-----END PGP SIGNATURE-----
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.j2ee.Management;
import javax.management.j2ee.ManagementHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class Test2 {

	public static void main(String[] args)
		throws NamingException, CreateException, RemoteException, RemoveException {
		System.out.println("started");
		Properties p = new Properties();
		p.setProperty(
			Context.INITIAL_CONTEXT_FACTORY,
			"org.jnp.interfaces.NamingContextFactory");
		p.setProperty(Context.PROVIDER_URL, "localhost:1099");
		p.setProperty(
			Context.URL_PKG_PREFIXES,
			"org.jboss.naming:org.jnp.interfaces");

		Context ctx = new InitialContext(p);
		ManagementHome home =
			(ManagementHome) PortableRemoteObject.narrow(
				ctx.lookup("ejb/mgmt/MEJB"),
				ManagementHome.class);

		Management mejb = home.create();
		try {

			J2EEManagedObject j2eeDomain =
				J2EEDomainFactory.getJ2EEDomain(mejb);
			dump(j2eeDomain, "", mejb);
		} catch (J2EEManagedObjectCreateException e) {
			System.out.println(e.getRootCause().getMessage());
			e.getRootCause().printStackTrace(System.out);
		}
		mejb.remove();
		System.out.println("done");

	}

	private static void dump(
		J2EEManagedObject managedObject,
		String indentation,
		Management mejb)
		throws J2EEManagedObjectCreateException {
		System.out.println(indentation + "NAME=" + managedObject.getName());
		if (indentation.length() < 6) {

			J2EEManagedObject[] children = managedObject.getChildren(mejb);
			for (int i = 0; i < children.length; i++)
				dump(children[i], indentation + "  ", mejb);
		}
	}

}

class J2EEDomainFactory {

	public static J2EEManagedObject getJ2EEDomain(Management mejb)
		throws J2EEManagedObjectCreateException {
		J2EEManagedObject rv = null;

		try {
			String domain = mejb.getDefaultDomain();

			Set managedDomains =
				mejb.queryNames(
					new ObjectName(domain + ":j2eeType=J2EEDomain,*"),
					null);

			if (managedDomains.size() != 1)
				throw new RuntimeException("Assertion failed. Not exactly one J2EEDomain.");
			ObjectName managedDomainObjectName =
				(ObjectName) managedDomains.iterator().next();

			rv = new J2EEManagedObject(null, managedDomainObjectName, mejb);
		} catch (Exception e) {
			throw new J2EEManagedObjectCreateException(
				"Unable to retrieve J2EEDomain.",
				e);
		}

		return rv;
	}

}
class J2EEManagedObject {

	private J2EEManagedObject parent;
	private J2EEManagedObject[] children;
	private List childrenObjectNames;
	private String name;

	/** parent can be null */
	J2EEManagedObject(
		J2EEManagedObject parent,
		ObjectName objectName,
		Management mejb)
		throws J2EEManagedObjectCreateException {

		try {

			childrenObjectNames = extractChildrenObjectNames(objectName, mejb);
		} catch (Exception e) {
			System.err.println(e.getMessage());
			e.printStackTrace(System.out);
			childrenObjectNames = new ArrayList(0);
			//			throw new J2EEManagedObjectCreateException(
			//				"Unable to create J2EEManagedObject.",
			//				e);
			//
		}
		this.name = objectName.getCanonicalKeyPropertyListString();
	}

	public String getName() {
		return name;
	}

	private List extractChildrenObjectNames(
		ObjectName objectName,
		Management mejb)
		throws
			IntrospectionException,
			AttributeNotFoundException,
			InstanceNotFoundException,
			MBeanException,
			ReflectionException,
			RemoteException {

		List children = new ArrayList(20);
		MBeanAttributeInfo[] managedBeanAttributeInfos =
			mejb.getMBeanInfo(objectName).getAttributes();
		for (int i = 0; i < managedBeanAttributeInfos.length; i++) {
			MBeanAttributeInfo managedBeanAttributeInfo =
				managedBeanAttributeInfos[i];

			if (managedBeanAttributeInfo
				.getType()
				.indexOf(ObjectName.class.getName())
				!= -1) {

				Object attributeValue = null;
				try {

					attributeValue =
						mejb.getAttribute(
							objectName,
							managedBeanAttributeInfo.getName());
				} catch (Exception e) {
					System.out.println(e.getMessage());
					e.printStackTrace(System.out);
				}
				if (attributeValue == null) {
					continue;
				}

				if (attributeValue instanceof ObjectName)
					children.add(attributeValue);
				else // ObjectName []
					children.addAll(Arrays.asList((Object[]) attributeValue));
			}
		}
		return children;
	}

	public synchronized J2EEManagedObject[] getChildren(Management mejb)
		throws J2EEManagedObjectCreateException {
		if (children == null) {
			children = new J2EEManagedObject[childrenObjectNames.size()];
			for (int i = 0; i < children.length; i++) {
				ObjectName objectName = (ObjectName) childrenObjectNames.get(i);
				children[i] = new J2EEManagedObject(this, objectName, mejb);
			}
		}
		return children;
	}

}
class J2EEManagedObjectCreateException extends Exception {
	private Exception rootCause;

	/** rootCause may be null */
	J2EEManagedObjectCreateException(String message, Exception rootCause) {
		super(message);
		this.rootCause = rootCause;
	}

	public Exception getRootCause() {
		return rootCause;
	}
}

Attachment: jsr77.log.tgz
Description: application/tgz

Reply via email to