package trafficjams.agents;
import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.TickerBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import trafficjams.model.classes.Auto;
/**
* Created by IntelliJ IDEA.
* User: Администратор
* Date: 04.12.11
* Time: 11:41
* To change this template use File | Settings | File Templates.
*/
public class VehicleDriveAgent extends Agent {
public void setup(){
//this.model = VehicleContainer.MODEL;
try{
ServiceDescription sd = new ServiceDescription();
sd.setType( "VehicleDriveAgent" );
sd.setName( "GuestServiceDescription" );
DFAgentDescription dfd = new DFAgentDescription();
dfd.setName( getAID() );
dfd.addServices( sd );
// register the description with the DF
DFService.register(this, dfd);
this.model = (Auto)this.getArguments()[0];
addBehaviour(new OneShotBehaviour() {
@Override
public void action() {
VehicleDriveAgent.this.model.start(null,0);
}
});
addBehaviour(new TickerBehaviour(this, Auto.MONITOR_INTERVAL_MILLIS) {
@Override
protected void onTick() {
VehicleDriveAgent.this.model.tryToGetNextPosition();
}
});
}catch (Exception e){
e.printStackTrace();
}
}
private Auto model;
}