Date: 2004-07-06T19:11:32
Editor: 220.247.207.122 <>
Wiki: Apache Geronimo Wiki
Page: GBeans
URL: http://wiki.apache.org/geronimo/GBeans
GBeans add few tips to wiki
Change Log:
------------------------------------------------------------------------------
@@ -1,4 +1,79 @@
-A GBeanMBean is a J2EE Management Managed Object, and is standard base for
Geronimo services.
+= GBeans =
+A GBeanMBean is a J2EE Management Managed Object, and is standard base for
Geronimo services. GBean is a class or object that Geronimo the container can
manage the lifecycle of. So, for example, when you deploy parts into a
container you want to start them and stop them, and they have dependencies:
Such as 'Bean A' can only start up when 'Bean B' is ready to go because 'Bean
B' provides services that 'Bean A' needs. So, GBeans are Geronimo's way of
packaging up things are that need to be managed, and can express dependencies.
The GBeans architecture lies at the heart of Geronimo's power to enable
developers to move or work with their existing J2EE assets, whether Open Source
or commercial.
+
+GBeans are designed to let you take things you have, put a GBean wrapper
around them, and use that to bridge the JSR 77 lifecycle requirements which
GBeans support). You can take anything lying around and get it to work with
GBeans. In addition, the GBeans will let developers bring other existing Open
Source Java projects into the Geronimo orbit.
+
This wraps one or more target POJOs and exposes the attributes and operations
according to a supplied
GBeanInfo instance. The GBeanMBean also supports caching of attribute values
and invocation results
which can reduce the number of calls to a target.
+
+ * 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
+
+== how to find Sample GBeans ==
+
+**search for all the implementetors of the GBeanLifecycle is a good way to
**find example** of the GBeans
+and I found the jetty module and the GBeanTest class quite helpful
+
+
+== Creating a GBean like follows ==
+ a. write new GBean
+ a. start/stop .. the GBean
+
+
+== Let us Write a GBean ==
+ * They should implements the GBeanLifecycle interface
+ * They can have attributes with getters and setters, 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.) There are ordinary attributes .. have getters and setters
+
+ * GBeans can have methods ..
+
+ * each GBean should have GBEAN_INFO attribute (see exapmles)
+{{{
+static {
+GBeanInfoFactory infoFactory = new GBeanInfoFactory("AxisGbean",
+AxisGbean.class);
+//attributes
+infoFactory.addAttribute("Name", String.class, true);
+infoFactory.addAttribute("kernel", Kernel.class, false);
+//operations
+infoFactory.addOperation("echo", new Class[]{String.class});
+
+infoFactory.setConstructor(new String[] {"kernel","Name"});
+GBEAN_INFO = infoFactory.getBeanInfo();
+}
+}}}
+
+ * following two are call back methods there are more
+{{{
+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");
+kernel.boot();
+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);
+Kernel.startGBean(name);
+System.out.println(kernel.getMBeanServer().getAttribute(name, "state"));
+System.out.println(kernel.getMBeanServer().invoke(name, "echo", new
+Object[]{"Hello"}, new String[]{String.class.getName()}));
+
+kernel.stopGBean(name);
+kernel.unloadGBean(name)
+}}}
+
+there are more to come :)