Advertisement
amine99

Untitled

Feb 3rd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. //Interface Barriére
  2.  
  3. package barriere;
  4. import java.rmi.Remote;
  5. import java.rmi.RemoteException;
  6.  
  7. public interface BarriereInt extends Remote {
  8.     boolean entre() throws RemoteException;
  9.     boolean sortir(int t) throws RemoteException;
  10. }
  11.  
  12.  
  13. //Impelemation Barriére
  14. package barriere;
  15.  
  16. import java.rmi.Naming;
  17. import java.rmi.RemoteException;
  18. import java.rmi.registry.LocateRegistry;
  19. import java.rmi.server.UnicastRemoteObject;
  20.  
  21. import parc.ParcInt;
  22.  
  23. public class Barriere extends UnicastRemoteObject implements BarriereInt {
  24.     private static int ticket= 0;
  25.    
  26.     public Barriere() throws RemoteException {
  27.         super();
  28.     }
  29.    
  30.     private boolean paid(int t) {
  31.         return true;
  32.     }
  33.    
  34.     @Override
  35.     public boolean entre() throws RemoteException {
  36.         try {
  37.             ParcInt p = (ParcInt)Naming.lookup("rmi://localhost/parc");
  38.             if(p.nbPlacesLibres() > 0) {
  39.                 ticket++;
  40.                 p.entreeVisiteur();
  41.                 return true;
  42.             } else {
  43.                 return false;
  44.             }
  45.         } catch (Exception e) {
  46.             System.out.println(e.toString());
  47.         }
  48.         return false;
  49.     }
  50.  
  51.     @Override
  52.     public boolean sortir(int t) throws RemoteException {
  53.         try {
  54.             ParcInt p = (ParcInt)Naming.lookup("rmi://localhost/parc");
  55.             if(paid(t)) {
  56.                 p.sortieVisiteur();
  57.                 return true;
  58.             } else {
  59.                 return false;
  60.             }
  61.         } catch (Exception e) {
  62.             System.out.println(e.toString());
  63.         }
  64.         return false;
  65.     }
  66.  
  67.     public int getTicket() {
  68.         return ticket;
  69.     }
  70.    
  71.     public static void main(String [] args) {
  72.         try {
  73.             Barriere b = new Barriere();
  74.             Naming.rebind("rmi://localhost/barriere", b);
  75.         } catch (Exception e) {
  76.             System.out.println(e.toString());
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement