Précédent   Forum du club des développeurs et IT Pro > Java > Général Java > Langage > Autres > Programmation par agent
Programmation par agent Forum d'entraide pour la programmation orientée agents et les frameworks associés (JADE, JACK, Jadex, JAgent, Janus, Jason, MadKit, ...)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Actualité déjà publiée
 
Outils de la discussion
Publicité
'
Vieux 08/04/2011, 09h49   #121
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
peux tu nous montrer le code de ton agent ?
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/04/2011, 09h56   #122
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Citation:
Merci à tous ,ça marche Bien Mnt ;
le problème est l'ordre de lancement le main container et le container-1 je pense
Merci infiniment Djug
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/04/2011, 10h36   #123
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Par défaut Agent JADE & MySql

Citation:
Envoyé par Djug Voir le message
Bonjour,

voici un article sur Les communications des agents JADE

http://djug.developpez.com/java/jade/communication/


vos remarques sont les bienvenues.
Citation:
Bonjour ,
j'ai réussi à faire la mobilité inter container ;
et j'ai créer une class qui permet de faire la connexion à la BDD MySql et du récupéré les donnes;
Mais lorsque j'ai essayé de faire que mon agent mobile récupérer ces donnes j'ai trouve une erreur même la mobilité ne marche pas(pas de trace) !!!!
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
 import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.*;
import jade.core.ContainerID;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.RowData;
public class AgentProj extends Agent{
	 Connection connection;
	Record[][] dc = new Record [3][4]; // donnes recupere 
	 String prod;
     public void setup(){
        addBehaviour(new B());
 
                        }
     private class B extends SimpleBehaviour{
 
