jdk/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 309 bda219d843f6
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 309
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.rmi.registry.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class HelloImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    implements Hello
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public static boolean clientCalledSuccessfully = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public HelloImpl() throws RemoteException {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    39
        super(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    }
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public synchronized String sayHello() {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    43
        HelloImpl.clientCalledSuccessfully = true;
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    44
        System.out.println("hello method called");
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    45
        this.notifyAll();
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    46
        return "hello";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static void main(String[] args) {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    50
        /*
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    51
         * The following line is required with the JDK 1.2 VM so that the
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    52
         * VM can exit gracefully when this test completes.  Otherwise, the
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    53
         * conservative garbage collector will find a handle to the server
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    54
         * object on the native stack and not clear the weak reference to
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    55
         * it in the RMI runtime's object table.
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    56
         */
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    57
        Object dummy = new Object();
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    58
        Hello hello = null;
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    59
        Registry registry = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    61
        TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    63
        try {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    64
            String protocol = "";
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    65
            if (args.length >= 1)
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    66
                protocol = args[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    68
            registry = java.rmi.registry.LocateRegistry.
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    69
                getRegistry("localhost", TestLibrary.REGISTRY_PORT,
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    70
                            new Compress.CompressRMIClientSocketFactory());
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    71
            UseCustomSocketFactory.checkStub(registry, "RMIClientSocket");
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    72
            hello = (Hello) registry.lookup("/HelloServer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    74
            /* lookup server */
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    75
            System.err.println(hello.sayHello() +
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    76
                               ", remote greeting.");
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    77
        } catch (Exception e) {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    78
            System.err.println("EXCEPTION OCCURRED:");
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    79
            e.printStackTrace();
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    80
        } finally {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    81
            hello = null;
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    82
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}