Ich versuche grade RMI zu lernen über ein ProxyPattern.
Ich verstehe den Fehler nicht .
Vielen Dank für eure Bemühungen im Voraus.
Client.java
Server.java
ParkhausService.java
ParkhausServiceImpl.java
ParkhausServiceProxy.java
Ich verstehe den Fehler nicht .
Vielen Dank für eure Bemühungen im Voraus.
Code:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: client.ParkhausServiceImpl
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at client.Client.main(Client.java:24)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: client.ParkhausServiceImpl
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
... 2 more
Caused by: java.io.NotSerializableException: client.ParkhausServiceImpl
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
BUILD SUCCESSFUL (total time: 0 seconds)
Client.java
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import java.net.*;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Client {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry();
ParkhausService service = (ParkhausService) registry.lookup("serviceDienst");
service.in(5);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Server.java
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import java.lang.reflect.InvocationTargetException;
import java.net.*;
import java.io.*;
import java.lang.reflect.Method;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Server {
static int plaetze = 5;
static int check = 100;
public static void main(String[] args) throws IOException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException {
Thread server = new Thread() {
public void run() {
try {
ParkhausService service = new ParkhausServiceImpl();
Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
registry.bind("serviceDienst", service);
Thread.sleep(10000);
registry.unbind("serviceDienst");
} catch (Exception e) {
e.printStackTrace();
}
}
};
server.start();
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
ParkhausService.java
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import java.net.*;
import java.io.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
*
* @author Markus admin
*/
public interface ParkhausService extends Remote {
public void in(int anzahl) throws RemoteException;
public void out(int anzahl) throws RemoteException;
public void free(int anzahl) throws RemoteException;
}
ParkhausServiceImpl.java
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
*
* @author chris
*/
@SuppressWarnings("serial")
public class ParkhausServiceImpl implements ParkhausService {
@Override
public void in(int anzahl) throws RemoteException{
if (Server.plaetze - anzahl < 0) {
Server.check = 0;
System.out.println("fail");
} else {
Server.check = 100;
Server.plaetze = Server.plaetze - anzahl;
System.out.println("Anzahl von Fahrzeugen, die reingefahren sind: " + anzahl);
System.out.println("Die Anzahl von freien Plätzen beträgt: " + Server.plaetze);
}
}
@Override
public void out(int anzahl) throws RemoteException{
if (Server.plaetze + anzahl > 5) {
Server.check = 0;
System.out.println("fail");
} else {
Server.check = 100;
Server.plaetze = Server.plaetze + anzahl;
System.out.println("Anzahl von Fahrzeugen, die rausngefahren sind: " + anzahl);
System.out.println("Die Anzahl von freien Plätzen beträgt: " + Server.plaetze);
}
}
@Override
public void free(int anzahl) throws RemoteException{
System.out.println("Die Anzahl von freien Plätzen beträgt: " + Server.plaetze);
}
}
ParkhausServiceProxy.java
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import java.rmi.RemoteException;
/**
*
* @author chris
*/
public class ParkhausServiceProxy implements ParkhausService{
private ParkhausServiceImpl _parkhausServiceImpl = new ParkhausServiceImpl();
@Override
public void in(int anzahl) throws RemoteException {
_parkhausServiceImpl.in(anzahl);
}
@Override
public void out(int anzahl) throws RemoteException{
_parkhausServiceImpl.out(anzahl);
}
@Override
public void free(int anzahl) throws RemoteException {
_parkhausServiceImpl.free(anzahl);
}
}
Zuletzt bearbeitet: