1 import java.rmi.RemoteException;
   2 import java.net.InetAddress;
   3 import java.net.MalformedURLException;
   4 import java.rmi.NotBoundException;
   5 import java.util.HashMap;
   6 import java.util.Vector;
   7 import java.util.concurrent.ConcurrentHashMap;
   8 import java.util.concurrent.locks.ReentrantLock;
   9 
  10 import javax.naming.NamingException;
  11 import javax.naming.InitialContext;
  12 import javax.naming.Context;
  13 import javax.naming.NameNotFoundException;
  14 import javax.naming.NamingException;
  15 import javax.rmi.PortableRemoteObject;
  16 
  17 import org.omg.CORBA.Any;
  18 import org.omg.CORBA.ORB;
  19 
  20 public class HelloClient implements Runnable {
  21     static final int MAX_RETRY = 10;
  22     static final int ONE_SECOND = 1000;
  23     private static boolean responseReceived;
  24 
  25     public static void main(String args[]) throws Exception {
  26         executeRmiClientCall();
  27     }
  28 
  29     @Override
  30     public void run() {
  31         try {
  32             executeRmiClientCall();
  33         } catch (Exception e) {
  34             e.printStackTrace();
  35             throw new RuntimeException(e);
  36         }
  37     }
  38 
  39 
  40     public static boolean isResponseReceived () {
  41         return responseReceived;
  42     }
  43 
  44     public static void executeRmiClientCall() throws Exception {
  45         Context ic;
  46         Object objref;
  47         HelloInterface helloSvc;
  48         String response;
  49         int retryCount = 0;
  50 
  51         Test test = new Test();
  52         System.out.println("HelloClient.main: enter ...");
  53         while (retryCount < MAX_RETRY) {
  54             try {
  55                 ic = new InitialContext();
  56                 System.out.println("HelloClient.main: HelloService lookup ...");
  57                 // STEP 1: Get the Object reference from the Name Service
  58                 // using JNDI call.
  59                 objref = ic.lookup("HelloService");
  60                 System.out.println("HelloClient: Obtained a ref. to Hello server.");
  61 
  62                 // STEP 2: Narrow the object reference to the concrete type and
  63                 // invoke the method.
  64                 helloSvc = (HelloInterface) PortableRemoteObject.narrow(objref,
  65                     HelloInterface.class);
  66                 System.out.println("HelloClient: Invoking on remote server with ConcurrentHashMap parameter");
  67                 ConcurrentHashMap <String, String> testConcurrentHashMap = new ConcurrentHashMap<String, String>();
  68                 response = helloSvc.sayHelloWithHashMap(testConcurrentHashMap);
  69                 System.out.println("HelloClient: Server says:  " + response);
  70                 if (!response.contains("Hello with hashMapSize ==")) {
  71                     System.out.println("HelloClient: expected response not received");
  72                     throw new RuntimeException("Expected Response Hello with hashMapSize == 0 not received");
  73                 }
  74                 responseReceived = true;
  75                 break;
  76             } catch (NameNotFoundException nnfEx) {
  77                 System.err.println("NameNotFoundException Caught  .... try again");
  78                 retryCount++;
  79                 try {
  80                     Thread.sleep(ONE_SECOND);
  81                 } catch (InterruptedException e) {
  82                     e.printStackTrace();
  83                 }
  84                 continue;
  85             } catch (Exception e) {
  86                 System.err.println("Exception " + e + "Caught");
  87                 e.printStackTrace();
  88                 throw new RuntimeException(e);
  89             }
  90         }
  91         System.err.println("HelloClient terminating ");
  92         try {
  93             Thread.sleep(5000);
  94         } catch (InterruptedException e) {
  95             e.printStackTrace();
  96         }
  97     }
  98 }