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