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