package astaRMI; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import java.util.HashMap; import java.util.Iterator; public class Battitore extends UnicastRemoteObject implements InterfacciaBattitore { protected Battitore() throws RemoteException { super(); } private static final long serialVersionUID = -8624867101274666805L; int offertaCorrente = 0; String vincitore = ""; HashMap clienti = new HashMap(); public synchronized int offer(String name, int howMuch) throws RemoteException { System.out.println("Ricevuta offerta "+howMuch+" da "+name); if(howMuch > offertaCorrente) { offertaCorrente = howMuch; vincitore = name; System.out.println("Il vincitore ora รจ "+vincitore+" che ha offerto "+offertaCorrente); Iterator it = clienti.values().iterator(); while(it.hasNext()) { ClientInterface ci = (ClientInterface) it.next(); ci.offer(offertaCorrente); } } return offertaCorrente; } public void register(String name, ClientInterface cif) throws RemoteException { System.out.println("Registrato "+name); clienti.put(name, cif); return; } }