Advertisement
amine99

Untitled

Feb 3rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. //Interface Parc
  2.  
  3. package parc;
  4. import java.rmi.Remote;
  5. import java.rmi.RemoteException;
  6.  
  7. public interface ParcInt extends Remote {
  8.     public int nbPlacesLibres() throws RemoteException;
  9.     public void entreeVisiteur() throws RemoteException;
  10.     public void sortieVisiteur() throws RemoteException;
  11. }
  12.  
  13.  
  14. //Implementation Parc
  15. package parc;
  16.  
  17. import java.rmi.RemoteException;
  18. import java.rmi.server.UnicastRemoteObject;
  19.  
  20. public class Parc extends UnicastRemoteObject implements ParcInt {
  21.  
  22.     private int places = 200;
  23.    
  24.     public Parc() throws RemoteException {
  25.         super();
  26.     }
  27.     @Override
  28.     public int nbPlacesLibres() throws RemoteException {
  29.         return places;
  30.     }
  31.     @Override
  32.     public void entreeVisiteur() throws RemoteException {
  33.         places--;
  34.     }
  35.     @Override
  36.     public void sortieVisiteur() throws RemoteException {
  37.         if(places < 200) places++;
  38.     }
  39.    
  40. }
  41.  
  42.  
  43. //Serveur Parc
  44.  
  45. package parc;
  46.  
  47. import java.rmi.Naming;
  48. import java.rmi.registry.LocateRegistry;
  49.  
  50. public class ParcServer {
  51.     public static void main(String[] args) {
  52.         try {
  53.             Parc p = new Parc();
  54.             LocateRegistry.createRegistry(1099);
  55.             Naming.rebind("rmi://localhost/parc", p);
  56.         } catch (Exception e) {
  57.             System.out.println(e.toString());
  58.         }
  59.        
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement