KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > samples > oneway > OnewayClient


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.samples.oneway;
8
9 import org.jboss.remoting.Client;
10 import org.jboss.remoting.InvokerLocator;
11
12 /**
13  * Simple test client to make oneway invocations on remoting server.
14  *
15  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
16  */

17 public class OnewayClient
18 {
19    // Default locator values
20
private static String JavaDoc transport = "socket";
21    private static String JavaDoc host = "localhost";
22    private static int port = 5400;
23
24    public void makeInvocation(String JavaDoc locatorURI) throws Throwable JavaDoc
25    {
26       InvokerLocator locator = new InvokerLocator(locatorURI);
27       System.out.println("Calling remoting server with locator uri of: " + locatorURI);
28
29       Client remotingClient = new Client(locator);
30
31       /**
32        * Make oneway invocation. The second parameter is for a map of payload
33        * metadata that you would want to send. Since this is a oneway invocation,
34        * the return is void.
35        *
36        * With this invokeOneway signature, it uses the current thread to execute
37        * the invocation on the server and will not return until the invocation request
38        * has been placed into a worker thread pool on the server. This ensures that
39        * the call at least made it to the server.
40        */

41       String JavaDoc payload1 = "Oneway call 1.";
42       System.out.println("Making oneway invocation with payload of '" + payload1 + "'");
43       remotingClient.invokeOneway(payload1, null);
44
45       /**
46        * This call is the same as the one above, except the last parameter will
47        * place the invocation request into a worker thread pool on the client and
48        * return immediately. The worker thread will then make the invocation
49        * on the remoting server.
50        */

51       String JavaDoc payload2 = "Oneway call 2.";
52       System.out.println("Making oneway invocation with payload of '" + payload2 + "'");
53       remotingClient.invokeOneway(payload2, null, true);
54    }
55
56    /**
57     * Can pass transport and port to be used as parameters.
58     * Valid transports are 'rmi' and 'socket'.
59     *
60     * @param args
61     */

62    public static void main(String JavaDoc[] args)
63    {
64       if(args != null && args.length == 2)
65       {
66          transport = args[0];
67          port = Integer.parseInt(args[1]);
68       }
69       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
70       OnewayClient client = new OnewayClient();
71       try
72       {
73          client.makeInvocation(locatorURI);
74       }
75       catch(Throwable JavaDoc e)
76       {
77          e.printStackTrace();
78       }
79    }
80
81
82 }
Popular Tags