public static void main(String[] args) throws Exception
{
try {
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("tutorial:service=serviceOne");
//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 interface: " + attr1);
//Create object name for ServiceThree
ObjectName service3 = new ObjectName("tutorial:service=serviceThree");
//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);
} catch (Exception e)
{
e.printStackTrace();
}