FileDocCategorySizeDatePackage
RMISolverImpl.javaAPI DocExample2507Sun Feb 01 14:52:56 GMT 1998dcj.examples.rmi

RMISolverImpl

public class RMISolverImpl extends UnicastRemoteObject implements RMISolver
Source code from "Java Distributed Computing", by Jim Farley. Class: RMISolverImpl Example: 3-12 Description: The server implementation of the RMI-based Solver.

Fields Summary
protected int
numIterations
protected RMIProblemSet
currProblem
Constructors Summary
public RMISolverImpl()


  // Constructors
       super(); 
public RMISolverImpl(int numIter)

    super();
    numIterations = numIter;
  
Methods Summary
public intgetIterations()

    return numIterations;
  
public RMIProblemSetgetProblem()

    return currProblem;
  
public static voidmain(java.lang.String[] argv)

    try {
      // Register an instance of RMISolverImpl with the
      // RMI Naming service
      String name = "TheSolver";
      System.out.println("Registering RMISolverImpl as \""
                         + name + "\"");
      RMISolverImpl solver = new RMISolverImpl();
      Naming.rebind(name, solver);
      System.out.println("Remote Solver ready...");
    }
    catch (Exception e) {
      System.out.println("Caught exception while registering: "
                         + e);
    }
  
public booleansetIterations(int numIter)

    numIterations = numIter;
    return true;
  
public booleansetProblem(RMIProblemSet s)

    currProblem = s;
    return true;
  
public booleansolve()

    System.out.println("Solving current problem...");
    return solve(currProblem, numIterations);
  
public booleansolve(RMIProblemSet s, int numIters)

    boolean success = true;

    if (s == null) {
      System.out.println("No problem to solve.");
      return false;
    }

    System.out.println("Problem value = " + s.getValue());

    // Solve problem here...
    try {
      s.setSolution(Math.sqrt(s.getValue()));
    }
    catch (ArithmeticException e) {
      System.out.println("Badly-formed problem.");
      success = false;
    }

    System.out.println("Problem solution = " + s.getSolution());

    return success;