home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / guide / rmi / activation / code / Client.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  2.8 KB  |  76 lines

  1. /*
  2.  * Copyright (c) 1998, 1999 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  5.  * modify and redistribute this software in source and binary code form,
  6.  * provided that i) this copyright notice and license appear on all copies of
  7.  * the software; and ii) Licensee does not utilize the software in a manner
  8.  * which is disparaging to Sun.
  9.  *
  10.  * This software is provided "AS IS," without a warranty of any kind. ALL
  11.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  12.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  13.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  14.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  15.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  16.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  17.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  18.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  19.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  20.  * POSSIBILITY OF SUCH DAMAGES.
  21.  *
  22.  * This software is not designed or intended for use in on-line control of
  23.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  24.  * the design, construction, operation or maintenance of any nuclear
  25.  * facility. Licensee represents and warrants that it will not use or
  26.  * redistribute the Software for such purposes.
  27.  */
  28. package examples.activation; 
  29.  
  30. import java.rmi.*;
  31.  
  32. public class Client {
  33.  
  34.     public static void main(String args[]) {
  35.  
  36.     String server = "localhost";
  37.     if (args.length < 1) {
  38.         System.out.println ("Usage: java Client <rmihost>");
  39.         System.exit(1);
  40.     } else {
  41.         server = args[0];
  42.     }
  43.  
  44.     try {
  45.  
  46.         String location = "rmi://" + server + "/ActivatableImplementation";
  47.  
  48.         // Since you can't create an instance of an interface, what we get 
  49.         // back from the lookup method is a remote reference to an object
  50.         // that implements MyRemoteInterface.
  51.         //  
  52.         // Then we cast the remote reference (serialized stub instance)
  53.         // returned from Naming.lookup to a "MyRemoteInterface" so we can
  54.         // call the interface method(s).    
  55.             //         
  56.         MyRemoteInterface mri = (MyRemoteInterface)Naming.lookup(location);
  57.         System.out.println("Got a remote reference to the object that" + 
  58.         " extends Activatable.");
  59.  
  60.         // The String "result" will be changed to "Success" by the remote 
  61.         // method call
  62.         //
  63.         String result = "failure";
  64.         System.out.println("Making remote call to the server");
  65.  
  66.         result = (String)mri.callMeRemotely();
  67.         System.out.println("Returned from remote call");
  68.         System.out.println("Result: " + result);
  69.  
  70.     } catch (Exception e) {
  71.         e.printStackTrace();
  72.     }
  73.     }
  74. }
  75.  
  76.