Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/rmi/PortableRemoteObject/8146975/HelloClient.java
38853 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
25
import java.util.ArrayList;
26
27
import javax.naming.InitialContext;
28
import javax.naming.Context;
29
import javax.naming.NameNotFoundException;
30
31
import javax.rmi.PortableRemoteObject;
32
33
34
35
public class HelloClient implements Runnable {
36
static final int MAX_RETRY = 10;
37
static final int ONE_SECOND = 1000;
38
private static boolean responseReceived;
39
40
public static void main(String args[]) throws Exception {
41
executeRmiClientCall();
42
}
43
44
@Override
45
public void run() {
46
try {
47
executeRmiClientCall();
48
} catch (Exception e) {
49
e.printStackTrace();
50
throw new RuntimeException(e);
51
}
52
}
53
54
55
public static boolean isResponseReceived () {
56
return responseReceived;
57
}
58
59
public static void executeRmiClientCall() throws Exception {
60
Context ic;
61
Object objref;
62
HelloInterface helloSvc;
63
String response;
64
Object testResponse;
65
int retryCount = 0;
66
67
ArrayList<Test> listParam = new ArrayList<Test>();
68
listParam.add(null);
69
System.out.println("HelloClient.main: enter ...");
70
while (retryCount < MAX_RETRY) {
71
try {
72
ic = new InitialContext();
73
System.out.println("HelloClient.main: HelloService lookup ...");
74
// STEP 1: Get the Object reference from the Name Service
75
// using JNDI call.
76
objref = ic.lookup("HelloService");
77
System.out.println("HelloClient: Obtained a ref. to Hello server.");
78
79
// STEP 2: Narrow the object reference to the concrete type and
80
// invoke the method.
81
helloSvc = (HelloInterface) PortableRemoteObject.narrow(objref,
82
HelloInterface.class);
83
84
Test3 test3 = new Test3(listParam);
85
Test3 test3Response = helloSvc.sayHelloWithTest3(test3);
86
System.out.println("Server says: Test3 response == " + test3Response);
87
88
Test3 test3WithNullList = new Test3(null);
89
test3Response = helloSvc.sayHelloWithTest3(test3WithNullList);
90
System.out.println("Server says: Test3 response == "
91
+ test3Response);
92
93
Test4 test4 = new Test4(listParam);
94
Test3 test4Response = helloSvc.sayHelloWithTest3(test4);
95
System.out.println("Server says: Test3 response == " + test4Response);
96
97
responseReceived = true;
98
break;
99
} catch (NameNotFoundException nnfEx) {
100
System.err.println("NameNotFoundException Caught .... try again");
101
retryCount++;
102
try {
103
Thread.sleep(ONE_SECOND);
104
} catch (InterruptedException e) {
105
e.printStackTrace();
106
}
107
continue;
108
} catch (Exception e) {
109
System.err.println("Exception " + e + "Caught");
110
e.printStackTrace();
111
throw new RuntimeException(e);
112
}
113
}
114
System.err.println("HelloClient terminating ");
115
try {
116
Thread.sleep(ONE_SECOND);
117
} catch (InterruptedException e) {
118
e.printStackTrace();
119
}
120
}
121
}
122
123