Здравствуйте.
Начну с кода:
EquationI:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
package kazakevich;
import java.rmi.Remote;
import java.rmi.RemoteException;
/** Implementing this interface allows you to obtain access to solve an equation.
* @version 1.0
* @author Kirill Kazakevich
*/
public interface EquationI extends Remote{
/**
* @param function function that imlements interface FunctionI
* @param a begin of a segment
* @param b end of a segment
* @param eps fault
* @return root of an equation
* @throws RemoteException
*/
double solve(FunctionI function, double a, double b, double eps) throws RemoteException;
}
EquationServer:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
package kazakevich;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
/**
* Server.
* Server waits for clients to solve an equation and returns a solution.
* @version 1.0
* @author Kirill Kazakevich
*/
public class EquationServer extends UnicastRemoteObject implements EquationI{
public EquationServer() throws RemoteException{
}
public double solve(FunctionI function, double a, double b, double eps) throws RemoteException{
double m = (a + b) / 2 ;
double fa = function.f(a);
double fm = function.f(m);
double product = fa * fm;
if ((b - a) <= eps || product == 0 ){
BigDecimal epss = new BigDecimal(eps);
System.out.println(epss.scale());
return m;
}
return product < 0 ? solve(function, a, m, eps) : solve(function, m, b, eps);
}
/**
* @param args
* @throws RemoteException
* @throws MalformedURLException
*/
public static void main(String[] args) throws RemoteException, MalformedURLException{
System.setSecurityManager( new RMISecurityManager());
EquationServer server = new EquationServer();
LocateRegistry.createRegistry( 1099 );
Naming.rebind("EServer", server);
System.out.println("Server is waiting for clients.");
}
}
EquationClient:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
package kazakevich;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
/**
* Client.
* Client connects to server to solve an equation.
* @version 1.0
* @author Kirill Kazakevich
*/
public class EquationClient{
/**
* @param args
* @throws NotBoundException
* @throws MalformedURLException
* @throws RemoteException
*/
public static void main(String[] args) throws NotBoundException, MalformedURLException, RemoteException{
System.setSecurityManager( new RMISecurityManager());
FuncA a = new FuncA();
EquationI server = (EquationI)Naming.lookup("EServer");
System.out.println("The root of an equation is " + server.solve(a, 1 . 0 , 1 . 7 , 0 . 01 ));
}
}
FunctionI
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
package kazakevich;
/**
* Implementing this interface allows you to store a formula of f(<i>x</i>)
* @version 1.0
* @author Kirill Kazakevich
*/
public interface FunctionI{
/** Calculate f(<i>x</i>).
* @param x <i>x</i>
* @return f(<i>x</i>)
*/
double f( double x);
}
FuncA
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
package kazakevich;
import java.io.Serializable;
/** Class stores formula of equation <code>x<sup>4</sup> - 2x - 4</code>.
* @version 1.0
* @author Kirill Kazakevich
*/
public class FuncA implements FunctionI, Serializable{
public double f( double x){
double result = Math.pow(x, 4 ) - 2 *x - 4 ;
return result;
}
}
Программа вычисляет на сервере в методе solve корень уравнения f(x)=0 методом деления отрезка пополам. В метод solve передается ссылка на интерфейс FunctionI, реализация FuncA которого должна хранится у клиента, но если у сервера нету этого класса, то выдается исключение:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
Exception in thread main
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: kazakevich.FuncA
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java: 325 )
at sun.rmi.transport.Transport$ 1 .run(Transport.java: 154 )
at java.security.AccessController.doPrivileged( Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java: 149 )
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java: 460 )
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java: 701 )
at java.lang.Thread.run(Thread.java: 595 )
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java: 247 )
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java: 223 )
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java: 126 )
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java: 179 )
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java: 132 )
at $Proxy0.solve(Unknown Source)
at kazakevich.EquationClient.main(EquationClient.java: 29 )
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: kazakevich.FuncA
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java: 285 )
at sun.rmi.transport.Transport$ 1 .run(Transport.java: 154 )
at java.security.AccessController.doPrivileged( Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java: 149 )
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java: 460 )
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java: 701 )
at java.lang.Thread.run(Thread.java: 595 )
Caused by: java.lang.ClassNotFoundException: kazakevich.FuncA
at java.net.URLClassLoader$ 1 .run(URLClassLoader.java: 200 )
at java.security.AccessController.doPrivileged( Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java: 188 )
at java.lang.ClassLoader.loadClass(ClassLoader.java: 306 )
at java.lang.ClassLoader.loadClass(ClassLoader.java: 251 )
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java: 319 )
at java.lang. Class .forName0( Native Method)
at java.lang. Class .forName( Class .java: 242 )
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java: 430 )
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java: 165 )
at java.rmi.server.RMIClassLoader$ 2 .loadClass(RMIClassLoader.java: 620 )
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java: 247 )
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java: 197 )
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java: 1538 )
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java: 1460 )
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java: 1693 )
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java: 1299 )
at java.io.ObjectInputStream.readObject(ObjectInputStream.java: 339 )
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java: 290 )
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java: 279 )
... 6 more
Перепробовал уже кучу всего :( Может надо в java.policy что-нибудь прописать? Прописано только SocketPermission.
На всякий случай код в архиве.