creato rmi counter. verifica blanda di errori di input

This commit is contained in:
2014-11-17 00:46:26 +01:00
parent bc03a1f378
commit f17671da1c
11 changed files with 259 additions and 8 deletions

View File

@@ -0,0 +1,64 @@
package rmi_counter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Logger;
/**
* Created by Giovanni on 16/11/2014.
*/
public class LaunchClient {
private static Logger l =Logger.getLogger("counterclientlogger");
public static void main (String args[]) {
try {
CounterInterface rc = (CounterInterface) Naming.lookup("rmi://localhost/Counter");
BufferedReader i = new BufferedReader(new InputStreamReader(System.in));
while (true) {
l.info("Commands:current,sum <value>,any other to quit");
String command = LaunchClient.cmd(i);
l.info(command);
if (command.equals("current")) {
l.info(rc.getvalue("Client1") + "");
} else if ( command.length()>=3 && command.substring(0,3).equals("sum")) {
int value = Integer.parseInt(command.substring(4));
l.info(String.valueOf(rc.sum( "Client1",value )));
} else {
l.info("quitting");
break;
}
}
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
}
}
public static String cmd (BufferedReader i ){
try {
String input = i.readLine();
return input;
} catch (IOException e) {
}
return "";
}
}