Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getMbeanServer in WebSphere Application Server

111 views
Skip to first unread message

zsidd1

unread,
Jul 11, 2005, 6:09:20 PM7/11/05
to
Hi:

Does anyone has an example code that shows how the getMBeanServer
method is called for WebSphere Application Server JMX programs?

Thanks,
Zafar

cyrille...@gmail.com

unread,
Jul 13, 2005, 7:33:17 PM7/13/05
to
Hello Zafar,

Do you know these interesting articles :
- "IBM WebSphere Developer Technical Journal: System Administration
for WebSphere Application Server V5 -- Part 4"
-> "How to Extend the WebSphere Management System (and Create Your
Own MBeans)"
->
http://www-128.ibm.com/developerworks/websphere/techjournal/0304_williamson/williamson.html
- "IBM WebSphere Developer Technical Journal: System Administration
for WebSphere Application Server V5"
-> "Part 2 -- Writing Your Own Administration Programs"
->
http://www-128.ibm.com/developerworks/websphere/techjournal/0302_cundiff/cundiff.html

SERVER SIDE CODE
--------------------------------

The basic server side syntax is :
MBeanServer mbs =
com.ibm.websphere.management.AdminServiceFactory.getMBeanFactory().getMBeanServer();

Then you have a standard javax.management.MBeanServer. I use this
MBeanServer in a ServletContextListener of my webApplication to
register my custom MBeans.

CLIENT SIDE CODE
------------------------------

Then I manage my application throught MC4J JMX Console (
http://mc4j.sourceforge.net ).

A funny thing to do is to invoke rour MBeans throught WsAdmin
AdminControl object (you have queryNames and invoke methods)

I can also use client java code like this :

Properties props = new Properties();
props.put(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
props.put(AdminClient.CONNECTOR_HOST, "localhost");
props.put(AdminClient.CONNECTOR_PORT, "8880");

com.ibm.websphere.management.AdminClient adminClient =
com.ibm.websphere.management.AdminClientFactory.createAdminClient(props);

adminClient.queryNames(...)

Unfortunatelly, AdminClient does not implement MBeanServerConnection
(at least in Websphere 5.1) ; it is a prorietary class

Hope this helps,

Cyrille

zsidd1

unread,
Jul 14, 2005, 4:32:34 PM7/14/05
to
Hi Cyrille:

Thanks for the information you provided. I was wondering if the
AdminClient can be typecast to MBeanServer?

Two of the methods in my class are

public boolean connect (Properties props) and
public MBeanServer getServer ()

in the first method I am creating an AdminClient as follows:
ac = AdminClientFactory.createAdminClient(props);

and in the second method I am returning the adminClient as
return (MBeanServer) ac;

The program compiles fine but on execution it is complaining about
Exception in thread "P=872651:O=0:CT" java.lang.ClassCastException:
com.ibm.ws.management.AdminClientImpl

I was wondering if this typecast is ok? (MBeanServer)ac;

Thanks
Zafar

Cyrille Le Clerc

unread,
Jul 18, 2005, 9:39:40 AM7/18/05
to
Hello Zafar,

I hesitated to talked about this frustration in my first reply :

- According to the JavaDoc of javax.management.MBeanServerConnection,
AdminClient should be an instance of MBeanServerConnection (not of
MBeanServer that is server side). Extract of the javadoc
"This interface represents a way to talk to an MBean server,
whether local or remote.
The MBeanServer interface, representing a local MBean server,
extends this interface."

- I find it strange but Websphere V6 javadoc of AdminClient refers to
MBeanServer instead of MBeanServerConnection :

http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/management/AdminClient.html
"Most of APIs here are mapped from those defined in JMX MBeanServer
interface, but not all MBeanServer APIs are contained in the
AdminClientImpl."

- Websphere 5.x' version of JMX is old and does NOT include the class
MBeanServerConnection
-> WAS 5.x relies on Tivoli's implementation of JMX (aka TMX4J ) :
"1.0 Final Release, July 2000" version of JMX (according to the
manifest of $WAS_HOME/lib/jmxc.jar).
-> TMX4J project is no longer available on alphaworks
(http://www.alphaworks.ibm.com/tech/TMX4J ), it seems
discontinued (see Websphere 6 & MX4J below)
-> You can not mix tmx4j with a newer version of JMX (jmxc.jar is
sealed and there are serialVersionUid incompatibilities with
newer Jmx Versions)

- Websphere 6.x is totally different.
-> It relies on MX4j ( http://mx4j.sf.net ). Take care, the names
of the jmx jars are the same as Websphere 5's jars but
implementation is different.
-> FYI : MX4J has no link with Tivoli TMX4J (according to
mx4j.sf.net and to the name of the committers)

- To fulfill your need, An idea would be to wrap AdminClient in a proxy
of MBeanServer (or MBeanServerConnection if available in
Websphere 6).
-> see java.lang.reflect.Proxy#newProxyInstance(...)
-> I join a sample of InvocationHandler below

Hope this helps,

Cyrille

----------------------------
Cyrille Le Clerc
clec...@pobox.com
cyrille...@fr.ibm.com
----------------------------

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ProxyInvocationHandler implements InvocationHandler {

private Object m_target;

public ProxyInvocationHandler(Object target) {
super();
m_target = target;
}

public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Method targetMethod = m_target.getClass().getMethod(method.getName(),
method.getParameterTypes());
Object result = targetMethod.invoke(m_target, args);
return result;
}
}

0 new messages