1. /*
  2. * @(#)RMIIIOPServerImpl.java 1.24 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management.remote.rmi;
  8. import java.io.IOException;
  9. import java.rmi.Remote;
  10. import java.util.Map;
  11. import java.util.Collections;
  12. import java.util.Properties;
  13. import javax.rmi.PortableRemoteObject;
  14. import javax.security.auth.Subject;
  15. /**
  16. * <p>An {@link RMIServerImpl} that is exported through IIOP and that
  17. * creates client connections as RMI objects exported through IIOP.
  18. * User code does not usually reference this class directly.</p>
  19. *
  20. * @see RMIServerImpl
  21. *
  22. * @since 1.5
  23. * @since.unbundled 1.0
  24. */
  25. public class RMIIIOPServerImpl extends RMIServerImpl {
  26. /**
  27. * <p>Creates a new {@link RMIServerImpl}.</p>
  28. *
  29. * @param env the environment containing attributes for the new
  30. * <code>RMIServerImpl</code>. Can be null, which is equivalent
  31. * to an empty Map.
  32. *
  33. * @exception IOException if the RMI object cannot be created.
  34. */
  35. public RMIIIOPServerImpl(Map<String,?> env)
  36. throws IOException {
  37. super(env);
  38. this.env = (env == null) ? Collections.EMPTY_MAP : env;
  39. }
  40. protected void export() throws IOException {
  41. PortableRemoteObject.exportObject(this);
  42. }
  43. protected String getProtocol() {
  44. return "iiop";
  45. }
  46. /**
  47. * <p>Returns an IIOP stub.</p>
  48. * The stub might not yet be connected to the ORB. The stub will
  49. * be serializable only if it is connected to the ORB.
  50. * @return an IIOP stub.
  51. * @exception IOException if the stub cannot be created - e.g the
  52. * RMIIIOPServerImpl has not been exported yet.
  53. **/
  54. public Remote toStub() throws IOException {
  55. // javax.rmi.CORBA.Stub stub =
  56. // (javax.rmi.CORBA.Stub) PortableRemoteObject.toStub(this);
  57. final Remote stub = PortableRemoteObject.toStub(this);
  58. // java.lang.System.out.println("NON CONNECTED STUB " + stub);
  59. // org.omg.CORBA.ORB orb =
  60. // org.omg.CORBA.ORB.init((String[])null, (Properties)null);
  61. // stub.connect(orb);
  62. // java.lang.System.out.println("CONNECTED STUB " + stub);
  63. return (Remote) stub;
  64. }
  65. /**
  66. * <p>Creates a new client connection as an RMI object exported
  67. * through IIOP.
  68. *
  69. * @param connectionId the ID of the new connection. Every
  70. * connection opened by this connector server will have a
  71. * different ID. The behavior is unspecified if this parameter is
  72. * null.
  73. *
  74. * @param subject the authenticated subject. Can be null.
  75. *
  76. * @return the newly-created <code>RMIConnection</code>.
  77. *
  78. * @exception IOException if the new client object cannot be
  79. * created or exported.
  80. */
  81. protected RMIConnection makeClient(String connectionId, Subject subject)
  82. throws IOException {
  83. if (connectionId == null)
  84. throw new NullPointerException("Null connectionId");
  85. RMIConnection client =
  86. new RMIConnectionImpl(this, connectionId, getDefaultClassLoader(),
  87. subject, env);
  88. PortableRemoteObject.exportObject(client);
  89. return client;
  90. }
  91. protected void closeClient(RMIConnection client) throws IOException {
  92. PortableRemoteObject.unexportObject(client);
  93. }
  94. /**
  95. * <p>Called by {@link #close()} to close the connector server by
  96. * unexporting this object. After returning from this method, the
  97. * connector server must not accept any new connections.</p>
  98. *
  99. * @exception IOException if the attempt to close the connector
  100. * server failed.
  101. */
  102. protected void closeServer() throws IOException {
  103. PortableRemoteObject.unexportObject(this);
  104. }
  105. private final Map env;
  106. }