Solved

How to create a CompositeType and CompositeData for Mbean operation?

Posted on 2014-04-02
2
781 Views
Last Modified: 2014-05-06
I googled but can't find any good example for creating the CompositeData object to pass it as a parameter to the MBean operation.

Can you help?

Say, I have a Person class

Person class {String name;int age; boolean married;}

interface PersonDao {
public int addPerson(Person p);
}

PersonDaoImpl class implements PersonDao {
public int addPerson(Person p);
}


MBean
public int addPerson(Person person) {
String[] sig = { String.class.getName(),
Integer.class.getName(), Boolean.class.getName(),
};
Object[] arg = { person.getName(),new Integer(person.getAge()),
Boolean.valueOf(Person.IsMarried};

int rowNo = (int) server.invoke(name, "addPerson", arg, sig);

}

Here I cannot pass person as object.
So I have to pass it as primitive data type.


How can I create a CompositeType as Person class and CompositeData?

  private static String[] itemNames = {"name", "age", "married"};
private static String[] itemDescriptions = {"Full Name", "Age", "Married or not"};
  private static OpenType[] itemTypes = {SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN};
    private static CompositeType personType = null;

 personType = new CompositeType("person",
                                    "a Person",
                                itemNames,
                                   itemDescriptions,
                                  itemTypes);


How do I use the CompositeDat in my invoke method?

MBean
public int addPerson(Person person) {
String[] sig = { String.class.getName(),
Integer.class.getName(), Boolean.class.getName(),
};
Object[] arg = { person.getName(),new Integer(person.getAge()),
Boolean.valueOf(Person.IsMarried};

int rowNo = (int) server.invoke(name, "addPerson", arg, sig);

}
0
Comment
Question by:dkim18
2 Comments
 
LVL 9

Accepted Solution

by:
sanjooz earned 500 total points
ID: 39989614
Here is an example. Scroll down to Example 2-11

http://docs.oracle.com/cd/E19159-01/819-7758/gcitp/index.html
0
 

Author Comment

by:dkim18
ID: 39990229
Already saw that.

That doesnot show much other than invoke method returning a result set and casting using compositedata.

I am looking for an example or something explaining 1) how CustomInfo was inserted into compositetype object back in the mbean method ans 2) how to pass CustomInfo object as compositedata type to mbean method.

I looked and looked but can't find any example.

Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL  on Tomcat 8 47
web application structure 18 77
how to install java on RHEL image on EC2 4 30
Is there a simpler dropbox system? 10 24
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question