    	 private boolean _done;
    	 private int step=0;
 
 
            public void action(){
            	System.out.println("My name is "+ getLocalName());
            	System.out.println(" I'm in Main container ");
        		Object[] args = getArguments();
        		if (args != null){
        			for (int i = 0; i < args.length; i++) {
        			   System.out.println(" I'm try to buy "+(String)args[i]);
        			   prod=(String)args[i];
        	    }	
        		}else{
        			System.out.println("No arguments");
        		}
         //************************************Migration 1*************************************
 
             switch(step){
 
                     case 0:
                          System.out.println("\n Moving1 ...");
                          // on déclare la variable qui va contenir le nom du Container 
                         String containerName = "Container-1";
                         ContainerID destination = new ContainerID();
                         // on déclare la variable qui represente la destination
                          destination.setName(containerName);
                         // et on fait la migration
                         myAgent.doMove(destination);
                         System.out.println("Hello, I'm in container-1 ");
                         try
                         {
                             Class.forName("com.mysql.jdbc.Driver");
                             System.out.println("com.mysql.jdbc.Driver found");
                             connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/agent","root","root");
                             System.out.println("Connexion Ok");
                             Statement instruction = connection.createStatement();
                     		 ResultSet resultat = instruction.executeQuery("SELECT * FROM tab1 where nom_prod LIKE'"+prod+"'");
                     		  while(resultat.next()){
                     			  if (resultat!= null){
                     				  System.out.println(resultat.getString("prix_prod")); 
 
                     			  }
                     		  }
                         }
                         catch(Exception cnfe)
                         {
                             System.out.println("Error:"+cnfe.getMessage());
                         }
				         step++;
                        break;
          //***************************** Migration 2***********************************************              
                    case 1:
                         System.out.println("\n Moving2 ...");
                      // on déclare la variable qui va contenir le nom du Container 
                         String containerName2 = "Container-2";
                         ContainerID destination2 = new ContainerID();
                         // on déclare la variable qui represente la destination
                         destination2.setName(containerName2);
                         // et on fait la migration
                         myAgent.doMove(destination2);
                         System.out.println("Hello I'm in container-2 ");
                         try
                         {
                             Class.forName("com.mysql.jdbc.Driver");
                             System.out.println("com.mysql.jdbc.Driver found");
                             connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/agent2","root","root");
                             System.out.println("Connexion Ok");
                             Statement instruction = connection.createStatement();
                     		 ResultSet resultat2 = instruction.executeQuery("SELECT * FROM tab2 where nom_prod LIKE'"+prod+"'");
                     		  while(resultat2.next()){
                     			  if (resultat2!= null){
                     				  System.out.println(resultat2.getString("prix_prod")); 
 
                     			  }
                     		  }
                         }
                         catch(Exception cnfe)
                         {
                             System.out.println("Error:"+cnfe.getMessage());
                         }
                         step++;
                         break;
          //******************************** Retour à Main container *******************************          
                    case 2:
 
                        System.out.println("\n\nMoving3 ...");
            			String containerName3 = "Main-Container";
                        ContainerID destination3 = new ContainerID();
                        // on déclare la variable qui represente la destination
                        destination3.setName(containerName3);
                        System.out.println("je vais retourner ...");
                        // et on fait la migration
                        myAgent.doMove(destination3);
                        System.out.println(" Les donnes recuperer :");
                        step++;
                        break;
 
        //********************************** Finich************************************************           
 
                  case 3:
                  _done=true;
                  System.out.println(" I'm finiche My work :The agent has terminated its itinirary");
 
                          }//end switch
   }//end action
            public boolean done()
            {
            	return _done;
            }
 
 
} // end setup
} // end AgentProj
Citation:
j'ai trouve ce erreur :
17 avr. 2011 23:01:28 jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved
GRAVE: Error in agent serialization. Abort transfer. java.io.NotSerializableException: java.lang.Object
Citation:
quelqu'un peux m'aider ou bien corrige mon idée ,merci à vos réponses
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/04/2011, 10h43   #124
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
Citation:
quelqu'un peux m'aider ou bien corrige mon idée
corriger une idée ?? je crois que ce n'ai pas du tout facile, mais si tu nous indique la partie qui te pose problème, on peut peut être t'aider
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/04/2011, 20h13   #125
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Citation:
Envoyé par Djug Voir le message
corriger une idée ?? je crois que ce n'ai pas du tout facile, mais si tu nous indique la partie qui te pose problème, on peut peut être t'aider
Citation:
salut , Je vais essayer de réécrire ma question de manière plus,
je veux que mon agent mobile récupérer les donnes du conteneurs visité ?
est ce que mon code réponde à cet besoin ?
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
 
 import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.*;
import jade.core.ContainerID;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.RowData;
public class AgentProj extends Agent{
	 Connection connection;
	Record[][] dc = new Record [3][4]; // donnes recupere 
	 String prod;
     public void setup(){
        addBehaviour(new B());
 
                        }
     private class B extends SimpleBehaviour{
 
