KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > service > client > Client


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.service.client;
8
9 import org.jboss.tutorial.service.bean.ServiceOneRemote;
10 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
11
12 import javax.naming.InitialContext JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14
15
16 public class Client
17 {
18    public static void main(String JavaDoc[] args) throws Exception JavaDoc
19    {
20       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
21       //Get hold of the MBean server invoker
22
RMIAdaptor server = (RMIAdaptor)ctx.lookup("jmx/invoker/RMIAdaptor");
23
24       //Set attribute on singleton ServiceOne via remote interface
25
ServiceOneRemote serviceOne = (ServiceOneRemote) ctx.lookup(ServiceOneRemote.class.getName());
26       serviceOne.setAttribute(100);
27
28       //Create object name for ServiceOne
29
ObjectName JavaDoc service1 = new ObjectName JavaDoc("jboss.j2ee:service=EJB3,name=org.jboss.tutorial.service.bean.ServiceOne,type=service");
30       //Get attribute of singleton ServiceOne via JMX
31
int attr1 = (Integer JavaDoc)server.getAttribute(service1, "Attribute");
32       System.out.println("attribute value for singleton obtained via JMX is what we set via remote i/f: " + attr1);
33
34       //Create object name for ServiceThree
35
ObjectName JavaDoc service3 = new ObjectName JavaDoc("jboss.j2ee:service=EJB3,name=org.jboss.tutorial.service.bean.ServiceThree,type=service");
36       //Call serviceOneHello() and serviceTwoHello() on ServiceThree
37
Object JavaDoc[] noArgs = new Object JavaDoc[0];//No arguments
38
String JavaDoc[] noSig = new String JavaDoc[0];//No parameters in signature
39

40       String JavaDoc service1Hello = (String JavaDoc)server.invoke(service3, "serviceOneHello", noArgs, noSig);
41       System.out.println(service1Hello);
42       String JavaDoc service2Hello = (String JavaDoc)server.invoke(service3, "serviceTwoHello", noArgs, noSig);
43       System.out.println(service2Hello);
44    }
45 }
46
Popular Tags