FileDocCategorySizeDatePackage
RMISolverClient.javaAPI DocExample1683Sun Jan 11 17:37:12 GMT 1998dcj.examples.rmi

RMISolverClient

public class RMISolverClient extends Object
Source code from "Java Distributed Computing", by Jim Farley. Class: RMISolverClient Example: 3-14 Description: A client class that uses the RMI-based Solver and ProblemSet interfaces to interact with a remote Solver.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

    // Install a security manager that can handle remote stubs
    System.setSecurityManager(new RMISecurityManager());

    // Get a remote reference to the RMISolver class
    String name = "TheSolver";
    System.out.println("Looking up " + name + "...");
    RMISolver solver = null;
    try {
      solver = (RMISolver)Naming.lookup(name);
    }
    catch (Exception e) {
      System.out.println("Caught an exception looking up Solver.");
      System.exit(1);
    }

    // Make a problem set for the solver
    RMIProblemSetImpl s = null;

    try {
      s = new RMIProblemSetImpl();
      s.setValue(Double.valueOf(argv[0]).doubleValue());
    }
    catch (Exception e) {
      System.out.println("Caught exception initializing problem.");
      e.printStackTrace();
    }

    // Ask solver to solve
    try {
      if (solver.solve(s, 1)) {
        System.out.println("Solver returned solution: " +
                           s.getSolution());
      }
      else {
        System.out.println(
          "Solver was unable to solve problem with value = " +
          s.getValue());
      }
    }
    catch (RemoteException e) {
      System.out.println("Caught remote exception.");
      System.exit(1);
    }