Strumenti Utente

Strumenti Sito


lpr-b: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/battitoreasta.txt · Ultima modifica: 07/12/2007 alle 09:55 (17 anni fa) da Marco Danelutto