Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/management/remote/mandatory/connection/ReconnectTest.java
41159 views
1
/*
2
* Copyright (c) 2003, 2020, 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
* @test
26
* @bug 4927217
27
* @summary test to reconnect
28
* @author Shanliang JIANG
29
* @library /test/lib
30
* @run clean ReconnectTest
31
* @run build ReconnectTest
32
* @run main ReconnectTest
33
*/
34
35
import jdk.test.lib.Utils;
36
37
import java.util.*;
38
import java.net.MalformedURLException;
39
40
import javax.management.*;
41
import javax.management.remote.*;
42
43
public class ReconnectTest {
44
private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
45
private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
46
47
private static HashMap env = new HashMap(2);
48
49
static {
50
String timeout = Long.toString(Utils.adjustTimeout(1000));
51
env.put("jmx.remote.x.server.connection.timeout", timeout);
52
env.put("jmx.remote.x.client.connection.check.period", timeout);
53
}
54
55
public static void main(String[] args) throws Exception {
56
System.out.println(">>> test to reconnect.");
57
58
59
boolean ok = true;
60
for (int i = 0; i < protocols.length; i++) {
61
try {
62
if (!test(protocols[i])) {
63
System.out.println(">>> Test failed for " + protocols[i]);
64
ok = false;
65
} else {
66
System.out.println(">>> Test successed for " + protocols[i]);
67
}
68
} catch (Exception e) {
69
System.out.println(">>> Test failed for " + protocols[i]);
70
e.printStackTrace(System.out);
71
ok = false;
72
}
73
}
74
75
if (ok) {
76
System.out.println(">>> Test passed");
77
} else {
78
System.out.println(">>> TEST FAILED");
79
System.exit(1);
80
}
81
}
82
83
private static boolean test(String proto)
84
throws Exception {
85
System.out.println("\n\n>>> Test for protocol " + proto);
86
87
JMXServiceURL u = null;
88
JMXConnectorServer server = null;
89
90
try {
91
u = new JMXServiceURL(proto, null, 0);
92
server = JMXConnectorServerFactory.newJMXConnectorServer(u, env, mbs);
93
} catch (MalformedURLException e) {
94
System.out.println("Skipping unsupported URL " + proto);
95
return true;
96
}
97
98
server.start();
99
u = server.getAddress();
100
101
JMXConnector conn = JMXConnectorFactory.newJMXConnector(u, env);
102
conn.connect();
103
System.out.print("The default domain is ");
104
System.out.println(conn.getMBeanServerConnection().getDefaultDomain());
105
106
for (int i=0; i<3; i++) {
107
System.out.println("************** Sleeping ...... "+i);
108
Thread.sleep(Utils.adjustTimeout(2000));
109
System.out.println("Sleep done.");
110
111
System.out.println("The default domain is "
112
+conn.getMBeanServerConnection().getDefaultDomain());
113
}
114
115
System.out.println("Close the client ...");
116
117
conn.close();
118
119
System.out.println("Close the server ...");
120
121
server.stop();
122
123
System.out.println("Bye bye.");
124
125
return true;
126
}
127
}
128
129