home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / RemoteServer.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  96 lines

  1. /*
  2.  * @(#)RemoteServer.java    1.9 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.rmi.server;
  15.  
  16. import java.rmi.*;
  17.  
  18. /**
  19.  * The RemoteServer class is the common superclass to all server
  20.  * implementations and provides the framework to support a wide range
  21.  * of remote reference semantics.  Specifically, the functions needed
  22.  * to create and export remote objects (i.e. to make them remotely
  23.  * available) are provided abstractly by RemoteServer and concretely
  24.  * by its subclass(es). <p>
  25.  *
  26.  * The subclass selected identifies the semantics of the remote
  27.  * reference, for example whether the server is a single object or is
  28.  * a replicated object requiring communications with multiple
  29.  * locations. At present only UnicastRemoteObject is supported.
  30.  */
  31. public abstract class RemoteServer extends RemoteObject
  32. {
  33.     private static String logname = "RMI";
  34.     private static LogStream log;
  35.  
  36.     protected RemoteServer() {
  37.     super();
  38.     }
  39.     
  40.     protected RemoteServer(RemoteRef ref) {
  41.     super(ref);
  42.     }
  43.  
  44.     /**
  45.      * Return the hostname of the current client.  When called from a
  46.      * thread actively handling a remote method invocation the
  47.      * hostname of the client is returned.
  48.      * @exception ServerNotActiveException If called outside of servicing
  49.      * a remote method invocation.
  50.      */
  51.     public static String getClientHost() throws ServerNotActiveException {
  52.     try {
  53.         Class refClass = Class.forName(RemoteRef.packagePrefix +
  54.                        ".UnicastServerRef");
  55.         ServerRef ref = (ServerRef)refClass.newInstance();
  56.         return ref.getClientHost();
  57.     } catch (ServerNotActiveException e) {
  58.         throw e;
  59.     } catch (Exception e) {
  60.         throw new ServerNotActiveException("Client host unobtainable");
  61.     }
  62.     }
  63.  
  64.     /**
  65.      * Log RMI calls to the output stream <I>out</I>. If <I>out</I> is
  66.      * null, call logging is turned off.
  67.      */
  68.     public static void setLog(java.io.OutputStream out) 
  69.     {
  70.     if (out == null) {
  71.         log = null;
  72.     } else {
  73.         LogStream tempLog = LogStream.log(logname);
  74.         tempLog.setOutputStream(out);
  75.         log = tempLog;
  76.     }
  77.     }
  78.     /**
  79.      * Returns stream for the RMI call log.
  80.      */
  81.     public static java.io.PrintStream getLog() 
  82.     {
  83.     return log;
  84.     }
  85.  
  86.     static 
  87.     {
  88.     // initialize log
  89.     try {
  90.         log = (Boolean.getBoolean("java.rmi.server.logCalls") ?
  91.            LogStream.log(logname) : null);
  92.     } catch (Exception e) {
  93.     }
  94.     }
  95. }
  96.