Example #1
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;
 }
  public static void main(String[] args) {
    String host = args[0];
    int port = Integer.parseInt(args[1]);

    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new RMISecurityManager());
    }

    String name = "//" + host + ":" + port + "/EquationSolver";

    double[][] A = {
      {4.0, 3.0, 1.0},
      {2.0, -6.0, 4.0},
      {7.0, 5.0, 3.0}
    };
    double[] b = {17.0, 8.0, 32.0};

    try {
      EquationSolver solver = (EquationSolver) Naming.lookup(name);
      double[] x = solver.solve(A, b);

      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < x.length; i++) {
        sb.append(x[i]);
        sb.append(' ');
      }
      System.out.println(sb);

    } catch (RemoteException ex) {
      ex.printStackTrace(System.err);

    } catch (NotBoundException ex) {
      ex.printStackTrace(System.err);

    } catch (MalformedURLException ex) {
      ex.printStackTrace(System.err);
    }
  }