Skip to content

Commit

Permalink
Commit final dernier Livrable
Browse files Browse the repository at this point in the history
  • Loading branch information
djdhm committed Sep 22, 2018
1 parent 4e4d8c2 commit 2dd530a
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .idea/mainframer_state.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/RMI/ClientRMI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ public ClientRMI(){
}
}

public boolean ajouterData(String data){
public Bloque creerChaine(String data){
try {
return this.serveur.nouvelleChaine(data);
}catch (RemoteException e){

}
return null;
}
public Bloque ajouterData(String data){
try {
return this.serveur.ajouterData(data);
}catch (RemoteException e){
e.printStackTrace();
}
return true;
return null;
}


public ArrayList<String> ChercherUnMot(String mot){
try {
System.out.println("Chercher un mot dans clientRMI");
System.out.println(this.serveur.occurenceMot(mot));
return this.serveur.occurenceMot(mot);
}catch (RemoteException e){
e.printStackTrace();
Expand Down
7 changes: 7 additions & 0 deletions src/RMI/Noeud.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public ArrayList<Bloque> afficherChaineBloque() throws RemoteException{
return this.chaineBloque.getListeBloque();
}

@Override
public boolean nouvelleChaine(Bloque nouveauBloqueMine) throws RemoteException {
this.chaineBloque=new ChaineBloque(5);
this.chaineBloque.getListeBloque().add(nouveauBloqueMine);
System.out.println("Creation d'une nouvelle chaine de bloque ");
return true;
}


public void enregistreMoi(){
Expand Down
2 changes: 2 additions & 0 deletions src/RMI/RemoteNoeud.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface RemoteNoeud extends Remote{
public void arreterMining(Bloque bloque) throws RemoteException;
public ArrayList<String> rechercher(String mot) throws RemoteException;
public ArrayList<Bloque> afficherChaineBloque() throws RemoteException;

public boolean nouvelleChaine(Bloque nouveauBloqueMine) throws RemoteException;
}
4 changes: 2 additions & 2 deletions src/RMI/RemoteServeur.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.util.ArrayList;

public interface RemoteServeur extends Remote{

public Bloque nouvelleChaine(String data) throws RemoteException;
public boolean enregistrerNoeud(String addresse) throws RemoteException;
public boolean ajouterData(String data) throws RemoteException;
public Bloque ajouterData(String data) throws RemoteException;
public ArrayList<String> occurenceMot(String mot) throws RemoteException;
public ArrayList<Bloque> afficherChaineBloques() throws RemoteException;

Expand Down
44 changes: 40 additions & 4 deletions src/RMI/Serveur.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@ public static void main(String [] args) {

}

@Override
public Bloque nouvelleChaine(String data) throws RemoteException {

MiningCountdown countdown=new MiningCountdown(1);
for (String addresse:
listeAddresseNoeuds) {

Thread thread=new Thread(new MiningRunnable(addresse,data,countdown ));
thread.start();
}


try {
countdown.await();
for (String addresse:listeAddresseNoeuds
) {
RemoteNoeud r=(RemoteNoeud) Naming.lookup(addresse);
r.nouvelleChaine(countdown.getNouveauBloqueMine());

}

} catch (InterruptedException e) {
e.printStackTrace();
}
catch (NotBoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}

System.out.println("Nouveau bloc miné avec succés");
return countdown.getNouveauBloqueMine();
}

@Override
public boolean enregistrerNoeud(String addresse) throws RemoteException {
System.out.println("Ajout de neoud avec success");
Expand All @@ -43,7 +77,7 @@ public boolean enregistrerNoeud(String addresse) throws RemoteException {
}

@Override
public boolean ajouterData(String data) throws RemoteException {
public Bloque ajouterData(String data) throws RemoteException {
MiningCountdown countdown=new MiningCountdown(1);
for (String addresse:
listeAddresseNoeuds) {
Expand Down Expand Up @@ -73,21 +107,22 @@ public boolean ajouterData(String data) throws RemoteException {
}

System.out.println("Nouveau bloc miné avec succés");
return true;
return countdown.getNouveauBloqueMine();
}

@Override
public ArrayList<String> occurenceMot(String mot) throws RemoteException {
System.out.println("Occurence mot dans Serveur");
RechercheCountdown countdown=new RechercheCountdown(0);
RechercheCountdown countdown=new RechercheCountdown(1);
for (String addresse:listeAddresseNoeuds
) {
Thread thread=new Thread(new RechercheRunnable(addresse,countdown,mot));
thread.start();
}
try {
ArrayList<String> res=countdown.getResultat();
countdown.await();
ArrayList<String> res=countdown.getResultat();
System.out.println("resultat : "+res);
return res;
} catch (InterruptedException e) {
e.printStackTrace();
Expand All @@ -99,6 +134,7 @@ public ArrayList<String> occurenceMot(String mot) throws RemoteException {
public ArrayList<Bloque> afficherChaineBloques() throws RemoteException{
try{
RemoteNoeud n=(RemoteNoeud) Naming.lookup(this.listeAddresseNoeuds.get(0));
System.out.println(n.afficherChaineBloque().size());
return n.afficherChaineBloque();
}catch (NotBoundException e){
e.printStackTrace();
Expand Down
1 change: 0 additions & 1 deletion src/Structure/Bloque.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void minerBlockaDistance(int difficulte) {
hash = calculerHash();
}
if(encore) System.out.println("Structure.Bloque Resolu!!! : " + hash);
else System.out.println("Lqaweha chatryn ");
}

// Verifie si le bloque est valide ou pas
Expand Down
48 changes: 48 additions & 0 deletions src/Vues/AffichageBloque.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Vues;

import Structure.Bloque;

import javax.swing.*;
import java.util.Iterator;
import java.util.Spliterator;

public class AffichageBloque extends JPanel {
final int LENGTH=16;

public AffichageBloque(Bloque bloque, int indice){
super();
String data = bloque.getData();
addText("----------------------------------\n");
addText("| Bloque Num : "+indice+ " |\n");
addText("----------------------------------\n");
addText("| Contenu de Bloque\t|\n");
addText("----------------------------------\n");
afficher(data);
this.setLayout(new BoxLayout(this,BoxLayout
.Y_AXIS));
addText("----------------------------------\n");

addText("| Hash |\n");
addText("----------------------------------\n");
data=bloque.getHash();
afficher(data);
addText("----------------------------------\n");
data=bloque.getHashPrecedent();
addText("| Hash Précédent |\n");
addText("----------------------------------\n");
afficher(data);
addText("----------------------------------\n");

}

private void afficher(String data) {
for (int i = 0; i< data.length(); i+=LENGTH) {
int indice=Math.min(i+LENGTH,data.length());
addText(" "+data.substring(i,indice)+" ");
}
}

private void addText(String texte){
this.add(new JLabel(texte));
}
}
33 changes: 25 additions & 8 deletions src/Vues/AfficherChaine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,50 @@
import Structure.Bloque;

import javax.swing.*;
import javax.swing.text.ComponentView;
import javax.swing.text.View;
import java.awt.*;
import java.util.ArrayList;

public class AfficherChaine extends JFrame {
JScrollPane scrollPane;
public AfficherChaine(ClientRMI clientRMI){
this.setTitle("Afficher la chaine de bloques");
this.setSize(800,800);
this.setSize(640,480);
this.setLocationRelativeTo(null);
JPanel pan=new JPanel(null);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JPanel pan=new JPanel();
ArrayList<Bloque> chaineDeBloque=clientRMI.afficherChaine();
if(chaineDeBloque==null){

if(chaineDeBloque.size()==0){
pan.setLayout(new BorderLayout());
JTextArea vide=new JTextArea("La chaine est vide");
vide.setFont(new Font("Arial", Font.PLAIN, 40));
pan.add(vide);
pan.add(vide,BorderLayout.CENTER);
}
else{
JPanel liste=new JPanel();
BoxLayout horizontalLayout=new BoxLayout(liste,BoxLayout.X_AXIS);
liste.setLayout(horizontalLayout);
int indice=1;
for(Bloque b:chaineDeBloque){
JTextArea donnesBloque=new JTextArea(b.getData());
donnesBloque.setFont(new Font("Arial", Font.PLAIN, 40));
pan.add(donnesBloque);
liste.add(new JLabel("---------->"));
AffichageBloque donnesBloque=new AffichageBloque(b,indice);
liste.add(donnesBloque);
indice++;

}
scrollPane=new JScrollPane(liste);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// scrollPane.add(liste);
//scrollPane.setBounds(50,50,500,400);
pan.add(scrollPane);

}


this.setContentPane(scrollPane);

this.setContentPane(pan);
setVisible(true);
}
}
25 changes: 24 additions & 1 deletion src/Vues/AjouterNouvelleDonnees.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Vues;
import RMI.ClientRMI;
import Structure.Bloque;

import javax.swing.*;
import java.awt.*;
Expand All @@ -23,7 +24,20 @@ public AjouterNouvelleDonnees(ClientRMI clientRMI){
ajouterBoutton.setFont(new Font("Arial", Font.PLAIN, 20));
ajouterBoutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clientRMI.ajouterData(inputNouvelleDonnee.getText());
Bloque nouveauBloque=clientRMI.ajouterData(inputNouvelleDonnee.getText());

pan.removeAll();
pan.add(new JLabel("Nouveau bloque miné"),BorderLayout.NORTH);
pan.add(new AffichageBloque(nouveauBloque,1),BorderLayout.CENTER);
JButton retour=new JButton("Retour");
retour.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
close();
}
});
pan.add(retour,BorderLayout.PAGE_END);
raffraichir(pan);
}
} );

Expand All @@ -34,4 +48,13 @@ public void actionPerformed(ActionEvent e) {


}

private void raffraichir(JPanel pan) {
this.setContentPane(pan);
this.repaint();
}

private void close() {
this.dispose();
}
}
29 changes: 25 additions & 4 deletions src/Vues/ChercherDonneeDansLaChaine.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ public ChercherDonneeDansLaChaine(ClientRMI clientRMI){


JButton chercherBoutton=new JButton("Chercher");
chercherBoutton.setPreferredSize(new Dimension(400,100));
chercherBoutton.setFont(new Font("Arial", Font.PLAIN, 20));
chercherBoutton.setPreferredSize(new Dimension(180,60));
chercherBoutton.setFont(new Font("Arial", Font.PLAIN, 14));

chercherBoutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<String> res=clientRMI.ChercherUnMot(inputRecherche.getText());
if(res==null){
System.out.println("res dans client "+res);
pan.removeAll();
if(res.size()==0){
JTextArea vide=new JTextArea("Cette données n'exite pas dans la chaine");
vide.setPreferredSize(new Dimension(400,100));
vide.setFont(new Font("Arial", Font.PLAIN, 20));
Expand All @@ -38,13 +42,30 @@ public void actionPerformed(ActionEvent e) {
pan.add(donneeUnBloque);
}
}
rafraichier(pan);

}
} );




});
pan.add(inputRecherche);
pan.add(chercherBoutton);
this.setContentPane(pan);
this.setVisible(true);

}


public void rafraichier(JPanel panel) {
System.out.println("Rafraichissement");
this.setContentPane(panel);
this.repaint();
}




}

Loading

0 comments on commit 2dd530a

Please sign in to comment.