Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java
38821 views
1
/*
2
* Copyright (c) 2005, 2012, 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
/* @test
25
* @bug 6261402 6824141
26
* @summary If rmid has an inherited channel that is not a server
27
* socket (such as it if was started using rsh/rcmd), then it should
28
* function normally.
29
* @author Peter Jones
30
*
31
* @library ../../testlibrary
32
* @build TestLibrary RMID ActivationLibrary
33
* @run main/othervm/timeout=240 InheritedChannelNotServerSocket
34
*/
35
36
import java.io.IOException;
37
import java.net.Socket;
38
import java.net.ProtocolFamily;
39
import java.nio.channels.Channel;
40
import java.nio.channels.DatagramChannel;
41
import java.nio.channels.Pipe;
42
import java.nio.channels.ServerSocketChannel;
43
import java.nio.channels.SocketChannel;
44
import java.nio.channels.spi.AbstractSelector;
45
import java.nio.channels.spi.SelectorProvider;
46
import java.rmi.NotBoundException;
47
import java.rmi.Remote;
48
import java.rmi.RemoteException;
49
import java.rmi.activation.ActivationGroup;
50
import java.rmi.activation.ActivationSystem;
51
import java.rmi.registry.LocateRegistry;
52
import java.rmi.registry.Registry;
53
import java.rmi.server.UnicastRemoteObject;
54
55
public class InheritedChannelNotServerSocket {
56
private static final Object lock = new Object();
57
private static boolean notified = false;
58
59
private InheritedChannelNotServerSocket() { }
60
61
public interface Callback extends Remote {
62
void notifyTest() throws RemoteException;
63
}
64
65
public static class CallbackImpl implements Callback {
66
CallbackImpl() { }
67
public void notifyTest() {
68
synchronized (lock) {
69
notified = true;
70
System.err.println("notification received.");
71
lock.notifyAll();
72
}
73
}
74
}
75
76
public static void main(String[] args) throws Exception {
77
System.err.println("\nRegression test for bug 6261402\n");
78
System.setProperty("java.rmi.activation.port",
79
Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
80
RMID rmid = null;
81
Callback obj = null;
82
try {
83
/*
84
* Export callback object and bind in registry.
85
*/
86
System.err.println("export callback object and bind in registry");
87
obj = new CallbackImpl();
88
Callback proxy =
89
(Callback) UnicastRemoteObject.exportObject(obj, 0);
90
Registry registry =
91
LocateRegistry.createRegistry(
92
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
93
registry.bind("Callback", proxy);
94
95
/*
96
* Start rmid.
97
*/
98
System.err.println("start rmid with inherited channel");
99
RMID.removeLog();
100
rmid = RMID.createRMID(System.out, System.err, true, true,
101
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
102
rmid.addOptions(new String[]{
103
"-Djava.nio.channels.spi.SelectorProvider=" +
104
"InheritedChannelNotServerSocket$SP"});
105
rmid.start();
106
107
/*
108
* Get activation system and wait to be notified via callback
109
* from rmid's selector provider.
110
*/
111
System.err.println("get activation system");
112
ActivationSystem system = ActivationGroup.getSystem();
113
System.err.println("ActivationSystem = " + system);
114
synchronized (lock) {
115
while (!notified) {
116
lock.wait();
117
}
118
}
119
System.err.println("TEST PASSED");
120
} finally {
121
if (obj != null) {
122
UnicastRemoteObject.unexportObject(obj, true);
123
}
124
ActivationLibrary.rmidCleanup(rmid);
125
}
126
}
127
128
public static class SP extends SelectorProvider {
129
private final SelectorProvider provider;
130
private volatile SocketChannel channel = null;
131
132
public SP() {
133
provider = sun.nio.ch.DefaultSelectorProvider.create();
134
}
135
136
public DatagramChannel openDatagramChannel() throws IOException {
137
return provider.openDatagramChannel();
138
}
139
140
public DatagramChannel openDatagramChannel(ProtocolFamily family)
141
throws IOException
142
{
143
return provider.openDatagramChannel(family);
144
}
145
146
public Pipe openPipe() throws IOException {
147
return provider.openPipe();
148
}
149
150
public AbstractSelector openSelector() throws IOException {
151
return provider.openSelector();
152
}
153
154
public ServerSocketChannel openServerSocketChannel()
155
throws IOException
156
{
157
return provider.openServerSocketChannel();
158
}
159
160
public SocketChannel openSocketChannel() throws IOException {
161
return provider.openSocketChannel();
162
}
163
164
public synchronized Channel inheritedChannel() throws IOException {
165
System.err.println("SP.inheritedChannel");
166
if (channel == null) {
167
channel = SocketChannel.open();
168
Socket socket = channel.socket();
169
System.err.println("socket = " + socket);
170
171
/*
172
* Notify test that inherited channel was created.
173
*/
174
try {
175
System.err.println("notify test...");
176
Registry registry =
177
LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
178
Callback obj = (Callback) registry.lookup("Callback");
179
obj.notifyTest();
180
} catch (NotBoundException nbe) {
181
throw (IOException)
182
new IOException("callback object not bound").
183
initCause(nbe);
184
}
185
}
186
return channel;
187
}
188
}
189
}
190
191