KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > samples > simple > SimpleClient


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.samples.simple;
8
9 import org.jboss.remoting.Client;
10 import org.jboss.remoting.InvokerLocator;
11
12 /**
13  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
14  */

15 public class SimpleClient
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       // This could have been new Client(locator), but want to show that subsystem param is null
28
// Could have also been new Client(locator, "sample");
29
Client remotingClient = new Client(locator, null);
30       Object JavaDoc response = remotingClient.invoke("Do something", null);
31
32       System.out.println("Invocation response: " + response);
33    }
34
35    /**
36     * Can pass transport and port to be used as parameters.
37     * Valid transports are 'rmi' and 'socket'.
38     *
39     * @param args
40     */

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