geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Srinath Perera" <>
Subject GBeans? What I learn[Add to WIKI]
Date Tue, 06 Jul 2004 12:43:57 GMT
Hi all;

As I promised here is what I leran about Gbeans ..
I do not know much yet I able to get a simple one runing ..

pls let me know are there any way to do them better ..
if they look good I will add them to wiki.



* Gbeans are way of providing managements services to Geronimo
* It is implemented on top of the JMX right now but supposes to be
independent of JMX. User should be able to use them without knowledge of
the JMX. And it can be make independent of GBeans .
* The GBean can be converted into the MBean using the GBeanMBean and use
the JMX to give the services

Creating a GBean like follows
a) write new GBean
b) start/stop .. the GBean

Let us Write a GBean
1)They should implements the GBeanLifecycle interface
(**search for all the implementetors of the GBeanLifecycle is a good way
to **find example** of the GBeans)
2) they can have attributes with getters and setters
	a) there are attributes that are final and I think they are standard ..
(What is the list of them) e.g. name, Kernel (they can use to get hold of
the system info, have a look at the sample GBeans.)
	b) there are ordinary attributes .. have getters and setters
3) GBeans can have methods ..
3) each GBean should have GBEAN_INFO attribute (see exapmles)

static {
		GBeanInfoFactory infoFactory = new GBeanInfoFactory("AxisGbean",
		infoFactory.addAttribute("Name", String.class, true);
		infoFactory.addAttribute("kernel", Kernel.class, false);
		infoFactory.addOperation("echo", new Class[]{String.class});

		infoFactory.setConstructor(new String[] {"kernel","Name"});
		GBEAN_INFO = infoFactory.getBeanInfo();

4) following two are call back methods
	public void doStart() throws WaitingException, Exception {
       System.out.println("Axis GBean has started");
    public void doStop() throws WaitingException, Exception {
		System.out.println("Axis GBean has stoped");

Run A GBean
Having created a GBean like this to start/stop/set values/invoke operaions
 and GBean service use code like follows

name = new ObjectName("test:name=AxisGBean");
kernel = new Kernel("test.kernel", "test");
ClassLoader cl = getClass().getClassLoader();
ClassLoader myCl = new URLClassLoader(new URL[0], cl);
GBeanMBean gbean = new GBeanMBean(AxisGbean.getGBeanInfo(), myCl);
gbean.setAttribute("Name", "Test");

kernel.loadGBean(name, gbean);
System.out.println(kernel.getMBeanServer().getAttribute(name, "state"));
System.out.println(kernel.getMBeanServer().invoke(name, "echo", new
Object[]{"Hello"}, new String[]{String.class.getName()}));


View raw message