Strumenti Utente

Strumenti Sito


lpr-b-2007-2008:battitoreasta
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<String,ClientInterface> clienti = new HashMap<String,ClientInterface>();
 
	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<ClientInterface> 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;
	}
 
}
lpr-b-2007-2008/battitoreasta.txt · Ultima modifica: 19/09/2008 alle 14:08 (16 anni fa) (modifica esterna)