rmihello/example/hello/Client.java
author Markus Bröker <mbroeker@largo.dyndns.tv>
Mon, 21 Jun 2010 21:58:00 +0200
changeset 136 d82f65e902d0
parent 92 0bc2646daa82
permissions -rw-r--r--
getdir errors: avoid unneeded memory leaks committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
92
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/*
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 * Copyright 2004 Sun Microsystems, Inc. All  Rights Reserved.
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 *
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
 * without modification, are permitted provided that the following
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
 * conditions are met:
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
 *
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
 * -Redistributions of source code must retain the above copyright
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
 *  notice, this list of conditions and the following disclaimer.
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
 *
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
 * -Redistribution in binary form must reproduce the above copyright
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
 *  notice, this list of conditions and the following disclaimer in
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
 *  the documentation and/or other materials provided with the
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
 *  distribution.
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
 *
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
 * Neither the name of Sun Microsystems, Inc. or the names of
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
 * contributors may be used to endorse or promote products derived
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
 * from this software without specific prior written permission.
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
 *
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
 * This software is provided "AS IS," without a warranty of any
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
 * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
 * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
 *
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
 * You acknowledge that Software is not designed, licensed or
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
 * intended for use in the design, construction, operation or
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
 * maintenance of any nuclear facility.
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
 */
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
package example.hello;
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
import java.rmi.registry.LocateRegistry;
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
import java.rmi.registry.Registry;
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
public class Client {
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
    private Client () {
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
    }
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
    public static void main (String[]args) {
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
        String host = (args.length < 1) ? null : args[0];
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
        try {
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
            Registry registry = LocateRegistry.getRegistry (host);
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
            Hello stub = (Hello) registry.lookup ("Hello");
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
            String response = stub.sayHello ();
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
            System.out.println ("response: " + response);
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
        } catch (Exception e) {
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
            System.err.println ("Client exception: " + e.toString ());
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
            e.printStackTrace ();
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
        }
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
    }
0bc2646daa82 RMI Hello Example from Sun Microsystems
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
}