Exemple #1
0
 /**
  * Requests a {@link RServi} instance from a pool. The pool must be accessible via RMI under the
  * given address.
  *
  * <p>The R services returned by this method are available for exclusive usage by the caller
  * (consumer). The consumer is responsible to return it to the pool by {@link RServi#close()
  * closing} the RServi.
  *
  * <p>For SSL connections, use the prefix <code>ssl:</code>. Note that SSL requires the
  * configuration of keystore and truststore at server and client side.
  *
  * @param address the RMI address of the pool
  * @param name a name which can be used to identify the client
  * @return a reference to the RServi instance
  * @throws CoreException if the operation was failed; the status of the exception contains detail
  *     about the cause
  * @throws NoSuchElementException if there is currently no free RServi instance available. A later
  *     call with the same configuration can be successfully.
  * @throws LoginException if the RServi request requires authentication
  */
 public static RServi getRServi(final String address, final String name)
     throws CoreException, NoSuchElementException, LoginException {
   try {
     RjsComConfig.setRMIClientSocketFactory(null);
     RServiPool pool;
     try {
       final RMIAddress rmiAddress = new RMIAddress(address);
       final Registry registry =
           LocateRegistry.getRegistry(
               rmiAddress.getHost(),
               rmiAddress.getPortNum(),
               (rmiAddress.isSSL()) ? new SslRMIClientSocketFactory() : null);
       pool = (RServiPool) registry.lookup(rmiAddress.getName());
     } catch (final MalformedURLException e) {
       throw new CoreException(
           new Status(IStatus.ERROR, RJ_SERVI_ID, 0, "Invalid address for the RServi pool.", e));
     } catch (final UnknownHostException e) {
       throw new CoreException(
           new Status(IStatus.ERROR, RJ_SERVI_ID, 0, "Invalid address for the RServi pool.", e));
     } catch (final NotBoundException e) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               RJ_SERVI_ID,
               0,
               "The address does not point to a valid RServi pool.",
               e));
     } catch (final ClassCastException e) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               RJ_SERVI_ID,
               0,
               "The address does not point to a valid/compatible RServi pool.",
               e));
     } catch (final RemoteException e) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               RJ_SERVI_ID,
               0,
               "Failed looking for RServi pool in the RMI registry.",
               e));
     }
     try {
       return pool.getRServi(name, null);
     } catch (final RjException e) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               RJ_SERVI_ID,
               0,
               "Failed getting an RServi instance from the RServi pool.",
               e));
     } catch (final RemoteException e) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               RJ_SERVI_ID,
               0,
               "Failed looking for RServi pool in the RMI registry.",
               e));
     }
   } finally {
     RjsComConfig.clearRMIClientSocketFactory();
   }
 }
  private static IStatus collectServerInfos(
      String address,
      int port,
      final SpecialAddress special,
      final List<RemoteR> infos,
      final SubMonitor progress) {
    try {
      if (special != null) {
        address = special.fPublicHost;
        port = special.fPort;
      }
      progress.subTask(
          NLS.bind(Messages.RRemoteConsoleSelectionDialog_task_Resolving_message, address));
      final InetAddress inetAddress = InetAddress.getByName(address);
      final String hostname = inetAddress.getHostName();
      final String hostip = inetAddress.getHostAddress();
      progress.worked(1);
      if (progress.isCanceled()) {
        return Status.CANCEL_STATUS;
      }

      progress.subTask(
          NLS.bind(Messages.RRemoteConsoleSelectionDialog_task_Connecting_message, hostname));
      final Registry registry;
      if (special != null) {
        final RMIClientSocketFactory socketFactory = special.getSocketFactory(progress.newChild(5));
        RjsComConfig.setRMIClientSocketFactory(socketFactory);
        registry = LocateRegistry.getRegistry(special.fPrivateHost, port, socketFactory);
      } else {
        RjsComConfig.setRMIClientSocketFactory(null);
        registry = LocateRegistry.getRegistry(address, port);
      }
      final String rmiBase =
          (port == Registry.REGISTRY_PORT)
              ? "//" + address + '/'
              : //$NON-NLS-1$
              "//" + address + ':' + port + '/'; // $NON-NLS-1$
      final String[] names = registry.list();
      for (final String name : names) {
        try {
          final Remote remote = registry.lookup(name);
          if (remote instanceof Server) {
            final Server server = (Server) remote;
            final ServerInfo info = server.getInfo();
            final String rmiAddress = rmiBase + name;
            final RemoteR r = new RemoteR(hostname, hostip, rmiAddress, info);
            infos.add(r);
          }
        } catch (final Exception e) {
        }
      }
      return Status.OK_STATUS;
    } catch (final RemoteException e) {
      return new Status(IStatus.WARNING, RConsoleUIPlugin.PLUGIN_ID, address);
    } catch (final UnknownHostException e) {
      return new Status(
          IStatus.ERROR,
          RConsoleUIPlugin.PLUGIN_ID,
          "Unknown host: " + e.getLocalizedMessage()); // $NON-NLS-1$
    } catch (final CoreException e) {
      return e.getStatus();
    } finally {
      RjsComConfig.clearRMIClientSocketFactory();
    }
  }