    	 private boolean _done;
    	 private int step=0;
 
 
            public void action(){
            	System.out.println("My name is "+ getLocalName());
            	System.out.println(" I'm in Main container ");
        		Object[] args = getArguments();
        		if (args != null){
        			for (int i = 0; i < args.length; i++) {
        			   System.out.println(" I'm try to buy "+(String)args[i]);
        			   prod=(String)args[i];
        	    }	
        		}else{
        			System.out.println("No arguments");
        		}
         //************************************Migration 1*************************************
 
             switch(step){
 
                     case 0:
                          System.out.println("\n Moving1 ...");
                          // on déclare la variable qui va contenir le nom du Container 
                         String containerName = "Container-1";
                         ContainerID destination = new ContainerID();
                         // on déclare la variable qui represente la destination
                          destination.setName(containerName);
                         // et on fait la migration
                         myAgent.doMove(destination);
                         System.out.println("Hello, I'm in container-1 ");
                         try
                         {
                             Class.forName("com.mysql.jdbc.Driver");
                             System.out.println("com.mysql.jdbc.Driver found");
                             connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/agent","root","root");
                             System.out.println("Connexion Ok");
                             Statement instruction = connection.createStatement();
                     		 ResultSet resultat = instruction.executeQuery("SELECT * FROM tab1 where nom_prod LIKE'"+prod+"'");
                     		  while(resultat.next()){
                     			  if (resultat!= null){
                     				  System.out.println(resultat.getString("prix_prod")); 
 
                     			  }
                     		  }
                         }
                         catch(Exception cnfe)
                         {
                             System.out.println("Error:"+cnfe.getMessage());
                         }
				         step++;
                        break;
          //***************************** Migration 2***********************************************              
                    case 1:
                         System.out.println("\n Moving2 ...");
                      // on déclare la variable qui va contenir le nom du Container 
                         String containerName2 = "Container-2";
                         ContainerID destination2 = new ContainerID();
                         // on déclare la variable qui represente la destination
                         destination2.setName(containerName2);
                         // et on fait la migration
                         myAgent.doMove(destination2);
                         System.out.println("Hello I'm in container-2 ");
                         try
                         {
                             Class.forName("com.mysql.jdbc.Driver");
                             System.out.println("com.mysql.jdbc.Driver found");
                             connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/agent2","root","root");
                             System.out.println("Connexion Ok");
                             Statement instruction = connection.createStatement();
                     		 ResultSet resultat2 = instruction.executeQuery("SELECT * FROM tab2 where nom_prod LIKE'"+prod+"'");
                     		  while(resultat2.next()){
                     			  if (resultat2!= null){
                     				  System.out.println(resultat2.getString("prix_prod")); 
 
                     			  }
                     		  }
                         }
                         catch(Exception cnfe)
                         {
                             System.out.println("Error:"+cnfe.getMessage());
                         }
                         step++;
                         break;
          //******************************** Retour à Main container *******************************          
                    case 2:
 
                        System.out.println("\n\nMoving3 ...");
            			String containerName3 = "Main-Container";
                        ContainerID destination3 = new ContainerID();
                        // on déclare la variable qui represente la destination
                        destination3.setName(containerName3);
                        System.out.println("je vais retourner ...");
                        // et on fait la migration
                        myAgent.doMove(destination3);
                        System.out.println(" Les donnes recuperer :");
                        step++;
                        break;
 
        //********************************** Finich************************************************           
 
                  case 3:
                  _done=true;
                  System.out.println(" I'm finiche My work :The agent has terminated its itinirary");
 
                          }//end switch
   }//end action
            public boolean done()
            {
            	return _done;
            }
 
 
} // end setup
} // end AgentProj
si oui pour quoi me donne ce erreur ? en plus j'ai remarqué que mon agent n'est pas migré du main container !!
Code :
1
2
3
 
17 avr. 2011 23:01:28 jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved
GRAVE: Error in agent serialization. Abort transfer. java.io.NotSerializableException: java.lang.Object
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/04/2011, 08h34   #126
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
je me souviens que je travaillais avec Jade, que celui la retourne toujours des erreurs qu'on essaye d'enchainer des tâches dans lesquelles l’agent doit migrer d'un endroit à un autre via des switch Case

la solution pour ce problème est l'utilisation des SequentielBehaviour ou des FSMBehaviour


et voici un tutoriel sur Les Behaviours dans JADE
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/04/2011, 16h06   #127
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Citation:
Envoyé par Djug Voir le message
je me souviens que je travaillais avec Jade, que celui la retourne toujours des erreurs qu'on essaye d'enchainer des tâches dans lesquelles l’agent doit migrer d'un endroit à un autre via des switch Case

la solution pour ce problème est l'utilisation des SequentielBehaviour ou des FSMBehaviour


et voici un tutoriel sur Les Behaviours dans JADE
Citation:
Alors j'ai essayé avec les deux en fin la mobilité ça marche bien avec le Séquentiel Behaviour ,Mais lorsque j'ai ajoute le code qui fait la connexion à la BDD j'ai tombé dans la même problème ,Donc ou ce trouve le pb !!?
(est ce que quand je programmé avec les agents mobiles les instruction du récupéré les donnes sont déférente ?)
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 Le code :
 import jade.core.Agent;
import jade.core.ContainerID;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.SequentialBehaviour;
import jade.core.behaviours.WakerBehaviour;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.*;
import jade.core.ContainerID;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.RowData;
 
public class Seq extends Agent {
	 String  prix_prod;
	 Connection connection;
	protected void setup(){
		//*************************** Main container**********************************
		SequentialBehaviour comportementSequentiel = new SequentialBehaviour();
 
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				//System.out.println("le premier sous-comportement");
				System.out.println(" Hello World My name is :"+ getLocalName());
	        	System.out.println(" I'm in Main container ");
	    		Object[] args = getArguments();
	    		if (args != null){
	    			for (int i = 0; i < args.length; i++) {
	    			   System.out.println(" I'm try to buy "+(String)args[i]);
 
	    			   prix_prod=(String)args[i];
	    	    }	
	    		}else{
	    			System.out.println("No arguments");}
 
 
			}
		});
		//****************************Migration à Container_1*******************************
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				System.out.println("\n Moving1 ...");
                // on déclare la variable qui va contenir le nom du Container 
               String containerName = "Container-1";
               ContainerID destination = new ContainerID();
               // on déclare la variable qui represente la destination
                destination.setName(containerName);
               // et on fait la migration
               myAgent.doMove(destination);
               System.out.println("Hello, I'm in container-1 ");
               try
               {
                   Class.forName("com.mysql.jdbc.Driver");
                   System.out.println("com.mysql.jdbc.Driver found");
                   connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/agent","root","root");
                   System.out.println("Connexion Ok");
                   Statement instruction = connection.createStatement();
           		 ResultSet resultat = instruction.executeQuery("SELECT * FROM tab1 where nom_prod LIKE'"+prix_prod+"'");
           		  while(resultat.next()){
           			  if (resultat!= null){
           				  System.out.println(resultat.getString("prix_prod")); 
 
           			  }
           		  }
               }
               catch(Exception cnfe)
               {
                   System.out.println("Error:"+cnfe.getMessage());
               }
 
 
			}
		});
		//*****************************Migration à Container_2********************************
         comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				System.out.println("\n Moving2 ...");
                // on déclare la variable qui va contenir le nom du Container 
                   String containerName2 = "Container-2";
                   ContainerID destination2 = new ContainerID();
                   // on déclare la variable qui represente la destination
                   destination2.setName(containerName2);
                   // et on fait la migration
                   myAgent.doMove(destination2);
                   System.out.println("Hello I'm in container-2 ");
 
				// connexion à BDD2............
 
			}
		});
 
		//****************************Retour à Main Container **********************************
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				//System.out.println("le derniers sous-comportement");
 
				 System.out.println("\n Moving3 ...");
     			String containerName3 = "Main-Container";
                 ContainerID destination3 = new ContainerID();
                 // on déclare la variable qui represente la destination
                 destination3.setName(containerName3);
                 System.out.println("je vais retourner à main container  ...");
                 // et on fait la migration
                 myAgent.doMove(destination3);
                 // recupere les donnes .................
				//myAgent.doDelete();
			}
		});
		addBehaviour(comportementSequentiel);
	}
}
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 résultat d'exécution :
Hello World My name is :Agent1
 I'm in Main container 
 I'm try to buy JADE
 
 Moving1 ...
Hello, I'm in container-1 
com.mysql.jdbc.Driver found
Connexion Ok
 
 Moving2 ...
Hello I'm in container-2 
 
 Moving3 ...
je vais retourner à main container  ...
19 avr. 2011 15:01:46 jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved
GRAVE: Error in agent serialization. Abort transfer. java.io.NotSerializableException: com.mysql.jdbc.DatabaseMetaData
19 avr. 2011 15:01:46 jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved
GRAVE: Error in agent serialization. Abort transfer. java.io.NotSerializableException: com.mysql.jdbc.DatabaseMetaData
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/04/2011, 09h42   #128
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
tout est dans le message d'erreur:

la chaine de connexion n'est pas "sérialisable", donc l'agent ne peut pas migrer tant qu'il reste connecté à la base de données,

