Ahoj vsem mam program v rmi na vypocet integralu.Ale bohužel nedaří se mi
sprovoznit.POtřeboval bych poradit,kde jsou chyby.Děkuji vám za pomoc
package rmiexample;
public interface Evaluatable {
public double evaluate (double valuate);
}
package rmiexample;
public class Integral {
public static double sum(double start, double stop, double stepSize,Evaluatable
evalObj) {
double sum = 0.0, current = start;
while (current <= stop){
sum += evalObj.evaluate(current);
current += stepSize;
}
return(sum);
}
public static double integrate(double start, double stop,int
numSteps,Evaluatable evalObj) {
double step = (stop - start) / (double)numSteps;
start = start + stopSize / 2.0;
return(stepSize * sum(start, stop, stepSize, evalObj));
}
}
package rmiexample;
import java.rmi.*;
public interface RemoteIntegral extends Remote {
public double sum(double start, double stop, double stepSize, Evaluatable
evalObj)
throws RemoteException;
public double integrate(double start,double stop, int numSteps, Evaluatable
evalObj)
throws RemoteException;
}
//sdileni clientem a serverem
package rmiexample;
//
public class RemoteIntegralclient {
public static void main(String[] args) {
try{
String host = (args.length > 0) ? args [0] : "localhost";
RemoteIntegral remoteIntegral = (RemoteIntegral)Naming.lookup("rmi://" + host +
"/RemoteIntegral");
for(int steps=10; steps<=10000; steps*=10) {
System.out.println("Approximated with " + steps + " steps:" +"\n Integral from
0 to pi of sin(x)=" + remoteIntegral.integrate(0.0, Math.PI, steps, new Sin()));
}
System.out.println("'Correct' answer using Math library:" +\n Integral from 0
to pi of sin(x)=" +(-Math.cos(Math.PI) - -Math.cos(0.0)));
}catch(RemoteException re) {
System.out.println("RemoteException: " + re);
}catch(NotBoundException nbe) {
System.out.println("NotBoundException: " + nbe);
}catch("MalformedURLException: " + mfe) {
System.out.println("MalformedURLException: "+ mfe);
}
}
}
package rmiexample;
public class RemoteIntegralClient2 {
public static void main(String[] args) {
try{
System.setSecurityManager(new RMIsecurityManager());
String host = (args.length > 0) ? args [0] : "localhost";
RemoteIntegral remoteIntegral = (RemoteIntegral)Naming.lookup("rmi://" + host +
"/RemoteIntegral");
for(int steps=10; steps<=10000; steps*10=10) {
System.out.println("Approximated with " + steps + " steps:" +"\n Integral from
0 to pi of sin(x)=" + remoteIntegral.integrate(0.0, Math.PI, steps,new Sin()));
}
System.out.println("'Correct' answer using Math library:" +\n Integral from 0
to pi of sin(x)= +(-Math.cos(Math.PI) - -Math.cos(0.0)));
}catch(RemoteException re) {
System.out.println("RemoteException> " + re);
}catch(NotBoundException nbe) {
System.out.println("NotBoundException: " + nbe);
}catch(MalformedURLException: " + mfe){
System("MalformedURLException: + mfe);
}
}
}
package rmiexample;
//remote interal implementation
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class RemoteIntegralImp extends UnicastRemoteObject implements
RemoteIntegral {
public RemoteIntegralImp() throws RemoteException {}
public double sum(double start, double stop, double stepSize,Evaluatable
evaObj) {
return(Integral.sum(start, stop, stepSize, evalObj));
}
public double integrate(double start, double stop, int numSteps,Evaluatable) {
return(Integral.integrate(start, stop, numSteps, evalObj));
}
}
package rmiexample;
//remote integral server
import java.rmi.*;
import java.net.*;
public class RemoteIntegralServer {
public static void main(String[] args) {
try {
RemoteIntegralImpl integral = new RemoteIntegralImpl();
Naming.rebind("rmi:///RemoteIntegral", integral);
}catch(RemoteException re) {
System.out.println("RemoteException : + re);
}catch(MalformedURLException mfe) {
System.out.println("MalformedURLException: " + mfe);
}
}
}
package rmiexample;
//remote integral client
import java.io.Serializable;
class Sin implements Evaluatable, Seriazable {
public double evaluate val) {
retrn(Math.sin(val));
}
public String toString() {
return("Sin")
}
}