• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to return non openType in MXBean  RSS feed

 
Peter van Nes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to implement an MXBean which returns a List of Beans.

MXBean

MBean



When i try to get the attribute



It fails with a ClassCastException.

<Sep 26, 2014 11:18:32 PM CEST> <Error> <com.reddipped.sysstats.model.SystemInfoCollector> <BEA-000000> <null
java.lang.ClassCastException: [Ljavax.management.openmbean.CompositeData; cannot be cast to javax.management.openmbean.CompositeData
at com.reddipped.sysstats.model.SystemInfoCollector.run(SystemInfoCollector.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
Truncated. see log file for complete stacktrace

Anyone able to help me out how to retrieve the mbean as an MXBean attribute ?

Cheers,
Peter
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "[L" indicates that you're getting back not a CompositeData, but CompositeData[], so that's what you should cast it to.
 
Peter van Nes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
It's quite hard to cast an array to a single object :-)

Cheers,
Peter
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it hard? An array is a single object.
You cannot cast an array to the type of its elements or vice versa.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!