Phase de debug sur la synchro de l'historique
This commit is contained in:
parent
af0f76c780
commit
9010fe3f23
10 changed files with 64 additions and 14 deletions
Binary file not shown.
|
@ -27,6 +27,7 @@ public class ChatApp {
|
|||
|
||||
/* Map on l'on stocke localement les historiques des messages */
|
||||
private Map<String,Historique> mapHistorique ;
|
||||
private boolean historiqueAvailable = true;
|
||||
|
||||
/* ChatApp est associe a un utilisateur */
|
||||
private Utilisateur me;
|
||||
|
@ -53,11 +54,28 @@ public class ChatApp {
|
|||
* @param pseudo Pseudo de l'utilisateur
|
||||
* @param h nouvel Historique entre les deux utilisateurs
|
||||
*/
|
||||
public void majHistorique(String pseudo,Historique h) {
|
||||
public synchronized void majHistorique(Historique h) {
|
||||
getMapHistorique().put(h.getUser2().getPseudo(),h);
|
||||
}
|
||||
|
||||
|
||||
/*public void majHistorique2(MessageHorodate mh, String pseudo) {
|
||||
Historique h = getMapHistorique().get(pseudo);
|
||||
//h.addMessage(mh);
|
||||
getMapHistorique().put(h.getUser2().getPseudo(),h);
|
||||
}*/
|
||||
|
||||
public void majHistorique2(String mh, String pseudo) {
|
||||
Historique h = getMapHistorique().get(pseudo);
|
||||
MessageHorodate msghor = new MessageHorodate(this.getMe(),this.getMe(),"rien",1);
|
||||
System.out.println(">>"+mh+"<<");
|
||||
System.out.print(msghor.getDateHorodatage());
|
||||
System.out.println(msghor.getDestinataire());
|
||||
System.out.println(msghor.getSource());
|
||||
System.out.println(msghor.getType());
|
||||
|
||||
h.addMessage(msghor);
|
||||
getMapHistorique().put(h.getUser2().getPseudo(),h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modification du pseudo de l'utilisateur
|
||||
|
@ -160,7 +178,7 @@ public class ChatApp {
|
|||
* @param pseudo Pseudo de l'utilisateur dont on souhaite obtenir l'historique
|
||||
* @return Un historique
|
||||
*/
|
||||
public Historique getHist(String pseudo) {
|
||||
public synchronized Historique getHist(String pseudo) {
|
||||
Historique h = this.mapHistorique.get(pseudo);
|
||||
if( h != null) {
|
||||
return h ;
|
||||
|
@ -202,6 +220,14 @@ public class ChatApp {
|
|||
|
||||
}
|
||||
|
||||
public boolean isHistoriqueAvailable() {
|
||||
return historiqueAvailable;
|
||||
}
|
||||
|
||||
public void setHistoriqueAvailable(boolean historiqueAvailable) {
|
||||
this.historiqueAvailable = historiqueAvailable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RunnerEcouteUDP implements Runnable {
|
||||
|
|
Binary file not shown.
|
@ -27,12 +27,12 @@ public class MessageHorodate {
|
|||
this.setDestinataire(destinataire) ;
|
||||
this.setSource(source) ;
|
||||
this.setMessage(Message) ;
|
||||
this.dateHorodatage = new Date();
|
||||
this.setDateHorodatage(new Date());
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setDate(Date d) {
|
||||
this.dateHorodatage=d;
|
||||
this.setDateHorodatage(d);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ public class MessageHorodate {
|
|||
*/
|
||||
public String dateToString() {
|
||||
DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
return format.format(this.dateHorodatage);
|
||||
return format.format(this.getDateHorodatage());
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,11 +78,11 @@ public class MessageHorodate {
|
|||
int type = Integer.parseInt(mots[2].split("::")[1]);
|
||||
DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
try {
|
||||
/*try {
|
||||
date = format.parse(mots[3].split("::")[1]);
|
||||
} catch (ParseException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
String payload = "";
|
||||
for(int i=4; i< mots.length; i++) {
|
||||
if(mots[i].startsWith("Message::")) {
|
||||
|
@ -92,7 +92,7 @@ public class MessageHorodate {
|
|||
}
|
||||
|
||||
MessageHorodate mh = new MessageHorodate(destinataire, source, payload, type);
|
||||
mh.setDate(date);
|
||||
//mh.setDate(date);
|
||||
|
||||
return mh ;
|
||||
}
|
||||
|
@ -129,4 +129,12 @@ public class MessageHorodate {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public Date getDateHorodatage() {
|
||||
return dateHorodatage;
|
||||
}
|
||||
|
||||
public void setDateHorodatage(Date dateHorodatage) {
|
||||
this.dateHorodatage = dateHorodatage;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -49,7 +49,7 @@ public class TCPEchange {
|
|||
Historique h = app.getHist(User2.getPseudo());
|
||||
h.addMessage(mh);
|
||||
// on update la liste des historiques de app
|
||||
app.majHistorique(User2.getPseudo(), h);
|
||||
app.majHistorique(h);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -131,11 +131,18 @@ class RunnerTCPEnvoi implements Runnable {
|
|||
out.flush();
|
||||
break;
|
||||
}
|
||||
while(!app.isHistoriqueAvailable()) {
|
||||
try{wait();
|
||||
}catch(InterruptedException e) {}
|
||||
}
|
||||
app.setHistoriqueAvailable(false);
|
||||
Historique h = app.getHist(Destinataire.getPseudo());
|
||||
h.addMessage(mh);
|
||||
// on update la liste des historiques de app
|
||||
app.majHistorique(Destinataire.getPseudo(), h);
|
||||
|
||||
app.majHistorique(h);
|
||||
//app.majHistorique2(mh.toString(),Destinataire.getPseudo());
|
||||
app.setHistoriqueAvailable(false);
|
||||
notifyAll();
|
||||
out.println(mh);
|
||||
System.out.println("Envoi d'un mesage");
|
||||
out.flush();
|
||||
|
@ -149,6 +156,7 @@ class RunnerTCPEnvoi implements Runnable {
|
|||
// Gestion de l'exception de la fermeture de la socket
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Reception
|
||||
|
@ -193,10 +201,18 @@ class RunnerTCPEcoute implements Runnable {
|
|||
MessageHorodate mh = MessageHorodate.stringToMessageHorodate(msg);
|
||||
System.out.println("Type du message:"+mh.getType());
|
||||
if(mh.getType()==1) {
|
||||
while(!app.isHistoriqueAvailable()) {
|
||||
try{wait();
|
||||
}catch(InterruptedException e) {}
|
||||
}
|
||||
app.setHistoriqueAvailable(false);
|
||||
System.out.println("Historique mis à jour lors de la reception");
|
||||
Historique h = app.getHist(mh.getSource().getPseudo());
|
||||
h.addMessage(mh);
|
||||
app.majHistorique(mh.getSource().getPseudo(), h);
|
||||
app.majHistorique(h);
|
||||
app.setHistoriqueAvailable(true);
|
||||
notifyAll();
|
||||
//app.majHistorique2(mh,mh.getSource().getPseudo());
|
||||
}
|
||||
else if(mh.getType()==0) {
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue