34 * java.rmi/sun.rmi.transport.tcp
35 * @build TestLibrary RMID ActivationLibrary
36 * @run main/othervm/timeout=240 RmidViaInheritedChannel
37 * @key intermittent
38 */
39
40 import java.io.IOException;
41 import java.net.InetAddress;
42 import java.net.InetSocketAddress;
43 import java.net.ServerSocket;
44 import java.net.ProtocolFamily;
45 import java.nio.channels.*;
46 import java.nio.channels.spi.*;
47 import java.rmi.Remote;
48 import java.rmi.NotBoundException;
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 RmidViaInheritedChannel implements Callback {
56 private static final Object lock = new Object();
57 private static boolean notified = false;
58
59 private RmidViaInheritedChannel() {}
60
61 public void notifyTest() {
62 synchronized (lock) {
63 notified = true;
64 System.err.println("notification received.");
65 lock.notifyAll();
66 }
67 }
68
69 public static void main(String[] args) throws Exception {
70 System.setProperty("java.rmi.activation.port",
71 Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
72 RMID rmid = null;
73 Callback obj = null;
168 public ServerSocketChannel openServerSocketChannel()
169 throws IOException
170 {
171 return provider.openServerSocketChannel();
172 }
173
174 public SocketChannel openSocketChannel()
175 throws IOException
176 {
177 return provider.openSocketChannel();
178 }
179
180 public synchronized Channel inheritedChannel() throws IOException {
181 System.err.println("RmidSelectorProvider.inheritedChannel");
182 if (channel == null) {
183 /*
184 * Create server socket channel and bind server socket.
185 */
186 channel = ServerSocketChannel.open();
187 ServerSocket serverSocket = channel.socket();
188 serverSocket.bind(
189 new InetSocketAddress(InetAddress.getLocalHost(),
190 TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
191 System.err.println("serverSocket = " + serverSocket);
192
193 /*
194 * Notify test that inherited channel was created.
195 */
196 try {
197 System.err.println("notify test...");
198 Registry registry =
199 LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
200 Callback obj = (Callback) registry.lookup("Callback");
201 obj.notifyTest();
202 } catch (NotBoundException nbe) {
203 throw (IOException)
204 new IOException("callback object not bound").
205 initCause(nbe);
206 }
207 }
|
34 * java.rmi/sun.rmi.transport.tcp
35 * @build TestLibrary RMID ActivationLibrary
36 * @run main/othervm/timeout=240 RmidViaInheritedChannel
37 * @key intermittent
38 */
39
40 import java.io.IOException;
41 import java.net.InetAddress;
42 import java.net.InetSocketAddress;
43 import java.net.ServerSocket;
44 import java.net.ProtocolFamily;
45 import java.nio.channels.*;
46 import java.nio.channels.spi.*;
47 import java.rmi.Remote;
48 import java.rmi.NotBoundException;
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 import static java.net.StandardSocketOptions.SO_REUSEADDR;
55 import static java.net.StandardSocketOptions.SO_REUSEPORT;
56
57 public class RmidViaInheritedChannel implements Callback {
58 private static final Object lock = new Object();
59 private static boolean notified = false;
60
61 private RmidViaInheritedChannel() {}
62
63 public void notifyTest() {
64 synchronized (lock) {
65 notified = true;
66 System.err.println("notification received.");
67 lock.notifyAll();
68 }
69 }
70
71 public static void main(String[] args) throws Exception {
72 System.setProperty("java.rmi.activation.port",
73 Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
74 RMID rmid = null;
75 Callback obj = null;
170 public ServerSocketChannel openServerSocketChannel()
171 throws IOException
172 {
173 return provider.openServerSocketChannel();
174 }
175
176 public SocketChannel openSocketChannel()
177 throws IOException
178 {
179 return provider.openSocketChannel();
180 }
181
182 public synchronized Channel inheritedChannel() throws IOException {
183 System.err.println("RmidSelectorProvider.inheritedChannel");
184 if (channel == null) {
185 /*
186 * Create server socket channel and bind server socket.
187 */
188 channel = ServerSocketChannel.open();
189 ServerSocket serverSocket = channel.socket();
190
191 // Enable SO_REUSEADDR before binding
192 serverSocket.setOption(SO_REUSEADDR, true);
193
194 // Enable SO_REUSEPORT, if supported, before binding
195 if (serverSocket.supportedOptions().contains(SO_REUSEPORT)) {
196 serverSocket.setOption(SO_REUSEPORT, true);
197 }
198
199 serverSocket.bind(
200 new InetSocketAddress(InetAddress.getLocalHost(),
201 TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
202 System.err.println("serverSocket = " + serverSocket);
203
204 /*
205 * Notify test that inherited channel was created.
206 */
207 try {
208 System.err.println("notify test...");
209 Registry registry =
210 LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
211 Callback obj = (Callback) registry.lookup("Callback");
212 obj.notifyTest();
213 } catch (NotBoundException nbe) {
214 throw (IOException)
215 new IOException("callback object not bound").
216 initCause(nbe);
217 }
218 }
|