package dcj.examples;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
/**
* Source code from "Java Distributed Computing", by Jim Farley.
*
* Class: CORBASolverClient
* Example: 3-9
* Description: A client that uses our CORBA-based Solver interface to interact
* with a remote Solver object.
*/
public class CORBASolverClient {
public static void main(String argv[]) {
try {
// Create an ORB
ORB orb = ORB.init(argv, null);
// Get a reference to the Naming Service
org.omg.CORBA.Object obj =
orb.resolve_initial_references("NameService");
NamingContext nc = NamingContextHelper.narrow(obj);
// Get a reference to the Solver on the remote host
NameComponent comp = new NameComponent("Solver", "");
NameComponent path[] = {comp};
org.omg.CORBA.Object sobj = nc.resolve(path);
Solver solver = SolverHelper.narrow(sobj);
// Make a problem and ask the solver to solve it
ProblemSet s = new ProblemSetImpl();
s.setValue(173.39);
solver.solve(new ProblemSetHolder(s), 1);
// Print out solution
System.out.println("Problem = " + s.getValue());
System.out.println("Solution = " + s.getSolution());
}
catch (Exception e) {
System.out.println(e) ;
e.printStackTrace(System.out);
}
}
} |