jdk/test/com/sun/corba/transport/KeepAliveSockets.java
author coffeys
Tue, 03 Sep 2013 22:37:07 +0100
changeset 19801 97f3caac6c77
child 30820 0d4717a011d3
permissions -rw-r--r--
8017195: Introduce option to setKeepAlive parameter on CORBA sockets Reviewed-by: chegar, msheppar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19801
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     1
/*
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     4
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     7
 * published by the Free Software Foundation.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     8
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    13
 * accompanied this code).
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    14
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    18
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    21
 * questions.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    22
 */
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    23
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    24
/*
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    25
 * @test
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    26
 * @bug 8017195
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    27
 * @summary Introduce option to setKeepAlive parameter on CORBA sockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    28
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    29
 * @run main/othervm KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    30
 * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    31
 * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive=true KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    32
 * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive=false KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    33
 */
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    34
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    35
import java.lang.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    36
import java.net.InetSocketAddress;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    37
import java.net.Socket;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    38
import java.nio.channels.ServerSocketChannel;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    39
import java.util.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    40
import com.sun.corba.se.impl.orb.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    41
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    42
import com.sun.corba.se.impl.transport.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    43
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    44
public class KeepAliveSockets {
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    45
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    47
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    48
        boolean keepAlive = false;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    49
        String prop = System.getProperty("com.sun.CORBA.transport.enableTcpKeepAlive");
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    50
        if (prop != null)
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    51
            keepAlive = !"false".equalsIgnoreCase(prop);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    52
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    53
        DefaultSocketFactoryImpl sfImpl = new DefaultSocketFactoryImpl();
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    54
        ORBImpl orb = new ORBImpl();
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    55
        orb.set_parameters(null);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    56
        sfImpl.setORB(orb);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    57
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    58
        ServerSocketChannel ssc = ServerSocketChannel.open();
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    59
        ssc.socket().bind(new InetSocketAddress(0));
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    60
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    61
        InetSocketAddress isa = new InetSocketAddress("localhost", ssc.socket().getLocalPort());
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    62
        Socket s = sfImpl.createSocket("ignore", isa);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    63
        System.out.println("Received factory socket" + s);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    64
        if (keepAlive != s.getKeepAlive())
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    65
            throw new RuntimeException("KeepAlive value not honoured in CORBA socket");
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    66
    }
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    67
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    68
}