0N/A/*
5266N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
1037N/A * @bug 6261402 6824141
0N/A * @summary If rmid has an inherited channel that is not a server
0N/A * socket (such as it if was started using rsh/rcmd), then it should
0N/A * function normally.
0N/A * @author Peter Jones
0N/A *
0N/A * @library ../../testlibrary
5551N/A * @build TestLibrary RMID ActivationLibrary
5266N/A * @run main/othervm/timeout=240 InheritedChannelNotServerSocket
0N/A */
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.net.Socket;
1037N/Aimport java.net.ProtocolFamily;
0N/Aimport java.nio.channels.Channel;
0N/Aimport java.nio.channels.DatagramChannel;
0N/Aimport java.nio.channels.Pipe;
0N/Aimport java.nio.channels.ServerSocketChannel;
0N/Aimport java.nio.channels.SocketChannel;
0N/Aimport java.nio.channels.spi.AbstractSelector;
0N/Aimport java.nio.channels.spi.SelectorProvider;
0N/Aimport java.rmi.NotBoundException;
0N/Aimport java.rmi.Remote;
0N/Aimport java.rmi.RemoteException;
0N/Aimport java.rmi.activation.ActivationGroup;
0N/Aimport java.rmi.activation.ActivationSystem;
0N/Aimport java.rmi.registry.LocateRegistry;
0N/Aimport java.rmi.registry.Registry;
0N/Aimport java.rmi.server.UnicastRemoteObject;
0N/A
0N/Apublic class InheritedChannelNotServerSocket {
0N/A private static final Object lock = new Object();
0N/A private static boolean notified = false;
0N/A
0N/A private InheritedChannelNotServerSocket() { }
0N/A
0N/A public interface Callback extends Remote {
0N/A void notifyTest() throws RemoteException;
0N/A }
0N/A
0N/A public static class CallbackImpl implements Callback {
0N/A CallbackImpl() { }
0N/A public void notifyTest() {
0N/A synchronized (lock) {
0N/A notified = true;
0N/A System.err.println("notification received.");
0N/A lock.notifyAll();
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A System.err.println("\nRegression test for bug 6261402\n");
5266N/A System.setProperty("java.rmi.activation.port",
5266N/A Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
0N/A RMID rmid = null;
0N/A Callback obj = null;
0N/A try {
0N/A /*
0N/A * Export callback object and bind in registry.
0N/A */
0N/A System.err.println("export callback object and bind in registry");
0N/A obj = new CallbackImpl();
0N/A Callback proxy =
0N/A (Callback) UnicastRemoteObject.exportObject(obj, 0);
0N/A Registry registry =
5266N/A LocateRegistry.createRegistry(
5266N/A TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
0N/A registry.bind("Callback", proxy);
0N/A
0N/A /*
0N/A * Start rmid.
0N/A */
0N/A System.err.println("start rmid with inherited channel");
0N/A RMID.removeLog();
5266N/A rmid = RMID.createRMID(System.out, System.err, true, true,
5266N/A TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
0N/A rmid.addOptions(new String[]{
0N/A "-Djava.nio.channels.spi.SelectorProvider=" +
0N/A "InheritedChannelNotServerSocket$SP"});
0N/A rmid.start();
0N/A
0N/A /*
0N/A * Get activation system and wait to be notified via callback
0N/A * from rmid's selector provider.
0N/A */
0N/A System.err.println("get activation system");
0N/A ActivationSystem system = ActivationGroup.getSystem();
0N/A System.err.println("ActivationSystem = " + system);
0N/A synchronized (lock) {
0N/A while (!notified) {
0N/A lock.wait();
0N/A }
0N/A }
0N/A System.err.println("TEST PASSED");
0N/A } finally {
0N/A if (obj != null) {
0N/A UnicastRemoteObject.unexportObject(obj, true);
0N/A }
5266N/A ActivationLibrary.rmidCleanup(rmid);
0N/A }
0N/A }
0N/A
0N/A public static class SP extends SelectorProvider {
0N/A private final SelectorProvider provider;
0N/A private volatile SocketChannel channel = null;
0N/A
0N/A public SP() {
0N/A provider = sun.nio.ch.DefaultSelectorProvider.create();
0N/A }
0N/A
0N/A public DatagramChannel openDatagramChannel() throws IOException {
0N/A return provider.openDatagramChannel();
0N/A }
0N/A
1037N/A public DatagramChannel openDatagramChannel(ProtocolFamily family)
1037N/A throws IOException
1037N/A {
1037N/A return provider.openDatagramChannel(family);
1037N/A }
1037N/A
0N/A public Pipe openPipe() throws IOException {
0N/A return provider.openPipe();
0N/A }
0N/A
0N/A public AbstractSelector openSelector() throws IOException {
0N/A return provider.openSelector();
0N/A }
0N/A
0N/A public ServerSocketChannel openServerSocketChannel()
0N/A throws IOException
0N/A {
0N/A return provider.openServerSocketChannel();
0N/A }
0N/A
0N/A public SocketChannel openSocketChannel() throws IOException {
0N/A return provider.openSocketChannel();
0N/A }
0N/A
0N/A public synchronized Channel inheritedChannel() throws IOException {
0N/A System.err.println("SP.inheritedChannel");
0N/A if (channel == null) {
0N/A channel = SocketChannel.open();
0N/A Socket socket = channel.socket();
0N/A System.err.println("socket = " + socket);
0N/A
0N/A /*
0N/A * Notify test that inherited channel was created.
0N/A */
0N/A try {
0N/A System.err.println("notify test...");
0N/A Registry registry =
5266N/A LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
0N/A Callback obj = (Callback) registry.lookup("Callback");
0N/A obj.notifyTest();
0N/A } catch (NotBoundException nbe) {
0N/A throw (IOException)
0N/A new IOException("callback object not bound").
0N/A initCause(nbe);
0N/A }
0N/A }
0N/A return channel;
0N/A }
0N/A }
0N/A}