InitialContext ctx = new InitialContext();
//Get hold of the MBean server invoker
RMIAdaptor server = (RMIAdaptor)ctx.lookup("jmx/invoker/RMIAdaptor");
//Set attribute on singleton ServiceOne via remote interface
ServiceOneRemote serviceOne = (ServiceOneRemote) ctx.lookup("ServiceOne/remote");
serviceOne.setAttribute(100);
//Create object name for ServiceOne
ObjectName service1 = new ObjectName("jboss.j2ee:jar=tutorial.jar,service=EJB3,name=ServiceOne,type=ManagementInterface");
//Get attribute of singleton ServiceOne via JMX
int attr1 = (Integer)server.getAttribute(service1, "Attribute");
System.out.println("attribute value for singleton obtained via JMX is what we set via remote i/f: " + attr1);
//Create object name for ServiceThree
ObjectName service3 = new ObjectName("jboss.j2ee:jar=tutorial.jar,service=EJB3,name=ServiceThree,type=ManagementInterface");
//Call serviceOneHello() and serviceTwoHello() on ServiceThree
Object[] noArgs = new Object[0];//No arguments
String[] noSig = new String[0];//No parameters in signature
String service1Hello = (String)server.invoke(service3, "serviceOneHello", noArgs, noSig);
System.out.println(service1Hello);
String service2Hello = (String)server.invoke(service3, "serviceTwoHello", noArgs, noSig);
System.out.println(service2Hello);