MàJ par récupération sur Clé USB et dans /mnt/hd/Chargement du pc portable
This commit is contained in:
BIN
A61/Anneau/NOEUD.class
Normal file
BIN
A61/Anneau/NOEUD.class
Normal file
Binary file not shown.
33
A61/Anneau/NOEUD.java
Normal file
33
A61/Anneau/NOEUD.java
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Smea
|
||||
*/
|
||||
public interface NOEUD extends java.rmi.Remote {
|
||||
|
||||
public NOEUD ConnectSuivant() throws java.rmi.RemoteException;
|
||||
|
||||
public NOEUD GetTonSuivant() throws java.rmi.RemoteException;
|
||||
|
||||
public String GetInfo() throws java.rmi.RemoteException;
|
||||
|
||||
public void SetTonSuivant(NOEUD n) throws java.rmi.RemoteException;
|
||||
|
||||
public void CloseSite(NOEUD n) throws java.rmi.RemoteException;
|
||||
|
||||
public void Numerote(int n) throws java.rmi.RemoteException;
|
||||
|
||||
public void KillSite(int n) throws java.rmi.RemoteException;
|
||||
|
||||
public void Election(int capaciteInit,
|
||||
int capaciteGagnante,
|
||||
int siteGagnant,
|
||||
int siteInitiateur) throws java.rmi.RemoteException;
|
||||
|
||||
public void ProclamationElection(int siteGagnant, int siteInitiateur) throws java.rmi.RemoteException;
|
||||
|
||||
}
|
256
A61/Anneau/NOEUDImpl.java
Normal file
256
A61/Anneau/NOEUDImpl.java
Normal file
@ -0,0 +1,256 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.*;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Smea
|
||||
*/
|
||||
|
||||
|
||||
public class NOEUDImpl extends UnicastRemoteObject implements NOEUD, Serializable{
|
||||
public NOEUD suivant = null;
|
||||
public String nom = "";
|
||||
public String rmi = "";
|
||||
public int numero = 0;
|
||||
public int survivance = 0;
|
||||
|
||||
public NOEUDImpl(String n, String r) throws RemoteException {
|
||||
this.nom = n;
|
||||
this.rmi = r;
|
||||
if(n.equals("INIT")) {
|
||||
this.numero = 1;
|
||||
this.survivance = (int)(Math.random()*1024)+1;
|
||||
}
|
||||
}
|
||||
|
||||
public NOEUD ConnectSuivant() throws RemoteException {
|
||||
NOEUD suiv = null;
|
||||
try {
|
||||
NOEUD init = (NOEUD) Naming.lookup(this.rmi + "/INIT" );
|
||||
if(init.GetTonSuivant() == null) {
|
||||
suiv = init;
|
||||
}
|
||||
else {
|
||||
suiv = init.GetTonSuivant();
|
||||
init.SetTonSuivant(this);
|
||||
}
|
||||
} catch (NotBoundException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
finally {
|
||||
return suiv;
|
||||
}
|
||||
}
|
||||
|
||||
public NOEUD GetTonSuivant() throws RemoteException {
|
||||
return this.suivant;
|
||||
}
|
||||
|
||||
public String GetInfo() throws RemoteException {
|
||||
return this.nom +"(" + this.numero + ")" +"-"+this.survivance ;
|
||||
}
|
||||
|
||||
public void SetTonSuivant(NOEUD n) throws RemoteException {
|
||||
this.suivant = n;
|
||||
}
|
||||
|
||||
public void CloseSite(NOEUD n) throws RemoteException {
|
||||
if(this.GetTonSuivant().equals(n)) {
|
||||
this.SetTonSuivant(n.GetTonSuivant());
|
||||
}
|
||||
else {
|
||||
this.GetTonSuivant().CloseSite(n);
|
||||
}
|
||||
}
|
||||
|
||||
public void Numerote(int n) throws RemoteException {
|
||||
if(this.numero != 1) {
|
||||
this.numero = n+1;
|
||||
this.survivance = (int)(Math.random()*1024)+1;
|
||||
this.GetTonSuivant().Numerote(n+1);
|
||||
}
|
||||
}
|
||||
|
||||
public void KillSite(int n) throws RemoteException {
|
||||
if(this.numero == n) {
|
||||
System.out.println("J'ai gagné, je m'en vais!");
|
||||
this.CloseSite(this);
|
||||
System.exit(1);
|
||||
}
|
||||
else {
|
||||
|
||||
this.GetTonSuivant().KillSite(n);
|
||||
}
|
||||
}
|
||||
|
||||
public void Election(int capaciteInit, int capaciteGagnante, int siteGagnant, int siteInitiateur) throws RemoteException {
|
||||
int dif = this.survivance-capaciteInit;
|
||||
if(this.numero == siteInitiateur) {
|
||||
new Thread() {
|
||||
private int gagnant;
|
||||
private int initiat;
|
||||
public void start(int g, int i) {
|
||||
this.gagnant = g;
|
||||
this.initiat = i;
|
||||
this.start();
|
||||
}
|
||||
public void run() {
|
||||
try {
|
||||
sleep(1000);
|
||||
ProclamationElection(gagnant, initiat);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}.start(siteGagnant,siteInitiateur);
|
||||
}
|
||||
else {
|
||||
if(dif <= capaciteGagnante) {
|
||||
this.GetTonSuivant().Election(capaciteInit, Math.abs(this.survivance-capaciteGagnante), this.numero, siteInitiateur);
|
||||
}
|
||||
else {
|
||||
this.GetTonSuivant().Election(capaciteInit, capaciteGagnante, siteGagnant, siteInitiateur);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ProclamationElection(int siteGagnant, int siteInitiateur) throws RemoteException {
|
||||
System.out.println("Gagnant noeud numero " + siteGagnant);
|
||||
this.KillSite(siteGagnant);
|
||||
}
|
||||
|
||||
public static void afficheMenu() {
|
||||
System.out.println('\t' + "K: Tuer ce noeud");
|
||||
System.out.println('\t' + "I: Infos de ce noeud");
|
||||
System.out.println('\t' + "N: Numeroter ");
|
||||
System.out.println('\t' + "E: Election ");
|
||||
System.out.println('\t' + "END: Quitter ");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String rmi = "rmi://" + args[0];
|
||||
String nom = args[1];
|
||||
NOEUD n = null;
|
||||
boolean cont = true;
|
||||
String cmd = "";
|
||||
BufferedReader bfr = new BufferedReader( new InputStreamReader( System.in) );
|
||||
if(nom.equals("INIT")) {
|
||||
try {
|
||||
n = new NOEUDImpl(nom, rmi);
|
||||
Naming.bind(rmi + "/" + nom, n);
|
||||
|
||||
} catch (AlreadyBoundException ex) {
|
||||
try {
|
||||
Naming.rebind(rmi + "/" + nom, n);
|
||||
} catch (RemoteException ex1) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex1);
|
||||
} catch (MalformedURLException ex1) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex1);
|
||||
}
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
n.SetTonSuivant(n.ConnectSuivant());
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
n = new NOEUDImpl(nom, rmi);
|
||||
n.SetTonSuivant(n.ConnectSuivant());
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
System.out.println("Menu de " + nom);
|
||||
System.out.println("Saisie commande: ");
|
||||
|
||||
while(cont) {
|
||||
afficheMenu();
|
||||
try {
|
||||
cmd = bfr.readLine();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
if(cmd.equals("K")) {
|
||||
try {
|
||||
n.CloseSite(n);
|
||||
System.exit(0);
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
else if(cmd.equals("I")) {
|
||||
try {
|
||||
String tmp = "NOEUD " + n.GetInfo() + " suivant " + n.GetTonSuivant().GetInfo();
|
||||
System.out.println(tmp);
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
else if(cmd.equals("N")) {
|
||||
try {
|
||||
NOEUD init = (NOEUD) Naming.lookup(rmi +"/INIT");
|
||||
init.GetTonSuivant().Numerote(1);
|
||||
init = null;
|
||||
} catch (NotBoundException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (RemoteException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
else if(cmd.equals("E")) {
|
||||
try {
|
||||
|
||||
NOEUD init = (NOEUD) Naming.lookup(rmi +"/INIT");
|
||||
StringTokenizer stSurvi = new StringTokenizer(init.GetInfo(),"-");
|
||||
stSurvi.nextToken();
|
||||
String survie = stSurvi.nextToken();
|
||||
init.GetTonSuivant().Election(new Integer(survie),1024,0,1);
|
||||
init = null;
|
||||
} catch (NotBoundException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (RemoteException ex) {
|
||||
//Logger.getLogger(NOEUDImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
else if(cmd.equals("END")) {
|
||||
cont = false;
|
||||
}
|
||||
cmd = "";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
BIN
A61/Client.class
Normal file
BIN
A61/Client.class
Normal file
Binary file not shown.
18
A61/Client.java
Normal file
18
A61/Client.java
Normal file
@ -0,0 +1,18 @@
|
||||
import java.rmi.* ;
|
||||
import java.net.MalformedURLException ;
|
||||
|
||||
public class Client {
|
||||
public static void main(String [] args) {
|
||||
if (args.length != 1) {
|
||||
System.out.println("Usage : java Client <machine du Serveur:port du rmiregistry>");
|
||||
System.exit(0);
|
||||
}
|
||||
try {
|
||||
Message b =(Message) Naming.lookup( "rmi://" + args[0] + "/Message" );
|
||||
System.out.println("Le client recoit : " + b.messageDistant());
|
||||
}
|
||||
catch (NotBoundException re) { System.out.println(re) ; }
|
||||
catch (RemoteException re) { System.out.println(re) ; }
|
||||
catch (MalformedURLException e) { System.out.println(e) ; }
|
||||
}
|
||||
}
|
BIN
A61/FASD.tar.gz
Normal file
BIN
A61/FASD.tar.gz
Normal file
Binary file not shown.
BIN
A61/FASD/ArbreNoeud.class
Normal file
BIN
A61/FASD/ArbreNoeud.class
Normal file
Binary file not shown.
53
A61/FASD/ArbreNoeud.java
Normal file
53
A61/FASD/ArbreNoeud.java
Normal file
@ -0,0 +1,53 @@
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public class ArbreNoeud {
|
||||
|
||||
private static int port = 1664;
|
||||
private Noeud noeud;
|
||||
|
||||
|
||||
public ArbreNoeud(String nom, String pere){
|
||||
Noeud noeud_pere;
|
||||
|
||||
System.out.println("creation du noeud:" + nom);
|
||||
if(pere == null) {
|
||||
try{
|
||||
noeud = new NoeudImpl(nom,null);
|
||||
Naming.rebind("rmi://127.0.0.1:" + port + "/" + nom, noeud);
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
try{
|
||||
noeud_pere = (Noeud)Naming.lookup("rmi://localhost:" + port + "/" + pere);
|
||||
noeud = new NoeudImpl(nom,pere);
|
||||
|
||||
Naming.rebind("rmi://127.0.0.1:" + port + "/" + nom, noeud);
|
||||
noeud_pere.addFils(nom.toString());
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main
|
||||
public static void main (String[] args) throws RemoteException {
|
||||
if(args.length == 2){
|
||||
new ArbreNoeud(args[0], args[1]);
|
||||
}
|
||||
else {
|
||||
if(args.length == 1) {
|
||||
new ArbreNoeud(args[0],null);
|
||||
}
|
||||
else {
|
||||
System.out.println(" ->Utilisation : java ArbreNoeud name father (pour un noeud)");
|
||||
System.out.println(" ->Utilisation : java ArbreNoeud name (pour la racine)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
A61/FASD/MyNoeud.class
Normal file
BIN
A61/FASD/MyNoeud.class
Normal file
Binary file not shown.
44
A61/FASD/MyNoeud.java
Normal file
44
A61/FASD/MyNoeud.java
Normal file
@ -0,0 +1,44 @@
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public class MyNoeud {
|
||||
|
||||
|
||||
public MyNoeud(String nom, String pere, String port) {
|
||||
|
||||
Noeud pere_temp;
|
||||
NoeudImpl n;
|
||||
|
||||
try{
|
||||
if(pere != null && !pere.equals("null")) {
|
||||
pere_temp = (Noeud)Naming.lookup("rmi://localhost:" + port + "/" + pere);
|
||||
n = new NoeudImpl(nom,pere_temp.getName());
|
||||
} else {
|
||||
pere_temp = null;
|
||||
n = new NoeudImpl(nom,null);
|
||||
}
|
||||
|
||||
try{
|
||||
Naming.rebind("rmi://127.0.0.1:" + port + "/" + nom, n);
|
||||
}catch (RemoteException e) {
|
||||
System.out.println(e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
System.out.println("rmi://localhost:" + port + "/" + nom);
|
||||
|
||||
if(pere_temp != null)
|
||||
pere_temp.addFils(nom);
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main (String[] args) throws RemoteException {
|
||||
if(args.length == 3){
|
||||
new MyNoeud(args[0], args[1], args[2]);
|
||||
} else {
|
||||
System.out.println(" please use : java MyNoeud name father port");
|
||||
}
|
||||
}
|
||||
}
|
BIN
A61/FASD/Noeud.class
Normal file
BIN
A61/FASD/Noeud.class
Normal file
Binary file not shown.
15
A61/FASD/Noeud.java
Normal file
15
A61/FASD/Noeud.java
Normal file
@ -0,0 +1,15 @@
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public interface Noeud extends Remote {
|
||||
|
||||
String getPere() throws RemoteException;
|
||||
String getName() throws RemoteException;
|
||||
String getFils(int i) throws RemoteException;
|
||||
void addFils(String n) throws RemoteException;
|
||||
int getNbFils() throws RemoteException;
|
||||
Vector getAllFils() throws RemoteException;
|
||||
|
||||
}
|
BIN
A61/FASD/NoeudImpl.class
Normal file
BIN
A61/FASD/NoeudImpl.class
Normal file
Binary file not shown.
46
A61/FASD/NoeudImpl.java
Normal file
46
A61/FASD/NoeudImpl.java
Normal file
@ -0,0 +1,46 @@
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.*;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
public class NoeudImpl extends UnicastRemoteObject implements Noeud {
|
||||
|
||||
private String name;
|
||||
private String pere;
|
||||
private int nbFils;
|
||||
private Vector<String> fils;
|
||||
|
||||
public NoeudImpl(String n, String p) throws RemoteException {
|
||||
name = n;
|
||||
pere = p;
|
||||
fils = new Vector<String>();
|
||||
nbFils = 0;
|
||||
}
|
||||
|
||||
public String getPere() throws RemoteException {
|
||||
return pere;
|
||||
}
|
||||
|
||||
public String getName() throws RemoteException {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFils(int i) throws RemoteException {
|
||||
return fils.get(i);
|
||||
}
|
||||
|
||||
public void addFils(String n) throws RemoteException {
|
||||
System.out.println("Message du pere:"+ name + ", Ajout du fils:" + n );
|
||||
fils.add(n);
|
||||
nbFils ++;
|
||||
}
|
||||
|
||||
public int getNbFils() throws RemoteException {
|
||||
return nbFils;
|
||||
}
|
||||
|
||||
public Vector getAllFils() throws RemoteException {
|
||||
return fils;
|
||||
}
|
||||
|
||||
}
|
BIN
A61/FASD/NoeudImpl_Stub.class
Normal file
BIN
A61/FASD/NoeudImpl_Stub.class
Normal file
Binary file not shown.
44
A61/FASD/launch.sh
Normal file
44
A61/FASD/launch.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "rmiregistry 1664&"
|
||||
rmiregistry 1664&
|
||||
sleep 1
|
||||
|
||||
echo
|
||||
# le parent & l'entrée dans l'arbre
|
||||
java ArbreNoeud n1&
|
||||
sleep 1
|
||||
|
||||
echo
|
||||
# n1 a 3 fils
|
||||
java ArbreNoeud n2 n1&
|
||||
sleep 1
|
||||
java ArbreNoeud n3 n1&
|
||||
sleep 1
|
||||
java ArbreNoeud n4 n1&
|
||||
sleep 1
|
||||
|
||||
echo
|
||||
# n2 a 2 fils
|
||||
java ArbreNoeud n5 n2&
|
||||
sleep 1
|
||||
java ArbreNoeud n6 n2&
|
||||
sleep 1
|
||||
|
||||
echo
|
||||
# n4 a 3 fils
|
||||
java ArbreNoeud n7 n4&
|
||||
sleep 1
|
||||
java ArbreNoeud n8 n4&
|
||||
sleep 1
|
||||
java ArbreNoeud n9 n4&
|
||||
sleep 1
|
||||
|
||||
# n1
|
||||
# |
|
||||
# ------------
|
||||
# | | |
|
||||
# n2 n3 n4
|
||||
# ----- ---------
|
||||
# | | | | |
|
||||
# n5 n6 n7 n8 n9
|
BIN
A61/Message.class
Normal file
BIN
A61/Message.class
Normal file
Binary file not shown.
7
A61/Message.java
Normal file
7
A61/Message.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public interface Message extends Remote {
|
||||
public String messageDistant()
|
||||
throws RemoteException ;
|
||||
}
|
BIN
A61/MessageImpl.class
Normal file
BIN
A61/MessageImpl.class
Normal file
Binary file not shown.
13
A61/MessageImpl.java
Normal file
13
A61/MessageImpl.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.rmi.server.UnicastRemoteObject ;
|
||||
import java.rmi.RemoteException ;
|
||||
|
||||
public class MessageImpl
|
||||
extends UnicastRemoteObject
|
||||
implements Message {
|
||||
|
||||
public MessageImpl () throws RemoteException {super();};
|
||||
public String messageDistant()
|
||||
throws RemoteException {
|
||||
return( "Ici notre message." );
|
||||
}
|
||||
}
|
BIN
A61/MessageImpl_Stub.class
Normal file
BIN
A61/MessageImpl_Stub.class
Normal file
Binary file not shown.
BIN
A61/Serveur.class
Normal file
BIN
A61/Serveur.class
Normal file
Binary file not shown.
18
A61/Serveur.java
Normal file
18
A61/Serveur.java
Normal file
@ -0,0 +1,18 @@
|
||||
import java.net.* ;
|
||||
import java.rmi.* ;
|
||||
|
||||
public class Serveur {
|
||||
public static void main(String [] args) {
|
||||
if (args.length != 1) {
|
||||
System.out.println("Usage : java Serveur <port du rmiregistry>");
|
||||
System.exit(0);
|
||||
}
|
||||
try {
|
||||
MessageImpl objLocal = new MessageImpl ();
|
||||
Naming.rebind("rmi://localhost:1099/Message",objLocal) ;
|
||||
System.out.println("Serveur pret");
|
||||
}
|
||||
catch (RemoteException re) { System.out.println(re) ; }
|
||||
catch (MalformedURLException e) { System.out.println(e) ; }
|
||||
}
|
||||
}
|
BIN
A61/src.zip
Normal file
BIN
A61/src.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user