KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > handler > mbean > service > ClientTest


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.remoting.handler.mbean.service;
8
9 import org.jboss.remoting.Client;
10 import org.jboss.remoting.InvokerLocator;
11
12 /**
13  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
14  */

15 public class ClientTest
16 {
17    // Default locator values
18
private static String JavaDoc transport = "socket";
19    private static String JavaDoc host = "localhost";
20    private static int port = 5400;
21
22    public void makeInvocation(String JavaDoc locatorURI) throws Throwable JavaDoc
23    {
24       InvokerLocator locator = new InvokerLocator(locatorURI);
25       System.out.println("Calling remoting server with locator uri of: " + locatorURI);
26
27       Client remotingClient = new Client(locator);
28       Object JavaDoc response = remotingClient.invoke("Do something");
29
30       System.out.println("Invocation response: " + response);
31    }
32
33    /**
34     * Can pass transport and port to be used as parameters.
35     * Valid transports are 'rmi' and 'socket'.
36     *
37     * @param args
38     */

39    public static void main(String JavaDoc[] args)
40    {
41       if(args != null && args.length == 2)
42       {
43          transport = args[0];
44          port = Integer.parseInt(args[1]);
45       }
46       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
47       ClientTest clientTest = new ClientTest();
48       try
49       {
50          clientTest.makeInvocation(locatorURI);
51       }
52       catch(Throwable JavaDoc e)
53       {
54          e.printStackTrace();
55       }
56    }
57
58 }
59
Popular Tags