Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/rmi/PortableRemoteObject/8146975/HelloClient.java
38853 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324import java.util.ArrayList;2526import javax.naming.InitialContext;27import javax.naming.Context;28import javax.naming.NameNotFoundException;2930import javax.rmi.PortableRemoteObject;31323334public class HelloClient implements Runnable {35static final int MAX_RETRY = 10;36static final int ONE_SECOND = 1000;37private static boolean responseReceived;3839public static void main(String args[]) throws Exception {40executeRmiClientCall();41}4243@Override44public void run() {45try {46executeRmiClientCall();47} catch (Exception e) {48e.printStackTrace();49throw new RuntimeException(e);50}51}525354public static boolean isResponseReceived () {55return responseReceived;56}5758public static void executeRmiClientCall() throws Exception {59Context ic;60Object objref;61HelloInterface helloSvc;62String response;63Object testResponse;64int retryCount = 0;6566ArrayList<Test> listParam = new ArrayList<Test>();67listParam.add(null);68System.out.println("HelloClient.main: enter ...");69while (retryCount < MAX_RETRY) {70try {71ic = new InitialContext();72System.out.println("HelloClient.main: HelloService lookup ...");73// STEP 1: Get the Object reference from the Name Service74// using JNDI call.75objref = ic.lookup("HelloService");76System.out.println("HelloClient: Obtained a ref. to Hello server.");7778// STEP 2: Narrow the object reference to the concrete type and79// invoke the method.80helloSvc = (HelloInterface) PortableRemoteObject.narrow(objref,81HelloInterface.class);8283Test3 test3 = new Test3(listParam);84Test3 test3Response = helloSvc.sayHelloWithTest3(test3);85System.out.println("Server says: Test3 response == " + test3Response);8687Test3 test3WithNullList = new Test3(null);88test3Response = helloSvc.sayHelloWithTest3(test3WithNullList);89System.out.println("Server says: Test3 response == "90+ test3Response);9192Test4 test4 = new Test4(listParam);93Test3 test4Response = helloSvc.sayHelloWithTest3(test4);94System.out.println("Server says: Test3 response == " + test4Response);9596responseReceived = true;97break;98} catch (NameNotFoundException nnfEx) {99System.err.println("NameNotFoundException Caught .... try again");100retryCount++;101try {102Thread.sleep(ONE_SECOND);103} catch (InterruptedException e) {104e.printStackTrace();105}106continue;107} catch (Exception e) {108System.err.println("Exception " + e + "Caught");109e.printStackTrace();110throw new RuntimeException(e);111}112}113System.err.println("HelloClient terminating ");114try {115Thread.sleep(ONE_SECOND);116} catch (InterruptedException e) {117e.printStackTrace();118}119}120}121122123