Skip to content

Commit 1966a34

Browse files
committedJun 21, 2014
...
1 parent d609ca7 commit 1966a34

File tree

5 files changed

+470
-228
lines changed

5 files changed

+470
-228
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Global logging properties.
2+
# ------------------------------------------
3+
# The set of handlers to be loaded upon startup.
4+
# Comma-separated list of class names.
5+
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
6+
7+
# Default global logging level.
8+
# Loggers and Handlers may override this level
9+
.level=INFO
10+
11+
# Loggers
12+
# ------------------------------------------
13+
# Loggers are usually attached to packages.
14+
# Here, the level for each package is specified.
15+
# The global level is used by default, so levels
16+
# specified here simply act as an override.
17+
jade.core.level=WARNING
18+
jade.domain.mobility.level=CONFIG
19+
agentville.level=ALL
20+
21+
sun.awt.level=OFF
22+
java.awt.level=OFF
23+
javax.swing.level=OFF
24+
25+
26+
27+
# Handlers
28+
# -----------------------------------------
29+
30+
# --- ConsoleHandler ---
31+
# Override of global logging level
32+
java.util.logging.ConsoleHandler.level=ALL
33+
#SEVERE
34+
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
35+
36+
# --- FileHandler ---
37+
# Override of global logging level
38+
java.util.logging.FileHandler.level=ALL
39+
40+
# Naming style for the output file:
41+
java.util.logging.FileHandler.pattern=target/agentlog-%u.log
42+
43+
# Limiting size of output file in bytes:
44+
java.util.logging.FileHandler.limit=50000
45+
46+
# Number of output files to cycle through, by appending an
47+
# integer to the base file name:
48+
java.util.logging.FileHandler.count=1
49+
50+
# Style of output (Simple or XML):
51+
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
52+
java.util.logging.SimpleFormatter.format=%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s %4$s: %5$s%n

‎agentville-bingo-player/pom.xml

