Example #1
0
 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;
   }
 }
  /**
   * Returns the Registry on the local machine on port IRMI_Defs.REGISTRY_PORT, as a server would
   * require. Creates the Registry if it isn't already running. Returns null system if unable to
   * create a Registry if needed.
   *
   * @return the Registry or null if no Registry could be made or found.
   */
  @Override
  public Registry getLocalRegistry() {

    try {
      // First try to create a registry
      return LocateRegistry.createRegistry(IRMI_Defs.REGISTRY_PORT);
    } catch (RemoteException e) {
      outputCmd.apply(
          "Could not create registry: " + e + "\n", "Attempting to locate existing registry...");
      try {
        // Creating a new registry will fail if it already exists, so
        // try to find it.
        Registry registry = LocateRegistry.getRegistry(IRMI_Defs.REGISTRY_PORT);
        outputCmd.apply("RMIUtils.getLocalRegistry: Success! Found Registry: " + registry);
        return registry;
      } catch (RemoteException e2) {
        outputCmd.apply(
            "RMIUtils.getLocalRegistry: Could not get registry on port "
                + IRMI_Defs.REGISTRY_PORT
                + ". \n"
                + e);
        return null;
      }
    }
  }
Example #3
0
  public SetupDataClient() throws RemoteException {

    try {
      // get the registry
      registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());
      // look up the remote object
      rmiServer = (databaseinter) registry.lookup("Database");

      rmiServer.receiveMessage("abc");
      // starting time
      long time1 = System.currentTimeMillis();
      // call the remote method

      System.out.println("sending " + text + " to " + serverAddress + ":" + serverPort);
      // receiving time
      long time2 = System.currentTimeMillis();
      long timedelay = time2 - time1;
      System.out.println("RMI delay time: " + timedelay);
      // converting process

      // finish converting
      long time3 = System.currentTimeMillis();
      long timefinish = time3 - time1;
      System.out.println("Total time: " + timefinish);
    } catch (NotBoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("File not found");
      System.out.println(e.getMessage());
      e.printStackTrace();
    }
  }
Example #4
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;
 }
  /**
   * Returns the Registry on the given machine on port IRMI_Defs.REGISTRY_PORT, as a client would
   * require.
   *
   * @param host the IP address or host name of the remote machine.
   * @return The remote Registry or null if it could not be located.
   */
  @Override
  public Registry getRemoteRegistry(String host) {

    try {
      Registry registry = LocateRegistry.getRegistry(host, IRMI_Defs.REGISTRY_PORT);
      outputCmd.apply("RMIUtils.getRemoteRegistry: Success! Found Registry: " + registry);
      return registry;
    } catch (RemoteException e) {
      outputCmd.apply(
          "RMIUtils.getRemoteRegistry: Could not get registry at "
              + host
              + ":"
              + IRMI_Defs.REGISTRY_PORT
              + ". \n"
              + e);
      return null;
    }
  }
  public ArrayList<KeyValueServerInterface> getServersList() throws RemoteException {
    //
    ArrayList<KeyValueServerInterface> res = new ArrayList();

    try {
      Registry registry = LocateRegistry.getRegistry();
      String[] name = registry.list();
      for (String str : name) {

        // if( str.equals(server_name) ) continue;

        KeyValueServerInterface obj = (KeyValueServerInterface) registry.lookup(str);
        res.add(obj);
      }

    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return res;
  }
  public static void main(String args[]) {

    /*
     * Create and install a security manager
     */
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new SecurityManager());
    }

    try {
      Registry registry = LocateRegistry.getRegistry(2002);
      Hello obj = (Hello) registry.lookup("Hello");
      String message = obj.sayHello();
      System.out.println(message);

    } catch (Exception e) {
      System.out.println("HelloClient exception: " + e.getMessage());
      e.printStackTrace();
    }
  }