1. /*
  2. * @(#)RemoteServer.java 1.22 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.rmi.server;
  11. import java.rmi.*;
  12. /**
  13. * The <code>RemoteServer</code> class is the common superclass to server
  14. * implementations and provides the framework to support a wide range
  15. * of remote reference semantics. Specifically, the functions needed
  16. * to create and export remote objects (i.e. to make them remotely
  17. * available) are provided abstractly by <code>RemoteServer</code> and
  18. * concretely by its subclass(es).
  19. *
  20. * @version 1.22, 02/02/00
  21. * @author Ann Wollrath
  22. * @since JDK1.1
  23. */
  24. public abstract class RemoteServer extends RemoteObject
  25. {
  26. private static String logname = "RMI";
  27. private static LogStream log;
  28. /* indicate compatibility with JDK 1.1.x version of class */
  29. private static final long serialVersionUID = -4100238210092549637L;
  30. /**
  31. * Constructs a <code>RemoteServer</code>.
  32. * @since JDK1.1
  33. */
  34. protected RemoteServer() {
  35. super();
  36. }
  37. /**
  38. * Constructs a <code>RemoteServer</code> with the given reference type.
  39. *
  40. * @param ref the remote reference
  41. * @since JDK1.1
  42. */
  43. protected RemoteServer(RemoteRef ref) {
  44. super(ref);
  45. }
  46. /**
  47. * Return the hostname of the current client. When called from a
  48. * thread actively handling a remote method invocation the
  49. * hostname of the client is returned.
  50. * @exception ServerNotActiveException If called outside of servicing
  51. * a remote method invocation.
  52. * @return client hostname
  53. * @since JDK1.1
  54. */
  55. public static String getClientHost() throws ServerNotActiveException {
  56. return sun.rmi.transport.tcp.TCPTransport.getClientHost();
  57. }
  58. /**
  59. * Log RMI calls to the output stream <I>out</I>. If <I>out</I> is
  60. * null, call logging is turned off.
  61. * @param out the output stream to which RMI calls should be logged
  62. * @since JDK1.1
  63. */
  64. public static void setLog(java.io.OutputStream out)
  65. {
  66. if (out == null) {
  67. log = null;
  68. } else {
  69. LogStream tempLog = LogStream.log(logname);
  70. tempLog.setOutputStream(out);
  71. log = tempLog;
  72. }
  73. }
  74. /**
  75. * Returns stream for the RMI call log.
  76. * @return the call log
  77. * @since JDK1.1
  78. */
  79. public static java.io.PrintStream getLog()
  80. {
  81. return log;
  82. }
  83. static
  84. {
  85. // initialize log
  86. try {
  87. Boolean tmp = (Boolean)java.security.AccessController.doPrivileged(
  88. new sun.security.action.GetBooleanAction("java.rmi.server.logCalls"));
  89. boolean logCalls = tmp.booleanValue();
  90. log = logCalls ? LogStream.log(logname) : null;
  91. } catch (Exception e) {
  92. }
  93. }
  94. }