-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiveASKforERBehaviour.java
More file actions
40 lines (37 loc) · 1.19 KB
/
ReceiveASKforERBehaviour.java
File metadata and controls
40 lines (37 loc) · 1.19 KB
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
package com.masim.emissionAgents;
import com.masim.ui.Console;
import com.masim.utils.SimulationFramework;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import jade.lang.acl.*;
/**
* The tickerbehavior of receiving an request for reducing the emission rate.
* @author Sabri Ghazi
*/
public class ReceiveASKforERBehaviour extends TickerBehaviour {
Agent _agnt;
public ReceiveASKforERBehaviour(Agent a, long period) {
super(a, period);
_agnt=a;
}
@Override
protected void onTick() {
ACLMessage amsg=_agnt.receive();
if(amsg!=null){
String msg=amsg.getContent();
if(msg.equalsIgnoreCase("ASK-FOR-ER")){
ACLMessage reply= amsg.createReply();
SourceConfigInfo sourceCFG=SimulationFramework.sourcesInfo.get(_agnt.getLocalName());
reply.setContent(sourceCFG.getEmisionRate()+"");
// Console.logMSG(sourceCFG.getSourceName()+" "+"ASKED to Reduce :"+msg);
// _agnt.send(reply);
}
else
//if(msg.equalsIgnoreCase("ASK-REDUCE-ER"))
{
double val=Double.parseDouble(msg);
((SourceConfigInfo)SimulationFramework.sourcesInfo.get(_agnt.getLocalName())).reduceEmissionBy(val);
}
}
}
}