import java.rmi.RemoteException; import java.util.Vector; import net.jini.core.lease.LeaseDeniedException; import net.jini.core.lookup.ServiceRegistrar; import net.jini.core.lookup.ServiceTemplate; import net.jini.core.transaction.server.TransactionManager; import net.jini.core.transaction.server.TransactionManager.Created; public class Urne { TransactionManager manager; Created leasedTransaction; public Urne(ServiceRegistrar registrar) throws RemoteException { Class[] txService = { TransactionManager.class }; ServiceTemplate template = new ServiceTemplate(null, txService, null); manager = (TransactionManager) registrar.lookup(template); if (manager == null) { System.out.println("Impossible de trouver TransactionManager"); System.exit(0); } try { leasedTransaction = manager.create(1000 * 60 * 2); System.out.println("Dépouillement 1: 4 voix pour le oui."); manager.join(leasedTransaction.id, new Oui(), 0); manager.join(leasedTransaction.id, new Oui(), 0); manager.join(leasedTransaction.id, new Oui(), 0); manager.join(leasedTransaction.id, new Oui(), 0); manager.commit(leasedTransaction.id); System.out.println("Vote à l'unanimité."); System.out.println("Dépouillement 2: 3 voix pour oui et une pour non"); manager.join(leasedTransaction.id, new Oui(), 0); manager.join(leasedTransaction.id, new Oui(), 0); manager.join(leasedTransaction.id, new Non(), 0); manager.join(leasedTransaction.id, new Oui(), 0); manager.commit(leasedTransaction.id); } catch (Exception e) { System.out.println("Vote divisé."); } } }