il faut fermer cette connexion avant la migration
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/04/2011, 08h53   #129
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Citation:
Envoyé par Djug Voir le message
tout est dans le message d'erreur:

la chaine de connexion n'est pas "sérialisable", donc l'agent ne peut pas migrer tant qu'il reste connecté à la base de données,

il faut fermer cette connexion avant la migration
Citation:
Bonjour,
,J'ai essayé comme décrit dans le code Mais je trouve le même problème
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 import jade.core.Agent;
import jade.core.ContainerID;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.SequentialBehaviour;
import jade.core.behaviours.WakerBehaviour;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.*;
import jade.core.ContainerID;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.RowData;

public class Seq extends Agent {
	 String  prod;
	 Connection connection=null;
	protected void setup(){
		//*************************** Main container**********************************
		SequentialBehaviour comportementSequentiel = new SequentialBehaviour();
		
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				//System.out.println("le premier sous-comportement");
				System.out.println(" Hello World My name is :"+ getLocalName());
	        	System.out.println(" I'm in Main container ");
	    		Object[] args = getArguments();
	    		if (args != null){
	    			for (int i = 0; i < args.length; i++) {
	    			   System.out.println(" I'm try to buy "+(String)args[i]);
	    			   
	    			   prod=(String)args[i];
	    	    }	
	    		}else{
	    			System.out.println("No arguments");}
	   	
			}
		});
		//****************************Migration à Container_1*******************************
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				try{
            	    Class.forName("com.mysql.jdbc.Driver");
            	}catch(Exception e){}

               
				System.out.println("\n Moving1 ...");
                // on déclare la variable qui va contenir le nom du Container 
               String containerName = "Container-1";
               ContainerID destination = new ContainerID();
               // on déclare la variable qui represente la destination
                destination.setName(containerName);
               // et on fait la migration
               myAgent.doMove(destination);
              // doWait(10);
               System.out.println("Hello, I'm in container-1 ");
               
           	try
            {
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("com.mysql.jdbc.Driver found");
                connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/agent","root","root");
                System.out.println("Connexion Ok");
                Statement instruction = connection.createStatement();
                
                ResultSet resultat = instruction.executeQuery("SELECT nom_prod FROM tab1 where nom_prod='"+prod+"'");
               	
              
                     
                while(resultat.next())
        			System.out.println(" Nom_produit: "+resultat.getString("nom_prod"));
        			

            }
            catch(Exception cnfe)
            {
                System.out.println("Error:"+cnfe.getMessage());
            }
        		
            if(connection!=null){try{connection.close();}catch(Exception e){e.printStackTrace();  }
            
            } 		
             
		}});
	
		//*****************************Migration à Container_2********************************
     comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				System.out.println("\n Moving2 ...");
                // on déclare la variable qui va contenir le nom du Container 
                   String containerName2 = "Container-2";
                   ContainerID destination2 = new ContainerID();
                   // on déclare la variable qui represente la destination
                   destination2.setName(containerName2);
                   // et on fait la migration
                   myAgent.doMove(destination2);
                   System.out.println("Hello I'm in container-2 ");
                  
				
			}
		});
		
		//****************************Retour à Main Container **********************************
		comportementSequentiel.addSubBehaviour(new OneShotBehaviour(){
			@Override
			public void action() {
				//System.out.println("le derniers sous-comportement");
				
				 System.out.println("\n Moving3 ...");
     			String containerName3 = "Main-Container";
                 ContainerID destination3 = new ContainerID();
                 // on déclare la variable qui represente la destination
                 destination3.setName(containerName3);
                 System.out.println("je vais retourner à main container  ...");
                 // et on fait la migration
                 myAgent.doMove(destination3);
				//myAgent.doDelete();
			}
		});
		addBehaviour(comportementSequentiel);
	}
}
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 résultat d'exécution : 

 Hello World My name is :AgentJDBC
 I'm in Main container 
 I'm try to buy JADE1

 Moving1 ...
