private void checkSslConfig() throws IOException {
   // Get the reference to the RMI Registry and lookup RMIServer stub
   //
   Registry registry;
   try {
     registry =
         LocateRegistry.getRegistry(registryHostName, registryPort, sslRMIClientSocketFactory);
     try {
       stub = (RMIServer) registry.lookup("jmxrmi");
     } catch (NotBoundException nbe) {
       throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
     }
     sslRegistry = true;
   } catch (IOException e) {
     registry = LocateRegistry.getRegistry(registryHostName, registryPort);
     try {
       stub = (RMIServer) registry.lookup("jmxrmi");
     } catch (NotBoundException nbe) {
       throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
     }
     sslRegistry = false;
   }
   // Perform the checks for secure stub
   //
   try {
     checkStub(stub, rmiServerImplStubClass);
     sslStub = true;
   } catch (SecurityException e) {
     sslStub = false;
   }
 }
  /**
   * Create a MonitoredHostProvider instance using the given HostIdentifier.
   *
   * @param hostId the host identifier for this MonitoredHost
   * @throws MonitorException Thrown on any error encountered while communicating with the remote
   *     host.
   */
  public MonitoredHostProvider(HostIdentifier hostId) throws MonitorException {
    this.hostId = hostId;
    this.listeners = new ArrayList();
    this.interval = DEFAULT_POLLING_INTERVAL;
    this.activeVms = new HashSet();

    String rmiName;
    String sn = serverName;
    String path = hostId.getPath();

    if ((path != null) && (path.length() > 0)) {
      sn = path;
    }

    if (hostId.getPort() != -1) {
      rmiName = "rmi://" + hostId.getHost() + ":" + hostId.getPort() + sn;
    } else {
      rmiName = "rmi://" + hostId.getHost() + sn;
    }

    try {
      remoteHost = (RemoteHost) Naming.lookup(rmiName);

    } catch (RemoteException e) {
      /*
       * rmi registry not available
       *
       * Access control exceptions, where the rmi server refuses a
       * connection based on policy file configuration, come through
       * here on the client side. Unfortunately, the RemoteException
       * doesn't contain enough information to determine the true cause
       * of the exception. So, we have to output a rather generic message.
       */
      String message = "RMI Registry not available at " + hostId.getHost();

      if (hostId.getPort() == -1) {
        message = message + ":" + java.rmi.registry.Registry.REGISTRY_PORT;
      } else {
        message = message + ":" + hostId.getPort();
      }

      if (e.getMessage() != null) {
        throw new MonitorException(message + "\n" + e.getMessage(), e);
      } else {
        throw new MonitorException(message, e);
      }

    } catch (NotBoundException e) {
      // no server with given name
      String message = e.getMessage();
      if (message == null) message = rmiName;
      throw new MonitorException("RMI Server " + message + " not available", e);
    } catch (MalformedURLException e) {
      // this is a programming problem
      e.printStackTrace();
      throw new IllegalArgumentException("Malformed URL: " + rmiName);
    }
    this.vmManager = new RemoteVmManager(remoteHost);
    this.timer = new Timer(true);
  }
Exemple #3
0
 /**
  * ***************************************************************
  *
  * @param ip
  * @param port
  * @return
  */
 public ChordMessageInterface rmiChord(String ip, int port) {
   ChordMessageInterface chord = null;
   try {
     Registry registry = LocateRegistry.getRegistry(ip, port);
     chord = (ChordMessageInterface) (registry.lookup("Chord"));
     return chord;
   } catch (RemoteException e) {
     e.printStackTrace();
   } catch (NotBoundException e) {
     e.printStackTrace();
   }
   return null;
 }