Hallo,
ich habe folgendes Programm
Mit dem rmic-Tool soll ich mit folgendem Befehl
Zwei weitere class-Dateien erzeugen, die BefragungImpl_Skel.class und BefragungImpl_Stub.class, es wird aber nur BefragungImpl_Stub.class erzeugt, warum?:bahnhof: Mache ich etwas falsch ?:bahnhof:
ich habe folgendes Programm
Java:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Befragung extends Remote{
public Frage getFrage() throws RemoteException;
public void putAntwort(int antwort) throws RemoteException;
}
Java:
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
public class BefragungImpl extends UnicastRemoteObject implements Befragung{
private static final long serialVersionUID = 1L;
private String frageString="";
private int antwortBereich=0;
private int tnZahl=0;
private double antwortAv=0.0;
public BefragungImpl(String frageString, int antwortBereich) throws RemoteException {
this.frageString=frageString;
this.antwortBereich=antwortBereich;
}
public Frage getFrage()throws RemoteException{
return new Frage(frageString, antwortBereich, tnZahl, antwortAv);
}
public void putAntwort(int antwort)throws RemoteException{
antwortAv=(antwortAv*tnZahl+antwort)/(++tnZahl);
System.out.println("\t"+tnZahl+" Teilnehmer\t"+antwortAv+"\t Antwortdurchschnitt");
}
public static void main (String [] args){
if(args.length==2){
BefragungImpl bef;
try{
LocateRegistry.createRegistry(1099);
int range=0;
try{
range=Integer.parseInt(args[1]);
}catch(Exception e){}
bef=new BefragungImpl(args[0], range);
Naming.bind("RMI-Befragung", bef);
System.out.println("\n*** Bereit fuer RMI's ***\n");
}catch(java.rmi.AlreadyBoundException abEx){
System.out.println("BefragungImpl: "+abEx.toString());
}catch(java.net.MalformedURLException malUrlEx){
System.out.println("BefragungImpl: "+malUrlEx.toString());
}catch(RemoteException remEx){
System.out.println("BefragungImpl: "+remEx.toString());
}
}else{
System.out.println("BefragungImpl: "+"\n\tAufruf mit einem Frage-String in \"...\""+"\n\tund einer Zahl fuer den Antwortbereich");
}
}
}
Java:
public class Frage extends Object implements java.io.Serializable{
private static final long serialVersionUID = 1L;
private String frageString;
private int antwortBereich;
private int tnZahl;
private double antwortAv;
public String getFrageString(){
return frageString;
}
public int getAntwortBereich(){
return antwortBereich;
}
public int getTnZahl(){
return tnZahl;
}
public double getAntwortAv(){
return antwortAv;
}
public Frage(){}
public Frage(String frageString, int antwortBereich, int tnZahl, double antwortAv){
this.frageString=frageString;
this.antwortBereich=antwortBereich;
this.tnZahl=tnZahl;
this.antwortAv=antwortAv;
}
}
Java:
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.rmi.Naming;
import java.rmi.RemoteException;
public class FrageClient {
Frage frage;
Befragung remoteObject;
StringBuffer strBuffer;
String antwort;
public FrageClient(){}
public static void main(String[] args) {
FrageClient client=new FrageClient();
client.execute();
}
private void execute() {
try {
remoteObject=(Befragung) Naming.lookup("rmi://127.0.0.1:1099/RMI-Befragung");
frage=remoteObject.getFrage();
System.out.println("Die Frage des remote-Objectes:\n");
System.out.println(frage.getFrageString()+"\n");
System.out.println("Ihre Antwort. Moeglichkeiten von 0 bis "+frage.getAntwortBereich()+": \n");
} catch (java.rmi.NotBoundException nbEx) {
System.out.println("FrageClient: "+nbEx.toString());
}catch (java.net.MalformedURLException malUrlEx) {
System.out.println("FrageClient: "+malUrlEx.toString());
}catch (RemoteException remEx) {
System.out.println("FrageClient: "+remEx.toString());
}
boolean schleife=true;
int iAntwort=0;
while(schleife){
if((antwort=konsolenDaten()) !=null){
try{
iAntwort=Integer.parseInt(antwort);
if(iAntwort<=frage.getAntwortBereich()&& iAntwort>=0){
try{
remoteObject.putAntwort(iAntwort);
double tnAvneu=(frage.getAntwortAv()*frage.getTnZahl()+iAntwort)/(frage.getTnZahl()+1);
System.out.println("Durchschnitt "+tnAvneu+" bei "+(frage.getTnZahl()+1+" Teilnehmern"));
schleife=false;
}catch(RemoteException remEx){
System.out.println("BefragungImpl: "+remEx.toString());
schleife=false;
}
}else
System.out.println("Die Zahl liegt nicht "+"im gueltigen bereich, bitte noch einmal:");
}catch(NumberFormatException nfEx){
System.out.println("BefragungImpl: "+nfEx.toString());
System.out.println("\nUngueltige Eingabe: Es muss eine Zahl eingegeben werden. Bitte noch einmal:");
}
}else System.out.println("Fehler ");
}
}
public String konsolenDaten(){
strBuffer=new StringBuffer();
char ch;
try{
Reader in=new InputStreamReader(System.in);
while((ch=(char)in.read())!='\r'){
strBuffer.append(ch);
}
System.out.println("Eingegeben: "+strBuffer.toString());
return strBuffer.toString();
}catch(IOException ioe){
System.out.println("BefragungImpl: "+ioe.toString());
return null;
}
}
}
Mit dem rmic-Tool soll ich mit folgendem Befehl
Code:
rmic BefragungImpl