2
|
1 |
/*
|
|
2 |
* Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
* @bug 4295885
|
|
26 |
* @summary rmid should be startable from inetd
|
|
27 |
* @author Ann Wollrath
|
|
28 |
*
|
|
29 |
* @library ../../testlibrary
|
|
30 |
* @build RMID ActivationLibrary
|
|
31 |
* @build RmidViaInheritedChannel
|
|
32 |
* @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 RmidViaInheritedChannel
|
|
33 |
*/
|
|
34 |
|
|
35 |
import java.io.IOException;
|
|
36 |
import java.net.InetAddress;
|
|
37 |
import java.net.InetSocketAddress;
|
|
38 |
import java.net.ServerSocket;
|
|
39 |
import java.nio.channels.*;
|
|
40 |
import java.nio.channels.spi.*;
|
|
41 |
import java.rmi.Remote;
|
|
42 |
import java.rmi.NotBoundException;
|
|
43 |
import java.rmi.activation.ActivationGroup;
|
|
44 |
import java.rmi.activation.ActivationSystem;
|
|
45 |
import java.rmi.registry.LocateRegistry;
|
|
46 |
import java.rmi.registry.Registry;
|
|
47 |
import java.rmi.server.UnicastRemoteObject;
|
|
48 |
|
|
49 |
public class RmidViaInheritedChannel implements Callback {
|
|
50 |
|
|
51 |
private static final int PORT = 5398;
|
|
52 |
private static final Object lock = new Object();
|
|
53 |
private static boolean notified = false;
|
|
54 |
|
|
55 |
private RmidViaInheritedChannel() {}
|
|
56 |
|
|
57 |
public void notifyTest() {
|
|
58 |
synchronized (lock) {
|
|
59 |
notified = true;
|
|
60 |
System.err.println("notification received.");
|
|
61 |
lock.notifyAll();
|
|
62 |
}
|
|
63 |
}
|
|
64 |
|
|
65 |
public static void main(String[] args) throws Exception {
|
|
66 |
|
|
67 |
RMID rmid = null;
|
|
68 |
Callback obj = null;
|
|
69 |
|
|
70 |
try {
|
|
71 |
/*
|
|
72 |
* Export callback object and bind in registry.
|
|
73 |
*/
|
|
74 |
System.err.println("export callback object and bind in registry");
|
|
75 |
obj = new RmidViaInheritedChannel();
|
|
76 |
Callback proxy = (Callback)
|
|
77 |
UnicastRemoteObject.exportObject(obj, 0);
|
|
78 |
Registry registry =
|
|
79 |
LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
|
|
80 |
registry.bind("Callback", proxy);
|
|
81 |
|
|
82 |
/*
|
|
83 |
* Start rmid.
|
|
84 |
*/
|
|
85 |
System.err.println("start rmid with inherited channel");
|
|
86 |
RMID.removeLog();
|
|
87 |
rmid = RMID.createRMID(System.out, System.err, true, false, PORT);
|
|
88 |
rmid.addOptions(new String[]{
|
|
89 |
"-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});
|
|
90 |
rmid.start();
|
|
91 |
|
|
92 |
/*
|
|
93 |
* Get activation system and wait to be notified via callback
|
|
94 |
* from rmid's selector provider.
|
|
95 |
*/
|
|
96 |
System.err.println("get activation system");
|
|
97 |
ActivationSystem system = ActivationGroup.getSystem();
|
|
98 |
System.err.println("ActivationSystem = " + system);
|
|
99 |
synchronized (lock) {
|
|
100 |
while (!notified) {
|
|
101 |
lock.wait();
|
|
102 |
}
|
|
103 |
}
|
|
104 |
System.err.println("TEST PASSED");
|
|
105 |
|
|
106 |
} finally {
|
|
107 |
if (obj != null) {
|
|
108 |
UnicastRemoteObject.unexportObject(obj, true);
|
|
109 |
}
|
|
110 |
ActivationLibrary.rmidCleanup(rmid, PORT);
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
public static class RmidSelectorProvider extends SelectorProvider {
|
|
115 |
|
|
116 |
private final SelectorProvider provider;
|
|
117 |
private ServerSocketChannel channel = null;
|
|
118 |
|
|
119 |
public RmidSelectorProvider() {
|
|
120 |
provider = sun.nio.ch.DefaultSelectorProvider.create();
|
|
121 |
}
|
|
122 |
|
|
123 |
public DatagramChannel openDatagramChannel()
|
|
124 |
throws IOException
|
|
125 |
{
|
|
126 |
return provider.openDatagramChannel();
|
|
127 |
}
|
|
128 |
|
|
129 |
public Pipe openPipe()
|
|
130 |
throws IOException
|
|
131 |
{
|
|
132 |
return provider.openPipe();
|
|
133 |
}
|
|
134 |
|
|
135 |
public AbstractSelector openSelector()
|
|
136 |
throws IOException
|
|
137 |
{
|
|
138 |
return provider.openSelector();
|
|
139 |
}
|
|
140 |
|
|
141 |
public ServerSocketChannel openServerSocketChannel()
|
|
142 |
throws IOException
|
|
143 |
{
|
|
144 |
return provider.openServerSocketChannel();
|
|
145 |
}
|
|
146 |
|
|
147 |
public SocketChannel openSocketChannel()
|
|
148 |
throws IOException
|
|
149 |
{
|
|
150 |
return provider.openSocketChannel();
|
|
151 |
}
|
|
152 |
|
|
153 |
public synchronized Channel inheritedChannel() throws IOException {
|
|
154 |
System.err.println("RmidSelectorProvider.inheritedChannel");
|
|
155 |
if (channel == null) {
|
|
156 |
/*
|
|
157 |
* Create server socket channel and bind server socket.
|
|
158 |
*/
|
|
159 |
channel = ServerSocketChannel.open();
|
|
160 |
ServerSocket serverSocket = channel.socket();
|
|
161 |
serverSocket.bind(
|
|
162 |
new InetSocketAddress(InetAddress.getLocalHost(), PORT));
|
|
163 |
System.err.println("serverSocket = " + serverSocket);
|
|
164 |
|
|
165 |
/*
|
|
166 |
* Notify test that inherited channel was created.
|
|
167 |
*/
|
|
168 |
try {
|
|
169 |
System.err.println("notify test...");
|
|
170 |
Registry registry =
|
|
171 |
LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT);
|
|
172 |
Callback obj = (Callback) registry.lookup("Callback");
|
|
173 |
obj.notifyTest();
|
|
174 |
} catch (NotBoundException nbe) {
|
|
175 |
throw (IOException)
|
|
176 |
new IOException("callback object not bound").
|
|
177 |
initCause(nbe);
|
|
178 |
}
|
|
179 |
}
|
|
180 |
return channel;
|
|
181 |
}
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
interface Callback extends Remote {
|
|
186 |
void notifyTest() throws IOException;
|
|
187 |
}
|