I have the code below:
public class PatientAgent extends Agent {
private final String HYPHEN = "-";
private ArrayList<HashSet<Integer>> prefs;
private AID provider ;
private boolean hasAppointment;
private int appointmentNo;
@Override
protected void setup() {
hasAppointment = false;
appointmentNo = 0; // A value of zero means agent does not have any
// allocated appointments (yet)
initPrefs(getArguments());
System.out.println(prefs.toString());
// Build the description used as template for the subscription
DFAgentDescription template = new DFAgentDescription();
ServiceDescription templateSd = new ServiceDescription();
templateSd.setType("allocate-appointments");
template.addServices(templateSd);
SearchConstraints sc = new SearchConstraints();
// We want to receive 10 results at most
sc.setMaxResults(new Long(10));
addBehaviour(new SubscriptionInitiator(this, DFService.createSubscriptionMessage(this, getDefaultDF(), template, sc)) {
protected void handleInform(ACLMessage inform) {
System.out.println("Agent "+getLocalName()+": Notification received from DF");
try {
DFAgentDescription[] results = DFService.decodeNotification(inform.getContent());
if (results.length > 0) {
// Assume there is only one hospital agent
assert(results.length == 1);
DFAgentDescription dfd = results[0];
Iterator it = dfd.getAllServices();
while (it.hasNext()) {
ServiceDescription sd = (ServiceDescription) it.next();
if (sd.getType().equals("allocate-appointments")) {
provider = dfd.getName();
System.out.println("Allocate-appointments service found:");
System.out.println("- Service \""+sd.getName()+"\" provided by agent "+provider.getName());
}
}
}
}
catch (FIPAException fe) {
fe.printStackTrace();
}
}
} );
public AID getProvider() { return provider; }
I clearly init provider with the line
provider = dfd.getName();
However the line
public AID getProvider() { return provider; }
returns null for it which I dont get why. Anyone has an idea about whats going on ?
if+while+if?