KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > connection > ConnectionValidatorClient


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.test.remoting.connection;
8
9 import org.jboss.remoting.Client;
10 import org.jboss.remoting.ConnectionListener;
11 import org.jboss.remoting.InvokerLocator;
12
13 import junit.framework.TestCase;
14
15 /**
16  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
17  */

18 public class ConnectionValidatorClient extends TestCase implements ConnectionListener
19 {
20    // Default locator values
21
private static String JavaDoc transport = "socket";
22    private static String JavaDoc host = "localhost";
23    private static int port = 5400;
24    String JavaDoc locatorURI = transport + "://" + host + ":" + port;
25    private Throwable JavaDoc validatorResp = null;
26
27    private Client remotingClient = null;
28
29    public void testValidator() throws Throwable JavaDoc
30    {
31
32       remotingClient.addConnectionListener(this);
33
34       Object JavaDoc response = remotingClient.invoke("Do something");
35
36       System.out.println("Invocation response: " + response);
37
38       Thread.currentThread().sleep(30000);
39
40       System.out.println("validatorResp = " + validatorResp);
41       assertNotNull("Connection listener was not called as expected.", validatorResp);
42    }
43
44    public void setUp() throws Exception JavaDoc
45    {
46       InvokerLocator locator = new InvokerLocator(locatorURI);
47       System.out.println("Calling remoting server with locator uri of: " + locatorURI);
48
49       remotingClient = new Client(locator);
50    }
51
52    public void tearDown() throws Exception JavaDoc
53    {
54       if(remotingClient != null)
55       {
56          remotingClient.disconnect();
57       }
58    }
59
60    /**
61     * Can pass transport and port to be used as parameters.
62     * Valid transports are 'rmi' and 'socket'.
63     *
64     * @param args
65     */

66    public static void main(String JavaDoc[] args)
67    {
68       if(args != null && args.length == 3)
69       {
70          transport = args[0];
71          host = args[1];
72          port = Integer.parseInt(args[2]);
73       }
74
75       ConnectionValidatorClient client = new ConnectionValidatorClient();
76       try
77       {
78          client.setUp();
79          client.testValidator();
80          client.tearDown();
81       }
82       catch(Throwable JavaDoc e)
83       {
84          e.printStackTrace();
85       }
86    }
87
88    public void handlerConnectionException(Throwable JavaDoc throwable, Client client)
89    {
90       System.out.println("Got connection exception.");
91       validatorResp = throwable;
92    }
93 }
Popular Tags