Communication entre agent

Fermé
AHop Messages postés 22 Date d'inscription jeudi 18 mai 2017 Statut Membre Dernière intervention 24 mai 2017 - 24 mai 2017 à 11:05
Bonjour

j'utilise ce code pour envoyer le contenu d'une liste d'un agent coordinateur à un autre agent véhicule


package exemple;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;

import pack1.LineFile;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.SequentialBehaviour;
import jade.core.behaviours.WakerBehaviour;
import jade.lang.acl.ACLMessage;



public class Coordinateur extends Agent {
    @SuppressWarnings({ "unchecked", "rawtypes" })

	protected void setup(){
		List<Cvs> listCvs = new LinkedList<Cvs>();

		SequentialBehaviour comportementSequentiel = new SequentialBehaviour();
		
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action()  {
				
				try {
				
				
					Class.forName("org.relique.jdbc.csv.CsvDriver");

					Properties props = new Properties();
					props.put("fileExtension", ".txt");

					Connection conn = DriverManager.getConnection("jdbc:relique:csv:C:\\csv", props);

					Statement stmt = conn.createStatement();

					List<Cvs> listCvs = new LinkedList<Cvs>();
					ResultSet results = stmt.executeQuery("select * from csv order by eo");

					while (results.next()) {
						int id = results.getInt("id");
						String origin = results.getString("origin");
						String destination = results.getString("destination");
						int capacite = results.getInt("capacite");
						String eo = results.getString("eo");
						String em = results.getString("Em");
						String dtm = results.getString("DTM");
						String dtd = results.getString("DTD");
						String lo = results.getString("lo");
						String ed = results.getString("ed");
						String ld = results.getString("ld");
						Cvs cvs = new Cvs(id, origin, destination, capacite, eo, em, dtm, dtd, lo, ed, ld);
						listCvs.add(cvs);
					}
					
					Collections.sort(listCvs, new Comparator() {
						@Override
						public int compare(Object CvsOne, Object CvsTwo) {
							return ((Cvs) CvsOne).getEo().compareTo(((Cvs) CvsTwo).getEo());
						}
					});

					
					
					
					for (Cvs str : listCvs) {
						
						ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
						
				
						
						msg.setContent(str.getEm()+str.getOrigin()+str.getDestination()+str.getCapacite() +str.getId());
						
						
						
				        msg.addReceiver( new AID( "Véhicule", AID.ISLOCALNAME) );


				        try {
							Thread.sleep(5000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
				        send(msg);
						
						
				        
				        
					}
				/*	ACLMessage reply = receive();
					
					if (reply!=null) {
						System.out.println(reply.getContent());
					
					}*/
					block();
			        
					
					
					conn.close();
				
				}
		
			 catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			}
		});
		
		
		
		
		comportementSequentiel.addSubBehaviour(new CyclicBehaviour(){

		


			@Override
			
			public void action() {
				
			/*	for (Cvs str : listCvs) {
					
					ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
					
					msg.setContent(str.getEm());
					
					
					
			        msg.addReceiver( new AID( "Véhicule", AID.ISLOCALNAME) );


			        try {
						Thread.sleep(5000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
			        send(msg);
					
					
				}
				
		        

			 
			ACLMessage reply = receive();
			if (reply!=null) {
				System.out.println(reply.getContent());
			
			}
			block();
				*/
				
			}
		});
	
	
		addBehaviour(comportementSequentiel);
	}
}






je veux récupérer le contenu de msg chez agent véhicule dans une liste au lieu d'un affichage simple .




 public void action() {
			  
			  ACLMessage msg = receive();
			  
	          if (msg!=null) {
				 
				  
	              System.out.println(msg.getContent() );
	             
	              
	             
	          
	             
	           }     block();
		  }



comment je fais ?