Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java
38821 views
/*1* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 4295885 682414125* @summary rmid should be startable from inetd26* @author Ann Wollrath27*28* @library ../../testlibrary29* @build TestLibrary RMID ActivationLibrary30* @run main/othervm/timeout=240 RmidViaInheritedChannel31*/3233import java.io.IOException;34import java.net.InetAddress;35import java.net.InetSocketAddress;36import java.net.ServerSocket;37import java.net.ProtocolFamily;38import java.nio.channels.*;39import java.nio.channels.spi.*;40import java.rmi.Remote;41import java.rmi.NotBoundException;42import java.rmi.activation.ActivationGroup;43import java.rmi.activation.ActivationSystem;44import java.rmi.registry.LocateRegistry;45import java.rmi.registry.Registry;46import java.rmi.server.UnicastRemoteObject;4748public class RmidViaInheritedChannel implements Callback {49private static final Object lock = new Object();50private static boolean notified = false;5152private RmidViaInheritedChannel() {}5354public void notifyTest() {55synchronized (lock) {56notified = true;57System.err.println("notification received.");58lock.notifyAll();59}60}6162public static void main(String[] args) throws Exception {63System.setProperty("java.rmi.activation.port",64Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));65RMID rmid = null;66Callback obj = null;6768try {69/*70* Export callback object and bind in registry.71*/72System.err.println("export callback object and bind in registry");73obj = new RmidViaInheritedChannel();74Callback proxy = (Callback)75UnicastRemoteObject.exportObject(obj, 0);76Registry registry =77LocateRegistry.createRegistry(78TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);79registry.bind("Callback", proxy);8081/*82* Start rmid.83*/84System.err.println("start rmid with inherited channel");85RMID.removeLog();86rmid = RMID.createRMID(System.out, System.err, true, false,87TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);88rmid.addOptions(new String[]{89"-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});90if (System.getProperty("os.name").startsWith("Windows") &&91System.getProperty("os.version").startsWith("5."))92{93/* Windows XP/2003 or older94* Need to expand ephemeral range to include RMI test ports95*/96rmid.addOptions(new String[]{97"-Djdk.net.ephemeralPortRange.low=1024",98"-Djdk.net.ephemeralPortRange.high=64000"99});100}101rmid.start();102103/*104* Get activation system and wait to be notified via callback105* from rmid's selector provider.106*/107System.err.println("get activation system");108ActivationSystem system = ActivationGroup.getSystem();109System.err.println("ActivationSystem = " + system);110synchronized (lock) {111while (!notified) {112lock.wait();113}114}115System.err.println("TEST PASSED");116117} finally {118if (obj != null) {119UnicastRemoteObject.unexportObject(obj, true);120}121ActivationLibrary.rmidCleanup(rmid);122}123}124125public static class RmidSelectorProvider extends SelectorProvider {126127private final SelectorProvider provider;128private ServerSocketChannel channel = null;129130public RmidSelectorProvider() {131provider = sun.nio.ch.DefaultSelectorProvider.create();132}133134public DatagramChannel openDatagramChannel()135throws IOException136{137return provider.openDatagramChannel();138}139140public DatagramChannel openDatagramChannel(ProtocolFamily family)141throws IOException142{143return provider.openDatagramChannel(family);144}145146public Pipe openPipe()147throws IOException148{149return provider.openPipe();150}151152public AbstractSelector openSelector()153throws IOException154{155return provider.openSelector();156}157158public ServerSocketChannel openServerSocketChannel()159throws IOException160{161return provider.openServerSocketChannel();162}163164public SocketChannel openSocketChannel()165throws IOException166{167return provider.openSocketChannel();168}169170public synchronized Channel inheritedChannel() throws IOException {171System.err.println("RmidSelectorProvider.inheritedChannel");172if (channel == null) {173/*174* Create server socket channel and bind server socket.175*/176channel = ServerSocketChannel.open();177ServerSocket serverSocket = channel.socket();178serverSocket.bind(179new InetSocketAddress(InetAddress.getLocalHost(),180TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));181System.err.println("serverSocket = " + serverSocket);182183/*184* Notify test that inherited channel was created.185*/186try {187System.err.println("notify test...");188Registry registry =189LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);190Callback obj = (Callback) registry.lookup("Callback");191obj.notifyTest();192} catch (NotBoundException nbe) {193throw (IOException)194new IOException("callback object not bound").195initCause(nbe);196}197}198return channel;199}200}201}202203interface Callback extends Remote {204void notifyTest() throws IOException;205}206207208