Last commit for RTU_RegistrarImpl.java: a87d8e28d0332a216a5d6e0104908fc9e5ff58b9

added javadoc comments

dp2041 [2002-10-26 00:38:20]
added javadoc comments
  1. /*
  2.  * @(#)RTU_RegistrarImpl.java
  3.  *
  4.  * Copyright (c) 2001: The Trustees of Columbia University in the City of New York. All Rights Reserved
  5.  *
  6.  * Copyright (c) 2001: @author Dan Phung (dp2041@cs.columbia.edu)
  7.  *
  8.  * CVS version control block - do not edit manually
  9.  * $RCSfile$
  10.  * $Revision$
  11.  * $Date$
  12.  * $Source$
  13.  */
  14.  
  15. package psl.worklets;
  16.  
  17. import java.rmi.*;
  18. import java.rmi.server.*;
  19. import java.security.*;
  20. import java.util.*;
  21. import java.net.MalformedURLException;
  22.  
  23. /**
  24.  * Acts as an intermediary between the registry and the RTU for RMI
  25.  * server registration purposes.
  26.  */
  27. /*
  28.   The reasoning for the existence of this object inbetween the RTU and
  29.   the registry is because if the RTU is secure and tries to make a
  30.   Naming call, it will get an exception because the RTU is expecting a
  31.   secure protocol. This object acts as an intermediary by calling the
  32.   Naming "binding" with itself, but in the WVM_Registry the server
  33.   that this class contains is the server that is actually bound.
  34.  */
  35. class RTU_RegistrarImpl extends UnicastRemoteObject implements RTU_Registrar{
  36. /** RMI name of the associated RMI server */
  37. private final String _name;
  38. /** Hostname of the system with the associated RMI server */
  39. private final String _host;
  40. /** Port that the RMI server handle is on, usually the port of the {@link WVM_Registry} */
  41. private final int _port;
  42. /** Unique registration key to be associated with the RMI server */
  43. private final String _registrationKey;
  44. /** Unique WVM_URL of the RMI server */
  45. private final String _WVM_URL;
  46. /** RTU that this registrar will handle */
  47. private WVM_RMI_Transporter.RTU _rtu;
  48.  
  49. /**
  50.   * Creates a RTU_Registrar
  51.   *
  52.   * @param name: RMI name of the RMI server
  53.   * @param host: hostname of the system
  54.   * @param port: port that the RMI server handle is on, usually the port of the {@link WVM_Registry}
  55.   * @param rng: <code>SecureRandom</code> (random number generator algorithm) to use
  56.   * @param seed: seed for the rng
  57.   * @throws RemoteException if RTU_Registrar cannot be created
  58.   */
  59. RTU_RegistrarImpl(String name, String host, int port, String rng, Date seed) throws RemoteException{
  60. super(0);
  61. _name = name;
  62. _host = host;
  63. _port = port;
  64.  
  65. SecureRandom r = null;
  66. if (rng == null) rng = "";
  67. try {
  68. r = SecureRandom.getInstance(rng);
  69. } catch (NoSuchAlgorithmException nsae){
  70. // WVM.err.println("Exception try to get instance of: " + rng + ":" + nsae);
  71. r = new SecureRandom();
  72. // WVM.out.println("Default to highest-priority installed provider: " + r.getProvider());
  73. }
  74. r.setSeed(seed.getTime());
  75. _registrationKey = "" + r.nextLong();
  76. _WVM_URL = _name + "@" + _host + ":" + _port;
  77. }
  78.  
  79. /**
  80.   * Binds the given RTU to the {@link WVM_Registry}
  81.   *
  82.   * @param rmibind: the RMI URL to bind, usually "rmi://" + hostname + ":" + port + "/" + RMI_name
  83.   * @param rtu: the RMI server to bind
  84.   * @throws RemoteException if the RTU could not be bound
  85.   * @throws AlreadyBoundException if the given rmibind URL is already used
  86.   * @throws MalformedURLException if the rmibind URL is malformed
  87.   */
  88. void bind(String rmibind, WVM_RMI_Transporter.RTU rtu) throws RemoteException, AlreadyBoundException, MalformedURLException{
  89. _rtu = rtu;
  90. Naming.bind(rmibind, this);
  91. }
  92.  
  93. /**
  94.   * Rebinds the given RTU to the {@link WVM_Registry}
  95.   *
  96.   * @param rmibind: the RMI URL to rebind, usually "rmi://" + hostname + ":" + port + "/" + RMI_name
  97.   * @param rtu: the RMI server to rebind
  98.   * @throws RemoteException if the RTU could not be rebound
  99.   * @throws MalformedURLException if the rmibind URL is malformed
  100.   */
  101. void rebind(String rmibind, WVM_RMI_Transporter.RTU rtu) throws RemoteException, MalformedURLException{
  102. _rtu = rtu;
  103. Naming.rebind(rmibind, this);
  104. }
  105.  
  106. /** Gets the RTU/RMI server */
  107. public Remote getServer() throws RemoteException{
  108. return _rtu;
  109. }
  110.  
  111. /** Gets the registration key of the RTU/RMI server */
  112. public String getRegistrationKey() throws RemoteException{
  113. return _registrationKey;
  114. }
  115.  
  116. /**
  117.   * Gets the WVM_URL of the RTU/RMI server. The WVM_URL is a URL
  118.   * that represents a {@link WVM} location in the form of :
  119.   * remote_hostname@RMI_name:remote_port where the RMI_name is
  120.   * optional.
  121.   */
  122. public String getWVM_URL() throws RemoteException{
  123. return _WVM_URL;
  124. }
  125. }
  126.