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