rmihello/example/hello/Server.java
changeset 92 0bc2646daa82
equal deleted inserted replaced
91:1181deef3bd6 92:0bc2646daa82
       
     1 /*
       
     2  * Copyright 2004 Sun Microsystems, Inc. All  Rights Reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or
       
     5  * without modification, are permitted provided that the following
       
     6  * conditions are met:
       
     7  *
       
     8  * -Redistributions of source code must retain the above copyright
       
     9  *  notice, this list of conditions and the following disclaimer.
       
    10  *
       
    11  * -Redistribution in binary form must reproduce the above copyright
       
    12  *  notice, this list of conditions and the following disclaimer in
       
    13  *  the documentation and/or other materials provided with the
       
    14  *  distribution.
       
    15  *
       
    16  * Neither the name of Sun Microsystems, Inc. or the names of
       
    17  * contributors may be used to endorse or promote products derived
       
    18  * from this software without specific prior written permission.
       
    19  *
       
    20  * This software is provided "AS IS," without a warranty of any
       
    21  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
       
    22  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
       
    23  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
       
    24  * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
       
    25  * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
       
    26  * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
       
    27  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
       
    28  * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
       
    29  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
       
    30  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
       
    31  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN
       
    32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
       
    33  *
       
    34  * You acknowledge that Software is not designed, licensed or
       
    35  * intended for use in the design, construction, operation or
       
    36  * maintenance of any nuclear facility.
       
    37  */
       
    38 package example.hello;
       
    39 
       
    40 import java.rmi.registry.Registry;
       
    41 import java.rmi.registry.LocateRegistry;
       
    42 import java.rmi.RemoteException;
       
    43 import java.rmi.server.UnicastRemoteObject;
       
    44 
       
    45 public class Server implements Hello {
       
    46 
       
    47     public Server () {
       
    48     }
       
    49 
       
    50     public String sayHello () {
       
    51         return "Hello, world!";
       
    52     }
       
    53 
       
    54     public static void main (String args[]) {
       
    55         try {
       
    56             Server obj = new Server ();
       
    57             Hello stub = (Hello) UnicastRemoteObject.exportObject (obj, 0);
       
    58 
       
    59             // Bind the remote object's stub in the registry
       
    60             Registry registry = LocateRegistry.getRegistry ();
       
    61             registry.bind ("Hello", stub);
       
    62 
       
    63             System.err.println ("Server ready");
       
    64         } catch (Exception e) {
       
    65             System.err.println ("Server exception: " + e.toString ());
       
    66             e.printStackTrace ();
       
    67         }
       
    68     }
       
    69 }