Hello, I'm in container-1 
com.mysql.jdbc.Driver found
Connexion Ok
 Nom_produit: JADE1

 Moving2 ...
Hello I'm in container-2 

 Moving3 ...
je vais retourner à main container  ...
24 avr. 2011 07:45:06 jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved
GRAVE: Error in agent serialization. Abort transfer. java.io.NotSerializableException: com.mysql.jdbc.DatabaseMetaData
24 avr. 2011 07:45:06 jade.core.mobility.AgentMobilityService$CommandSourceSink handleInformMoved
GRAVE: Error in agent serialization. Abort transfer. java.io.NotSerializableException: com.mysql.jdbc.DatabaseMetaData
Code :
1
2
3
4
5
INFO: --------------------------------------
Agent container Container-1@super-com-PC is ready.
--------------------------------------------
pas de trace que l'agent fait la migration 
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2011, 10h43   #130
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
il suffit de fermer la connexion à la base de données (tu l'a déjà essayé)
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2011, 11h25   #131
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Citation:
Envoyé par Djug Voir le message
il suffit de fermer la connexion à la base de données (tu l'a déjà essayé)
Bonjour ,
oui j'ai fermé la connexion comme suit :
Code :
    if(connection!=null){try{connection.close();}catch(Exception e){e.printStackTrace();  }
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2011, 11h50   #132
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
et pourtant le message d'erreur montre que la connexion est toujours active

une autre idée: et si tu utilises deux agents, l'un qui se charge de communiquer avec la base de données, et envoie les données récupérées à l'agent principale qui se charge de se "balader" entre les Container
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2011, 08h32   #133
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Par défaut integration web service et agent mobile

Citation:
Envoyé par Djug Voir le message
et pourtant le message d'erreur montre que la connexion est toujours active

une autre idée: et si tu utilises deux agents, l'un qui se charge de communiquer avec la base de données, et envoie les données récupérées à l'agent principale qui se charge de se "balader" entre les Container
Bonjour,
Pour ce Besoin et autres je veut intégrer le WSIG avec JADE ,Mais je ne sais pas comment le faire .si t'as une idée Merci tu me expliqué , sachant que j'ai téléchargé : Apatch Ant ,juddi-tomcat 3.0.0 ,juddi -portal-bundle , JadeLeapj2se , Wsig ;
Merci infiniment msr Djug
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2011, 08h35   #134
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
Citation:
je veut intégrer le WSIG avec JADE
je ne sais même pas de quoi s'agit il
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/04/2011, 08h19   #135
manare
Membre du Club
 
Femme Manar
Etudiante
Inscription : avril 2009
Messages : 33
Détails du profil
Informations personnelles :
Nom : Femme Manar
Localisation : Algérie

Informations professionnelles :
Activité : Etudiante

Informations forums :
Inscription : avril 2009
Messages : 33
Points : 40
Points : 40
Citation:
Envoyé par Djug Voir le message
je ne sais même pas de quoi s'agit il
voila : http://agents.develop123.com/index.p...services-part1
manare est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/04/2011, 09h26   #136
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
pourquoi tu veux intégrer WSIG avec JADE ?

la programmation orienté agent n'est pas facile, alors pourquoi vouloir la compliquer plus.

si ton but et de permettre aux agents de communiquer avec des entités qui se trouve sur d’autres machines, à mon avis la meilleure et la plus simples des solutions est la communication via les sockets
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/04/2011, 09h36   #137
Aurelienjjj
Candidat au titre de Membre du Club
 
Inscription : mai 2005
Messages : 22
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 22
Points : 10
Points : 10
Envoyer un message via MSN à Aurelienjjj
Bonjour

J'ai un petit soucis avec JADE: j'ai une série d'agents (sérialisés et créés automatiquement) gérés par un agent superviseur, et avec qui ce superviseur communique. Le problème, c'est que je ne peux pas, dans le programme, être certain du nombre d'agents existants au moment ou les fonctions de communication sont appelées, ce qui génère des exceptions (Java.Lang.Acl.UnreadableException, du au fait qu'on envoie un message à un agents n'existant plus dans l'annuaire et que je n'arrive pas à récupérer d'ailleurs).

Du coup j'aimerai savoir s'il y avait moyen de tester l'existence d'un agent dans l'annuaire en ne connaissant que son nom.

Un petit bout de code:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	public void SendMessageAll(String MessageToSend)
	{
	    ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
		ArrayList<String> message = new ArrayList<String>();
		int i;
		message.add(MessageToSend);
		try {
			msg.setContentObject(message);
		 	} catch (IOException e) {e.printStackTrace();}
               // Nombre max d'agents
		for(i=0;i<20;i++)
			{	
					msg.addReceiver(new AID("Robot"+i, AID.ISLOCALNAME));
					//L'erreur est provoquée ici, le catch avec une simple exception ou une UnreadableException ne sert à rien
                                        try {myAgent.send(msg);} catch (Exception e) {}
					msg.removeReceiver(new AID("Robot"+i, AID.ISLOCALNAME));
		}	
	}
(Au passage, je viens de m'apercevoir qu'il serait peut être plus judicieux de sortir l'envoie du message et le remover du for... )

Tant que je suis là, merci à Djug pour les tuto et l'aide donné sur ce forum qui m'ont bien aidé (surtout au démarrage, le jade.boot m'a fait tourné en rond un moment).
Aurelienjjj est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/04/2011, 09h47   #138
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
penses à utiliser l'agent DF (Directory Facilitator) :c'est l'agent qui représente la mémoire de la plateforme et tous les agents s’inscrivent auprès de lui dés leurs créations.

donc tu peux demander à l'agent DF si un tel agent x existe ou pas avant de l'ajouter à la liste des destinataires.
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/04/2011, 10h17   #139
Aurelienjjj
Candidat au titre de Membre du Club
 
Inscription : mai 2005
Messages : 22
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 22
Points : 10
Points : 10
Envoyer un message via MSN à Aurelienjjj
Merci de la réponse rapide

J'ai déjà testé avec l'agent DF, le problème est que la fonction DFService.search(Agent, dfd) et ses déclinaisons demandent toutes un agent en entrée. Or, mes agents secondaires ne sont pas déclarés ici, et je ne trouve pas de solution valable pour les appeler de façon correcte dans cette fonction.
(La fonction SendToAll est dans le behaviour de l'agent principal).

Ça fait déjà un moment que je suis penché là dessus sans trouver de solution, et ça m'embête un peu d'avoir systématiquement une flopée d'exceptions lorsque j'exécute certaines fonctionnalité du programme de façon incorrecte. Un collègue m'avait proposé d'utiliser les fonctionnalité de l'AMS, mais je n'ai plus trouvé de solution dans cette direction.
Aurelienjjj est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/04/2011, 10h27   #140
Djug
Rédacteur
 
Avatar de Djug
 
Homme
Inscription : mai 2007
Messages : 3 180
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Algérie

Informations forums :
Inscription : mai 2007
Messages : 3 180
Points : 19 506
Points : 19 506
je ne sais pas, j'ai pas touché à JADE depuis presque 2 ans , mais je crois que l'agent DF est la solution pour ta situation.

une autre idée:

créer un agents qui va jouer partiellement le rôle du DF (appelant le SubDF)

dés sa création, chaque agent va lui envoyer un message , et SubDF tiendra une liste qui contient les noms de tous les agents en cours d’exécution.

et donc ce cas la, avant d'envoyer un message aux agents, tu commences tt d'abord par la vérification de leurs existance en envoyant une demande/message au subDF.
__________________
Tweet more than 140 characters with long-tweets.com

Tutoriels JADE (Java Agent DEvelopment Framework)
http://djug.developpez.com

Je ne réponds pas aux questions techniques par Messages privés: les forums sont faits pour ça
Djug est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Actualité déjà publiée
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 06h30.


 
 
 
 
Partenaires

Hébergement Web