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