+147-147
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,148 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
5-
<groupId>agentville.agents.bingo.player</groupId>
6-
<artifactId>agentville-bingo-player</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
8-
<packaging>jar</packaging>
9-
10-
<name>Ein JADE Agent</name>
11-
<url>http://agentville.wordpress.com</url>
12-
13-
<properties>
14-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
</properties>
16-
17-
<repositories>
18-
<repository>
19-
<id>tilab</id>
20-
<url>http://jade.tilab.com/maven/</url>
21-
</repository>
22-
</repositories>
23-
24-
<dependencies>
25-
<dependency>
26-
<groupId>com.tilab.jade</groupId>
27-
<artifactId>jade</artifactId>
28-
<version>4.3.0</version>
29-
<scope>compile</scope>
30-
</dependency>
31-
<dependency>
32-
<groupId>com.tilab.jade</groupId>
33-
<artifactId>jade-misc</artifactId>
34-
<version>2.4.0</version>
35-
<scope>compile</scope>
36-
</dependency>
37-
<dependency>
38-
<groupId>com.tilab.jade</groupId>
39-
<artifactId>jade-test-suite</artifactId>
40-
<version>1.11.0</version>
41-
<scope>test</scope>
42-
</dependency>
43-
</dependencies>
44-
45-
<build>
46-
<pluginManagement>
47-
<plugins>
48-
<plugin>
49-
<groupId>org.codehaus.mojo</groupId>
50-
<artifactId>build-helper-maven-plugin</artifactId>
51-
<version>1.8</version>
52-
</plugin>
53-
<plugin>
54-
<groupId>org.eclipse.m2e</groupId>
55-
<artifactId>lifecycle-mapping</artifactId>
56-
<version>1.0.0</version>
57-
<configuration>
58-
<lifecycleMappingMetadata>
59-
<pluginExecutions>
60-
<!-- copy-dependency plugin -->
61-
<pluginExecution>
62-
<pluginExecutionFilter>
63-
<groupId>org.codehaus.mojo</groupId>
64-
<artifactId>build-helper-maven-plugin</artifactId>
65-
<versionRange>[1.8,)</versionRange>
66-
<goals>
67-
<goal>regex-property</goal>
68-
</goals>
69-
</pluginExecutionFilter>
70-
<action>
71-
<ignore />
72-
</action>
73-
</pluginExecution>
74-
</pluginExecutions>
75-
</lifecycleMappingMetadata>
76-
</configuration>
77-
</plugin>
78-
</plugins>
79-
</pluginManagement>
80-
<plugins>
81-
<plugin>
82-
<groupId>org.codehaus.mojo</groupId>
83-
<artifactId>build-helper-maven-plugin</artifactId>
84-
<version>1.8</version>
85-
<executions>
86-
<execution>
87-
<id>regex-property</id>
88-
<goals>
89-
<goal>regex-property</goal>
90-
</goals>
91-
<configuration>
92-
<name>project.group_Id</name>
93-
<value>${project.groupId}</value>
94-
<regex>[\.]</regex>
95-
<replacement>_</replacement>
96-
<failIfNoMatch>false</failIfNoMatch>
97-
</configuration>
98-
</execution>
99-
</executions>
100-
</plugin>
101-
<plugin>
102-
<groupId>org.apache.maven.plugins</groupId>
103-
<artifactId>maven-jar-plugin</artifactId>
104-
<version>2.4</version>
105-
<configuration>
106-
<archive>
107-
<!-- Erweitert das default-Manifest: -->
108-
<manifest>
109-
<mainClass>${project.groupId}.AgentStarter</mainClass>
110-
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
111-
</manifest>
112-
</archive>
113-
</configuration>
114-
<executions>
115-
<!-- Hier wird ein zusätzliches JAR erzeugt, das den Konventionen von
116-
JADE entspricht und so auch ohne Main-Methode ausgeführt oder über den
117-
RMA in einen schon laufenden Container importiert werden kann. -->
118-
<execution>
119-
<id>jade-agent</id>
120-
<goals><goal>jar</goal></goals>
121-
<phase>package</phase>
122-
<configuration>
123-
<finalName>${project.group_Id}_MyAgent</finalName>
124-
</configuration>
125-
</execution>
126-
</executions>
127-
</plugin>
128-
129-
<!-- <plugin> -->
130-
<!-- <artifactId>maven-surefire-plugin</artifactId> -->
131-
<!-- <configuration> -->
132-
<!-- <systemProperties> -->
133-
<!-- <property> -->
134-
<!-- <name>java.util.logging.config.file</name> -->
135-
<!-- <value>src/main/resources/myLogging.properties</value> -->
136-
<!-- </property> -->
137-
<!-- <property> -->
138-
<!-- <name>testlog.dir</name> -->
139-
<!-- <value>${project.build.directory}</value> -->
140-
<!-- </property> -->
141-
<!-- </systemProperties> -->
142-
<!-- </configuration> -->
143-
<!-- </plugin> -->
144-
145-
146-
</plugins>
147-
</build>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>agentville.agents.bingo.player</groupId>
6+
<artifactId>agentville-bingo-player</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>JADE Bingo Player</name>
11+
<url>http://agentville.wordpress.com</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<repositories>
18+
<repository>
19+
<id>tilab</id>
20+
<url>http://jade.tilab.com/maven/</url>
21+
</repository>
22+
</repositories>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>com.tilab.jade</groupId>
27+
<artifactId>jade</artifactId>
28+
<version>4.3.0</version>
29+
<scope>compile</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.tilab.jade</groupId>
33+
<artifactId>jade-misc</artifactId>
34+
<version>2.4.0</version>
35+
<scope>compile</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.tilab.jade</groupId>
39+
<artifactId>jade-test-suite</artifactId>
40+
<version>1.11.0</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<pluginManagement>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.codehaus.mojo</groupId>
50+
<artifactId>build-helper-maven-plugin</artifactId>
51+
<version>1.8</version>
52+
</plugin>
53+
<plugin>
54+
<groupId>org.eclipse.m2e</groupId>
55+
<artifactId>lifecycle-mapping</artifactId>
56+
<version>1.0.0</version>
57+
<configuration>
58+
<lifecycleMappingMetadata>
59+
<pluginExecutions>
60+
<!-- copy-dependency plugin -->
61+
<pluginExecution>
62+
<pluginExecutionFilter>
63+
<groupId>org.codehaus.mojo</groupId>
64+
<artifactId>build-helper-maven-plugin</artifactId>
65+
<versionRange>[1.8,)</versionRange>
66+
<goals>
67+
<goal>regex-property</goal>
68+
</goals>
69+
</pluginExecutionFilter>
70+
<action>
71+
<ignore />
72+
</action>
73+
</pluginExecution>
74+
</pluginExecutions>
75+
</lifecycleMappingMetadata>
76+
</configuration>
77+
</plugin>
78+
</plugins>
79+
</pluginManagement>
80+
<plugins>
81+
<plugin>
82+
<groupId>org.codehaus.mojo</groupId>
83+
<artifactId>build-helper-maven-plugin</artifactId>
84+
<version>1.8</version>
85+
<executions>
86+
<execution>
87+
<id>regex-property</id>
88+
<goals>
89+
<goal>regex-property</goal>
90+
</goals>
91+
<configuration>
92+
<name>project.group_Id</name>
93+
<value>${project.groupId}</value>
94+
<regex>[\.]</regex>
95+
<replacement>_</replacement>
96+
<failIfNoMatch>false</failIfNoMatch>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-jar-plugin</artifactId>
104+
<version>2.4</version>
105+
<configuration>
106+
<archive>
107+
<!-- Erweitert das default-Manifest: -->
108+
<manifest>
109+
<mainClass>${project.groupId}.AgentStarter</mainClass>
110+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
111+
</manifest>
112+
</archive>
113+
</configuration>
114+
<executions>
115+
<!-- Hier wird ein zusätzliches JAR erzeugt, das den Konventionen von
116+
JADE entspricht und so auch ohne Main-Methode ausgeführt oder über den
117+
RMA in einen schon laufenden Container importiert werden kann. -->
118+
<execution>
119+
<id>jade-agent</id>
120+
<goals><goal>jar</goal></goals>
121+
<phase>package</phase>
122+
<configuration>
123+
<finalName>${project.group_Id}_MyAgent</finalName>
124+
</configuration>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
129+
<!-- <plugin> -->
130+
<!-- <artifactId>maven-surefire-plugin</artifactId> -->
131+
<!-- <configuration> -->
132+
<!-- <systemProperties> -->
133+
<!-- <property> -->
134+
<!-- <name>java.util.logging.config.file</name> -->
135+
<!-- <value>src/main/resources/myLogging.properties</value> -->
136+
<!-- </property> -->
137+
<!-- <property> -->
138+
<!-- <name>testlog.dir</name> -->
139+
<!-- <value>${project.build.directory}</value> -->
140+
<!-- </property> -->
141+
<!-- </systemProperties> -->
142+
<!-- </configuration> -->
143+
<!-- </plugin> -->
144+
145+
146+
</plugins>
147+
</build>
148148
</project>
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,112 @@
1-
package agentville.agents.bingo.player;
2-
3-
import jade.core.Profile;
4-
import jade.core.ProfileImpl;
5-
import jade.core.Runtime;
6-
import jade.wrapper.AgentContainer;
7-
import jade.wrapper.AgentController;
8-
import jade.wrapper.StaleProxyException;
9-
10-
public class AgentStarter {
11-
12-
public static void main(String[] args){
13-
14-
String host;
15-
int port;
16-
String platform = null; //default name
17-
boolean main = true;
18-
19-
host = "localhost";
20-
port = -1; //default-port 1099
21-
22-
Runtime runtime = Runtime.instance();
23-
24-
Profile profile = null;
25-
AgentContainer container = null;
26-
27-
profile = new ProfileImpl(host, port, platform, main);
28-
29-
//Container erzeugen
30-
container = runtime.createMainContainer(profile);
31-
32-
// Agent rmagent = new jade.tools.rma.rma();
33-
// // Remote Monitoring Agenten erzeugen
34-
// try {
35-
// AgentController rma = container.acceptNewAgent(
36-
// "RMA",
37-
// rmagent
38-
// );
39-
// rma.start();
40-
// } catch(StaleProxyException e) {
41-
// throw new RuntimeException(e);
42-
// }
43-
44-
45-
// Agenten erzeugen und startet - oder aussteigen.
46-
try {
47-
AgentController agent = container.createNewAgent(
48-
"MyAgent",
49-
MyAgent.class.getName(),
50-
args);
51-
agent.start();
52-
} catch(StaleProxyException e) {
53-
throw new RuntimeException(e);
54-
}
55-
}
56-
}
1+
package agentville.agents.bingo.player;
2+
3+
import java.util.logging.LogManager;
4+
5+
import jade.core.Agent;
6+
import jade.core.Profile;
7+
import jade.core.ProfileImpl;
8+
import jade.core.Runtime;
9+
import jade.wrapper.AgentContainer;
10+
import jade.wrapper.AgentController;
11+
import jade.wrapper.StaleProxyException;
12+
13+
14+
/**
15+
* Die Implementierung der Main-Methode erzeugt einen lokalen
16+
* JADE-Main-Container mit RMA. Die damit erzeugte Plattform
17+
* ist die Testumgegung für die Entwicklung des Agenten und er-
18+
* möglicht so eine kontrollierte Umgebung. Eine "produktive"
19+
* Umgebung wird dadurch aber nicht erzeugt.
20+
*
21+
* @author Marco Steffens
22+
*
23+
*/
24+
public class AgentStarter {
25+
26+
public static void main(String[] args){
27+
28+
String host = "localhost";
29+
int port = -1; //default port 1099
30+
String platform = null; //default name
31+
boolean main = true; //erzeugt wird ein main-Container
32+
33+
//die projekteigene Konfiguration für das Logging laden
34+
configureLogging();
35+
36+
Runtime runtime = Runtime.instance();
37+
38+
Profile profile = null;
39+
AgentContainer container = null;
40+
41+
profile = new ProfileImpl(host, port, platform, main);
42+
43+
//Container erzeugen
44+
container = runtime.createMainContainer(profile);
45+
46+
//GUI wollen wir auch
47+
startingRemoteMonitoringAgent(container);
48+
49+
// Agenten erzeugen und startet.
50+
startingThisAgent(args, container);
51+
}
52+
53+
/*
54+
* Startet den eigentlichen Agenten, also DIESEN Agenten.
55+
*/
56+
private static void startingThisAgent(String[] args, AgentContainer container) {
57+
58+
try {
59+
AgentController agent = container.createNewAgent(
60+
"bingo-player",
61+
MyAgent.class.getName(),
62+
args);
63+
agent.start();
64+
} catch(StaleProxyException e) {
65+
throw new RuntimeException(e);
66+
}
67+
}
68+
69+
/*
70+
* Der RMA stellt das JADE-GUI zur Verfügung.
71+
*/
72+
private static void startingRemoteMonitoringAgent(AgentContainer container) {
73+
74+
Agent remoteManagementAgent = new jade.tools.rma.rma();
75+
76+
try {
77+
AgentController rma = container.acceptNewAgent(
78+
"RMA",
79+
remoteManagementAgent);
80+
rma.start(); }
81+
catch(StaleProxyException e) {
82+
throw new RuntimeException(e); }
83+
}
84+
85+
/*
86+
* Das Logging-System von JADE basiert auf java.util.logging, und im
87+
* Zusammenhang mit Maven bringt das ein paar Probleme mit sich. Einmal
88+
* weil Java die Konfigurationsdatei per default im Installationsverzeichnis
89+
* des SDK sucht. Und dann noch weil der Logging-Agent von JADE nur ganz
90+
* am Anfang die Konfiguration einliest und sich nicht mehr umkonfigurieren
91+
* lässt. Das bedeutet:
92+
* Da wir in einem Maven-Projekt alle relevanten Konfigurationsdateien im
93+
* Projektverzeichnis ablegen wollen, müssen wir den Pfad dahin noch irgendwie
94+
* innerhalb unserer VM bekannt machen. Einer der üblichen Wege ist die Übergabe
95+
* als VM-Parameter beim Start, aber da wir unsere Agenten auf verschiedene Arten
96+
* starten wollen, bietet sich das nicht an. Da andererseites der Logging-Agent
97+
* die Konfiguration aber nur beim Start einliest, muss die Konfiguration VOR dem
98+
* Erzeugen der Plattform stattfinden. Und das ist genau hier. Das heißt aber auch,
99+
* dass bei allen Startarten, die die Main-Methode umgehen, die jeweils lokal
100+
* vorhandene Konfigurationsdatei verwendet wird.
101+
*/
102+
private static void configureLogging() {
103+
104+
System.setProperty( "java.util.logging.config.file",
105+
"src/main/resources/logging.properties" );
106+
107+
try {
108+
LogManager.getLogManager().readConfiguration(); }
109+
catch ( Exception e ) {
110+
e.printStackTrace(); }
111+
}
112+
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,117 @@
1-
package agentville.agents.bingo.player;
2-
3-
import jade.core.Agent;
4-
import jade.util.Logger;
5-
6-
public class MyAgent extends Agent {
7-
8-
// Logger logger = jade.util.Logger.getMyLogger(this.getClass().getName());
9-
10-
private static final long serialVersionUID = 1L;
11-
12-
protected void setup() {
13-
14-
try {
15-
Thread.sleep(10000);
16-
} catch(InterruptedException ex) {
17-
Thread.currentThread().interrupt();
18-
}
19-
20-
// if (logger.isLoggable(jade.util.Logger.WARNING))
21-
// logger.log(jade.util.Logger.WARNING, "greetings from setup()");
22-
23-
System.out.println("Hello Eclipse! This is "
24-
+ getLocalName());
25-
}
1+
package agentville.agents.bingo.player;
2+
3+
import jade.core.AID;
4+
import jade.core.Agent;
5+
import jade.domain.DFService;
6+
import jade.domain.FIPAException;
7+
import jade.domain.FIPAAgentManagement.DFAgentDescription;
8+
import jade.domain.FIPAAgentManagement.ServiceDescription;
9+
import jade.util.Logger;
10+
import agentville.agents.bingo.player.behaviours.KeepAliveBehaviour;
11+
12+
/**
13+
* Die Implementierung des Agenten.
14+
*
15+
* @author Marco
16+
*
17+
*/
18+
public class MyAgent extends Agent {
19+
20+
private static final long serialVersionUID = 1L;
21+
22+
private static final Logger logger = jade.util.Logger.getMyLogger(
23+
MyAgent.class.getName());
24+
25+
/*
26+
* (non-Javadoc)
27+
* @see jade.core.Agent#setup()
28+
*/
29+
protected void setup() {
30+
31+
if (logger.isLoggable(jade.util.Logger.WARNING))
32+
logger.log(jade.util.Logger.WARNING,
33+
"setup() Agent " + getLocalName());
34+
35+
//create and register the bingo service in the yellow pages
36+
// createAndRegisterBingoService();
37+
38+
/*
39+
* - Nach dem Conferencier-Agenten (bzw. dessen Bingo-Service) suchen
40+
* - dort anmelden
41+
* - auf zahlen warten
42+
* - zahl verarbeiten
43+
* - wenn alle zahlen genannt wurden: "bingo" an den conf. senden
44+
* - antwort verarbeiten.
45+
* - wieder von vorne.
46+
*/
47+
48+
DFAgentDescription template = new DFAgentDescription();
49+
ServiceDescription sd = new ServiceDescription();
50+
sd.setType("bingo");
51+
template.addServices(sd);
52+
try {
53+
DFAgentDescription[] result = DFService.search(this, template);
54+
AID conferencier = new AID();
55+
for (int i = 0; i < result.length; ++i) {
56+
if (result[i].getName().toString() == "agentville-bingo") {
57+
conferencier = result[i].getName();
58+
}
59+
}
60+
} catch (FIPAException fe) {
61+
fe.printStackTrace();
62+
63+
}
64+
65+
//Der/die/das Behaviour wird ausgeführt, sobald hier die
66+
//setup()-Methode abgearbeitet wird. Also danach läuft
67+
//wohl der Scheduler an und führt den ersten Behaviour aus?
68+
KeepAliveBehaviour kab = new KeepAliveBehaviour(this);
69+
this.addBehaviour(kab);
70+
71+
}
72+
73+
// /*
74+
// * create and register the bingo service in the yellow pages
75+
// */
76+
// private void createAndRegisterBingoService() {
77+
// DFAgentDescription dfd = new DFAgentDescription();
78+
// dfd.setName(getAID());
79+
// ServiceDescription sd = new ServiceDescription();
80+
// sd.setType("bingo");
81+
// sd.setName("agentville-bingo");
82+
// //add language/ontology?
83+
// dfd.addServices(sd);
84+
// try {
85+
// DFService.register(this, dfd); }
86+
// catch (FIPAException fe) {
87+
// if (logger.isLoggable(jade.util.Logger.WARNING))
88+
// logger.log(jade.util.Logger.WARNING,
89+
// "Exception in setup(): " + fe.getStackTrace());
90+
// fe.printStackTrace();
91+
// }
92+
// }
93+
94+
/*
95+
* Die takeDown-Methode wird automatisch ausgeführt, wenn der Agent
96+
* per "doDelete()" gelöscht wird. Hier wäre also der richtige Ort
97+
* fuer Aufraeumarbeiten.
98+
*
99+
* @see jade.core.Agent#takeDown()
100+
*/
101+
protected void takeDown() {
102+
if (logger.isLoggable(jade.util.Logger.WARNING))
103+
logger.log(jade.util.Logger.WARNING, "takeDown");
104+
105+
// try {
106+
// DFService.deregister(this); }
107+
// catch (FIPAException fe) {
108+
// if (logger.isLoggable(jade.util.Logger.WARNING))
109+
// logger.log(jade.util.Logger.WARNING,
110+
// "Exception in setup(): " + fe.getStackTrace());
111+
// fe.printStackTrace();
112+
// }
113+
114+
if (logger.isLoggable(jade.util.Logger.WARNING))
115+
logger.log(jade.util.Logger.WARNING, "Agent bingo conferencier terminating");
116+
}
26117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package agentville.agents.bingo.player.behaviours;
2+
3+
import jade.core.Agent;
4+
import jade.core.behaviours.CyclicBehaviour;
5+
import jade.lang.acl.ACLMessage;
6+
import jade.util.Logger;
7+
8+
public class KeepAliveBehaviour extends CyclicBehaviour {
9+
10+
private static final long serialVersionUID = 1L;
11+
12+
private static final Logger logger = jade.util.Logger.getMyLogger(
13+
KeepAliveBehaviour.class.getName());
14+
15+
Agent agent = null;
16+
17+
public KeepAliveBehaviour(Agent a) {
18+
super(a);
19+
agent = a;
20+
}
21+
22+
/*
23+
* (non-Javadoc)
24+
* @see jade.core.behaviours.Behaviour#action()
25+
*/
26+
@Override
27+
public void action() {
28+
29+
ACLMessage msg = agent.receive();
30+
if (msg != null) {
31+
if (logger.isLoggable(jade.util.Logger.INFO))
32+
logger.log(jade.util.Logger.INFO, "processing message");
33+
} else {
34+
block();
35+
}
36+
37+
//Der Agent bleibt normalerweise am Leben, auch wenn kein Behaviour
38+
//mehr abgearbeitet wird. Und er kann dann auch noch Messages bekommen
39+
//und seine Arbeit wieder aufnehmen(TODO: stimmt das?)
40+
//Hier wollen wir das aber nicht, deshalb wird der Agent hier terminiert.
41+
//this.getAgent().doDelete();
42+
}
43+
}

0 commit comments

Comments
 (0)
Please sign in to comment.