Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java
38821 views
/*1* Copyright (c) 2005, 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 6261402 682414125* @summary If rmid has an inherited channel that is not a server26* socket (such as it if was started using rsh/rcmd), then it should27* function normally.28* @author Peter Jones29*30* @library ../../testlibrary31* @build TestLibrary RMID ActivationLibrary32* @run main/othervm/timeout=240 InheritedChannelNotServerSocket33*/3435import java.io.IOException;36import java.net.Socket;37import java.net.ProtocolFamily;38import java.nio.channels.Channel;39import java.nio.channels.DatagramChannel;40import java.nio.channels.Pipe;41import java.nio.channels.ServerSocketChannel;42import java.nio.channels.SocketChannel;43import java.nio.channels.spi.AbstractSelector;44import java.nio.channels.spi.SelectorProvider;45import java.rmi.NotBoundException;46import java.rmi.Remote;47import java.rmi.RemoteException;48import java.rmi.activation.ActivationGroup;49import java.rmi.activation.ActivationSystem;50import java.rmi.registry.LocateRegistry;51import java.rmi.registry.Registry;52import java.rmi.server.UnicastRemoteObject;5354public class InheritedChannelNotServerSocket {55private static final Object lock = new Object();56private static boolean notified = false;5758private InheritedChannelNotServerSocket() { }5960public interface Callback extends Remote {61void notifyTest() throws RemoteException;62}6364public static class CallbackImpl implements Callback {65CallbackImpl() { }66public void notifyTest() {67synchronized (lock) {68notified = true;69System.err.println("notification received.");70lock.notifyAll();71}72}73}7475public static void main(String[] args) throws Exception {76System.err.println("\nRegression test for bug 6261402\n");77System.setProperty("java.rmi.activation.port",78Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));79RMID rmid = null;80Callback obj = null;81try {82/*83* Export callback object and bind in registry.84*/85System.err.println("export callback object and bind in registry");86obj = new CallbackImpl();87Callback proxy =88(Callback) UnicastRemoteObject.exportObject(obj, 0);89Registry registry =90LocateRegistry.createRegistry(91TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);92registry.bind("Callback", proxy);9394/*95* Start rmid.96*/97System.err.println("start rmid with inherited channel");98RMID.removeLog();99rmid = RMID.createRMID(System.out, System.err, true, true,100TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);101rmid.addOptions(new String[]{102"-Djava.nio.channels.spi.SelectorProvider=" +103"InheritedChannelNotServerSocket$SP"});104rmid.start();105106/*107* Get activation system and wait to be notified via callback108* from rmid's selector provider.109*/110System.err.println("get activation system");111ActivationSystem system = ActivationGroup.getSystem();112System.err.println("ActivationSystem = " + system);113synchronized (lock) {114while (!notified) {115lock.wait();116}117}118System.err.println("TEST PASSED");119} finally {120if (obj != null) {121UnicastRemoteObject.unexportObject(obj, true);122}123ActivationLibrary.rmidCleanup(rmid);124}125}126127public static class SP extends SelectorProvider {128private final SelectorProvider provider;129private volatile SocketChannel channel = null;130131public SP() {132provider = sun.nio.ch.DefaultSelectorProvider.create();133}134135public DatagramChannel openDatagramChannel() throws IOException {136return provider.openDatagramChannel();137}138139public DatagramChannel openDatagramChannel(ProtocolFamily family)140throws IOException141{142return provider.openDatagramChannel(family);143}144145public Pipe openPipe() throws IOException {146return provider.openPipe();147}148149public AbstractSelector openSelector() throws IOException {150return provider.openSelector();151}152153public ServerSocketChannel openServerSocketChannel()154throws IOException155{156return provider.openServerSocketChannel();157}158159public SocketChannel openSocketChannel() throws IOException {160return provider.openSocketChannel();161}162163public synchronized Channel inheritedChannel() throws IOException {164System.err.println("SP.inheritedChannel");165if (channel == null) {166channel = SocketChannel.open();167Socket socket = channel.socket();168System.err.println("socket = " + socket);169170/*171* Notify test that inherited channel was created.172*/173try {174System.err.println("notify test...");175Registry registry =176LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);177Callback obj = (Callback) registry.lookup("Callback");178obj.notifyTest();179} catch (NotBoundException nbe) {180throw (IOException)181new IOException("callback object not bound").182initCause(nbe);183}184}185return channel;186}187}188}189190191