edu.pdx.cs.joy.rmi.EquationSolverImpl Maven / Gradle / Ivy
The newest version!
package edu.pdx.cs.joy.rmi;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
/**
* Instances of this remote class reside in a server JVM and perform
* the work of solving an equation of the form Ax = b
.
*/
public class EquationSolverImpl extends UnicastRemoteObject
implements EquationSolver {
/**
* Creates a new EquationSolverImpl
. Invokes
* UnicastRemoteObject's
constructor to register this
* object with the RMI runtime.
*/
public EquationSolverImpl() throws RemoteException {
super();
}
/**
* Use Cholesky's algorithm to solve a linear system of equations of
* the Ax = b
.
*
* @param matrix
* The A
in Ax = b
* @param constants
* The b
in Ax = b
*
* @throws IllegalArgumentException
* The number of rows and columns in the matrix are not the
* same
* @throws RemoteException
* Something went wrong while communicating with the server
*/
public double[] solve(double[][] matrix, double[] constants)
throws RemoteException {
return GaussianElimination.solve(matrix, constants);
}
/**
* Main program that creates a new EquationSolverImpl
* and binds it into the RMI registry under a given name.
*/
public static void main(String[] args) {
String host = args[0];
int port = Integer.parseInt(args[1]);
// Install an RMISecurityManager, if there is not a
// SecurityManager already installed
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
String name = "//" + host + ":" + port + "/EquationSolver";
try {
Remote solver = new EquationSolverImpl();
Naming.rebind(name, solver);
} catch (RemoteException ex) {
ex.printStackTrace(System.err);
} catch (MalformedURLException ex) {
ex.printStackTrace(System.err);
}
}
}