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,45 @@
package rmi_counter;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Enumeration;
import java.util.Vector;
import java.util.logging.Logger;
/**
* Created by Giovanni on 16/11/2014.
*/
public class RemoteCounter extends LocalCounter implements CounterInterface {
private static Logger l = Logger.getLogger("RemoteCounter");
public RemoteCounter( int in) throws RemoteException{
super(in);
UnicastRemoteObject.exportObject(this,5000);
accesses = new Vector<String>();
}
@Override
public synchronized int getvalue(String from) throws RemoteException {
accesses.add("Access from " + from + " value " + getlocalvalue());
return getlocalvalue();
}
@Override
public synchronized int sum(String from, int value) throws RemoteException {
accesses.add("Access from " + from + " value to add " + value);
for (int i = 0;i < value ;i++)
increment();
return getlocalvalue();
}
public String getaccesses (){
String returned = "";
for (Enumeration<String> e = accesses.elements(); e.hasMoreElements() ;)
returned+="\n" + e.nextElement();
return returned;
}
Vector<String> accesses;
}