home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / rmi / server / RemoteServer.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  4.1 KB  |  130 lines

  1. /*
  2.  * @(#)RemoteServer.java    1.15 98/03/18
  3.  *
  4.  * Copyright 1996-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. import sun.rmi.transport.ObjectTable;
  18.  
  19. /**
  20.  * The RemoteServer class is the common superclass to all server
  21.  * implementations and provides the framework to support a wide range
  22.  * of remote reference semantics.  Specifically, the functions needed
  23.  * to create and export remote objects (i.e. to make them remotely
  24.  * available) are provided abstractly by RemoteServer and concretely
  25.  * by its subclass(es). <p>
  26.  *
  27.  * The subclass selected identifies the semantics of the remote
  28.  * reference, for example whether the server is a single object or is
  29.  * a replicated object requiring communications with multiple
  30.  * locations. At present only UnicastRemoteObject is supported.
  31.  */
  32. public abstract class RemoteServer extends RemoteObject
  33. {
  34.     private static String logname = "RMI";
  35.     private static LogStream log;
  36.  
  37.     /* indicate compatibility with JDK 1.1.x version of class */
  38.     private static final long serialVersionUID = -4100238210092549637L;
  39.  
  40.     protected RemoteServer() {
  41.     super();
  42.     }
  43.     
  44.     protected RemoteServer(RemoteRef ref) {
  45.     super(ref);
  46.     }
  47.  
  48.    /**
  49.     * Remove the remote object, obj, from the RMI runtime. If
  50.     * successful, the object can no longer accept incoming RMI calls.
  51.     * If the force parameter is true, the object is forcibly unexported
  52.     * even if there are pending calls to the remote object or the
  53.     * remote object still has calls in progress.  If the force
  54.     * parameter is false, the object is only unexported if there are
  55.     * no pending or in progress calls to the object.
  56.     *
  57.     * @param obj the remote object to be unexported
  58.     * @param force if true, unexports the object even if there are
  59.     * pending or in-progress calls; if false, only unexports the object
  60.     * if there are no pending or in-progress calls
  61.     * @return true if operation is successful, false otherwise
  62.     * @exception NoSuchObjectException if the remote object is not
  63.     * currently exported
  64.     */
  65.    public static boolean unexportObject(Remote obj, boolean force)
  66.     throws java.rmi.NoSuchObjectException
  67.     {
  68.     return ObjectTable.unexportObject(obj, force);
  69.     }
  70.     
  71.     /**
  72.      * Return the hostname of the current client.  When called from a
  73.      * thread actively handling a remote method invocation the
  74.      * hostname of the client is returned.
  75.      * @exception ServerNotActiveException If called outside of servicing
  76.      * a remote method invocation.
  77.      */
  78.     public static String getClientHost() throws ServerNotActiveException {
  79.     try {
  80.         Class refClass = Class.forName(RemoteRef.packagePrefix +
  81.                        ".UnicastServerRef");
  82.         ServerRef ref = (ServerRef)refClass.newInstance();
  83.         return ref.getClientHost();
  84.     } catch (ServerNotActiveException e) {
  85.         throw e;
  86.     } catch (Exception e) {
  87.         throw new ServerNotActiveException("Client host unobtainable");
  88.     }
  89.     }
  90.  
  91.     /**
  92.      * Log RMI calls to the output stream <I>out</I>. If <I>out</I> is
  93.      * null, call logging is turned off.
  94.      */
  95.     public static void setLog(java.io.OutputStream out) 
  96.     {
  97.     if (out == null) {
  98.         log = null;
  99.     } else {
  100.         LogStream tempLog = LogStream.log(logname);
  101.         tempLog.setOutputStream(out);
  102.         log = tempLog;
  103.     }
  104.     }
  105.     /**
  106.      * Returns stream for the RMI call log.
  107.      */
  108.     public static java.io.PrintStream getLog() 
  109.     {
  110.     return log;
  111.     }
  112.  
  113.     static 
  114.     {
  115.     // initialize log
  116.     try {
  117.         boolean logCalls;
  118.  
  119.         try {
  120.         java.security.AccessController.beginPrivileged();
  121.         logCalls = Boolean.getBoolean("java.rmi.server.logCalls");
  122.         } finally {
  123.         java.security.AccessController.endPrivileged();
  124.         }
  125.         log = logCalls ? LogStream.log(logname) : null;
  126.     } catch (Exception e) {
  127.     }
  128.     }
  129. }
  130.