CompositeData attribute displayed weirdly in JConsole JDK5
I'm not sure how jconsole is supposed to display a CompositeData array but have a look at the screenshot.
http://imajr.com/Original.aspx?Id=compositedata_67110
I am doing something wrong with my code ?
package experiment.jmx.server;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.ReflectionException;
import javax.management.openmbean.*;
publicclass BabyMBeanimplements DynamicMBean
{
List<CompositeData> interfaces =new ArrayList<CompositeData>();
privatevoid loadNetworkInterfaces()throws SocketException, OpenDataException
{
Set<InetAddress> localAddrs =new HashSet<InetAddress>();
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while ( ifaces.hasMoreElements() )
{
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> addrs = iface.getInetAddresses();
while ( addrs.hasMoreElements() )
{
InetAddress ia = addrs.nextElement();
String s = ia.getCanonicalHostName();
CompositeData cd =new CompositeDataSupport(new CompositeType("netaddr","NetworkAddress",
new String[]{"interface","addy"},new String[]{"a","b"},new OpenType[]{
SimpleType.STRING, SimpleType.STRING} ),new String[]{"interface","addy"},
new Object[]{ iface.getDisplayName(), s} );
interfaces.add( cd );
System.out.println("\t" + s );
localAddrs.add( ia );
}
}
}
protected OpenMBeanConstructorInfo[] createMBeanConstructorInfo(){
returnnew OpenMBeanConstructorInfoSupport[]{
new OpenMBeanConstructorInfoSupport(
"BabyMBean",
"no-arg ctor desc",
new OpenMBeanParameterInfoSupport[0])
};
}
protected OpenMBeanOperationInfo[] createMBeanOperationInfo(){
returnnew OpenMBeanOperationInfoSupport[0];
}
protected OpenMBeanAttributeInfo[] createMBeanAttributeInfo()throws OpenDataException{
returnnew OpenMBeanAttributeInfo[]{
new OpenMBeanAttributeInfoSupport("interfaces","interfaces att descript.",
new ArrayType( 1,new CompositeType("netaddr","NetworkAddress",
new String[]{"interface","addy"},new String[]{"a","b"},new OpenType[]{
SimpleType.STRING, SimpleType.STRING} ) ), true, false,false)
};
}
public BabyMBean()throws SocketException, OpenDataException
{
loadNetworkInterfaces();
}
public Object getAttribute( String attribute )throws AttributeNotFoundException, MBeanException,
ReflectionException
{
if (attribute !=null && attribute.equals("interfaces" ))
return interfaces;
else
thrownew AttributeNotFoundException("No such property: " + attribute);
}
public AttributeList getAttributes( String[] attributes )
{
AttributeList retval =new AttributeList();
retval.add(new Attribute("interfaces", interfaces) );
return retval;
}
public MBeanInfo getMBeanInfo()
{
try
{
returnnew OpenMBeanInfoSupport
(
this.getClass().getName(),
"Baby MBean",
createMBeanAttributeInfo(),
createMBeanConstructorInfo(),
new OpenMBeanOperationInfo[0],
new MBeanNotificationInfo[0]
);
}
catch ( OpenDataException e )
{
e.printStackTrace();
returnnull;
}
//public OpenMBeanInfoSupport(String className,
//String description,
//OpenMBeanAttributeInfo[] openAttributes,
//OpenMBeanConstructorInfo[] openConstructors,
//OpenMBeanOperationInfo[] openOperations,
//MBeanNotificationInfo[] notifications) {
}
public Object invoke( String actionName, Object[] params, String[] signature )throws MBeanException,
ReflectionException
{
// TODO Auto-generated method stub
returnnull;
}
publicvoid setAttribute( Attribute attribute )throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException
{
// TODO Auto-generated method stub
}
public AttributeList setAttributes( AttributeList attributes )
{
// TODO Auto-generated method stub
returnnull;
}
}

