FileDocCategorySizeDatePackage
CORBASolverImpl.javaAPI DocExample2996Sun Jan 11 17:28:44 GMT 1998DCJ.examples

CORBASolverImpl

public class CORBASolverImpl extends _SolverImplBase
Source code from "Java Distributed Computing", by Jim Farley. Class: CORBASolverImpl Example: 3-7 Description: Server implementation of the Solver Java interface generated by idltojava from the IDL interface from Ex. 3-4.

Fields Summary
protected int
numIterations
protected ProblemSetHolder
currProblem
Constructors Summary
public CORBASolverImpl()


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

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

    return numIterations;
  
public ProblemSetgetProblem()

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


    try {
      // create and initialize the ORB
      System.out.println("Initializing ORB...");
      ORB orb = ORB.init(argv, null);

      // Create a Solver and register it with the ORB
      System.out.println("Connecting solver to ORB...");
      CORBASolverImpl solver = new CORBASolverImpl();
      orb.connect(solver);

      // Get the naming service from the ORB
      System.out.println("Getting reference to Naming Service...");
      org.omg.CORBA.Object ncObj =
        orb.resolve_initial_references("NameService");
      NamingContext ncRef = NamingContextHelper.narrow(ncObj);

      // Bind the Solver object to a name
      System.out.println("Registering Solver with Naming Service...");
      NameComponent comp = new NameComponent("Solver", "");
      NameComponent path[] = {comp};
      ncRef.rebind(path, solver);

      // Wait for client requests
      System.out.println("Waiting for clients...");
      java.lang.Object dummySync = new java.lang.Object();
      synchronized (dummySync) {
        dummySync.wait();
      }
    }
    catch (Exception e) {
      System.err.println(e);
      e.printStackTrace(System.out);
    }
  
public voidsetNumIterations(int i)

    numIterations = i;
  
public voidsetProblem(ProblemSetHolder ph)

    currProblem = ph;
  
public booleansolve(ProblemSetHolder sh, int numIters)

    ProblemSet s = sh.value;
    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;
  
public booleansolveCurrent()

    System.out.println("Solving current problem...");
    return solve(currProblem, numIterations);