Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Interface Barriére
- package barriere;
- import java.rmi.Remote;
- import java.rmi.RemoteException;
- public interface BarriereInt extends Remote {
- boolean entre() throws RemoteException;
- boolean sortir(int t) throws RemoteException;
- }
- //Impelemation Barriére
- package barriere;
- import java.rmi.Naming;
- import java.rmi.RemoteException;
- import java.rmi.registry.LocateRegistry;
- import java.rmi.server.UnicastRemoteObject;
- import parc.ParcInt;
- public class Barriere extends UnicastRemoteObject implements BarriereInt {
- private static int ticket= 0;
- public Barriere() throws RemoteException {
- super();
- }
- private boolean paid(int t) {
- return true;
- }
- @Override
- public boolean entre() throws RemoteException {
- try {
- ParcInt p = (ParcInt)Naming.lookup("rmi://localhost/parc");
- if(p.nbPlacesLibres() > 0) {
- ticket++;
- p.entreeVisiteur();
- return true;
- } else {
- return false;
- }
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- return false;
- }
- @Override
- public boolean sortir(int t) throws RemoteException {
- try {
- ParcInt p = (ParcInt)Naming.lookup("rmi://localhost/parc");
- if(paid(t)) {
- p.sortieVisiteur();
- return true;
- } else {
- return false;
- }
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- return false;
- }
- public int getTicket() {
- return ticket;
- }
- public static void main(String [] args) {
- try {
- Barriere b = new Barriere();
- Naming.rebind("rmi://localhost/barriere", b);
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement