home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / RemoteServer.java < prev    next >
Text File  |  1997-05-20  |  3KB  |  103 lines

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