Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

I have seen several postings asking about integration between Seam and JMX.

Here is a simple approach for registering a POJO as an MBean and a Component.

Objectives

  • Use Seam to register an MBean so that it can be configured via JMX Console
  • Inject the MBean like any other component

Example

Here is the configuration:

	<jmx:managed-bean name="echoService"
		objectName="net.taylor.jmx:service=EchoService"
		type="net.taylor.jmx.EchoServiceMBean"
		implementation="net.taylor.jmx.EchoService"
	/>

Here is injections:

	@In
	private EchoService echoService;

Here is the component code:

@Scope(ScopeType.APPLICATION)
@AutoCreate
@Startup
@BypassInterceptors
public class ManagedBean {

	private String objectName;

	private Class<?> type;

	private Class<?> implementation;

	private String agentId;

	private ObjectName _objectName;

	private MBeanServer server;

	private Object mbean;

	// setters/getters

	@Create
	public void create() throws Exception {
		List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId);
		server = servers.get(0);
		
		_objectName = new ObjectName(objectName);
		mbean = MBeanProxy.create(implementation, type, _objectName, server);
	}

	@Destroy
	public void destroy() throws Exception {
		server.unregisterMBean(_objectName);
	}

	@Unwrap
	public Object getMBean() {
		return mbean;
	}
}

Here is the full code: ManagedBean.java

4 comments:
 
03. Jun 2009, 14:26 America/New_York | Link

hi, - in what file does the configuration goes in? (jmx:managed-bean...) - is there a special setup for JMX for Jboss 4 needed? I can do what i want i never get a MBeanServer. thanks joe

 
23. Jul 2009, 19:55 America/New_York | Link
Arbi Sookazian

He's referring to components.xml descriptor file.

See this for more info on JMX/MBean example for Hibernate: https://www.hibernate.org/216.html

 
23. Jul 2009, 20:24 America/New_York | Link
Arbi Sookazian

Well apparently it's not components.xml (unless there is some typo, etc.)

I tried this impelmentation and got the following on deployment:

Caused by: org.dom4j.DocumentException: Error on line 64 of document  : The prefix "jmx" for element "jmx:managed-bean" is not bound. Nested exception: The prefix "jmx" for element "jmx:managed-bean" is not bound.

I checked the 2.1.2 API doc and there is only one class in the org.jboss.seam.jmx package (JBossClusterMonitor).

So what is the deal here???

 
04. Aug 2009, 02:03 America/New_York | Link

This component basically registers and unregisters a new instance of a class as an MBean. Which is not as good as registering and unregistering an existing Seam component.

I came up with this: JBSEAM-4329

There are lots of things lacking in Seam for complete JMX integration:

1. Simple ways to access JMX: Way to configure the MBeanServer used by Seam for registration, return the MBeanServer Seam uses, etc.

2. Converter for String to ObjectName.

3. Namespace for

<jmx:>, so you can do 
<jmx:mbean-server agent-id="platform" create="false"/>
<jmx:mbean name=":type=MBean" component="#{component}" />

4. Annotations for automatically creating MBeans from Seam components, something like support for JMX 2.0 annotations like @MBean etc.

5. Support for intercepting every MBean operation and attribute fetch and doing proper Seam injection.