diff --git a/Implementation/src/ChatApp.class b/Implementation/src/ChatApp.class index 36521f8..ecac7fc 100644 Binary files a/Implementation/src/ChatApp.class and b/Implementation/src/ChatApp.class differ diff --git a/Implementation/src/ChatApp.java b/Implementation/src/ChatApp.java index 30a63c3..4bcea64 100644 --- a/Implementation/src/ChatApp.java +++ b/Implementation/src/ChatApp.java @@ -27,6 +27,7 @@ public class ChatApp { /* Map on l'on stocke localement les historiques des messages */ private Map 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 { diff --git a/Implementation/src/MessageHorodate.class b/Implementation/src/MessageHorodate.class index 84fb0ad..8239524 100644 Binary files a/Implementation/src/MessageHorodate.class and b/Implementation/src/MessageHorodate.class differ diff --git a/Implementation/src/MessageHorodate.java b/Implementation/src/MessageHorodate.java index 1b6618e..7aeb573 100644 --- a/Implementation/src/MessageHorodate.java +++ b/Implementation/src/MessageHorodate.java @@ -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; + } + } diff --git a/Implementation/src/RunnerEcouteTCP.class b/Implementation/src/RunnerEcouteTCP.class index 376c68b..df8fec6 100644 Binary files a/Implementation/src/RunnerEcouteTCP.class and b/Implementation/src/RunnerEcouteTCP.class differ diff --git a/Implementation/src/RunnerEcouteUDP.class b/Implementation/src/RunnerEcouteUDP.class index 5399115..7cf0325 100644 Binary files a/Implementation/src/RunnerEcouteUDP.class and b/Implementation/src/RunnerEcouteUDP.class differ diff --git a/Implementation/src/RunnerTCPEcoute.class b/Implementation/src/RunnerTCPEcoute.class index fee6657..dfc1313 100644 Binary files a/Implementation/src/RunnerTCPEcoute.class and b/Implementation/src/RunnerTCPEcoute.class differ diff --git a/Implementation/src/RunnerTCPEnvoi.class b/Implementation/src/RunnerTCPEnvoi.class index 19d7545..0065535 100644 Binary files a/Implementation/src/RunnerTCPEnvoi.class and b/Implementation/src/RunnerTCPEnvoi.class differ diff --git a/Implementation/src/TCPEchange.class b/Implementation/src/TCPEchange.class index 85168f3..c5f4e52 100644 Binary files a/Implementation/src/TCPEchange.class and b/Implementation/src/TCPEchange.class differ diff --git a/Implementation/src/TCPEchange.java b/Implementation/src/TCPEchange.java index 4ad4411..f8404ee 100644 --- a/Implementation/src/TCPEchange.java +++ b/Implementation/src/TCPEchange.java @@ -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;