Example #1
0
  public static RjsConnection lookup(
      final Registry registry, final RemoteException registryException, final RMIAddress address)
      throws CoreException {
    if (address == null) {
      throw new NullPointerException();
    }

    final int[] clientVersion = AbstractRJComClient.version();
    clientVersion[2] = -1;
    final Server server;
    int[] version;
    try {
      if (registryException != null) {
        throw registryException;
      }
      server = (Server) registry.lookup(address.getName());
      version = server.getVersion();
    } catch (final NotBoundException e) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              RConsoleCorePlugin.PLUGIN_ID,
              ICommonStatusConstants.LAUNCHING,
              "The specified R engine is not in the service registry (RMI).",
              e));
    } catch (final RemoteException e) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              RConsoleCorePlugin.PLUGIN_ID,
              ICommonStatusConstants.LAUNCHING,
              NLS.bind(
                  "Cannot access the host/service registry (RMI) at ''{0}''.",
                  address.getRegistryAddress()),
              e));
    } catch (final ClassCastException e) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              RConsoleCorePlugin.PLUGIN_ID,
              ICommonStatusConstants.LAUNCHING,
              NLS.bind(
                  "The specified R engine ({0}) is incompatibel to this client ({1}).",
                  RjsUtil.getVersionString(null), RjsUtil.getVersionString(clientVersion)),
              e));
    }
    if (version.length != 3 || version[0] != clientVersion[0] || version[1] != clientVersion[1]) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              RConsoleCorePlugin.PLUGIN_ID,
              ICommonStatusConstants.LAUNCHING,
              NLS.bind(
                  "The specified R engine ({0}) is incompatibel to this client ({1}).",
                  RjsUtil.getVersionString(version), RjsUtil.getVersionString(clientVersion)),
              null));
    }
    return new RjsConnection(address, server);
  }
Example #2
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();
   }
 }