Discussion:
[jade-develop] DF Subscription
15490289 at sun.ac.za (Claassen, M, Mnr )
2014-07-21 10:52:25 UTC
Permalink
Good day,

I have solved my own problem. I made the silly mistake of using jade.domain.introspection.ACLMessage instead of jade.lang.acl.ACLMessage.

Silly...silly mistake. :)
________________________________
From: Claassen, M, Mnr <15490289 at sun.ac.za>
Sent: 21 July 2014 12:00 PM
To: jade-develop at avalon.tilab.com
Subject: DF Subscription

Good day,

I would like to get an inform message from the DF when a specific service ("CLAMP") has been registered with the DF. I implemented the code below. I registered an agent that provided a "CLAMP" service with the DF. I sniffed the DF agent and the agent who was supposed to receive the inform message and saw that it successfully received the inform message. However, it does not seem that the program goes into the "handleInform" method. I confirmed this through debugging and through the fact that it does not print the agent name to the console....any ideas why?

DFAgentDescription serviceTemplate = new DFAgentDescription();
ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.setType(AgentConstants.CLAMP);
serviceTemplate.addServices(serviceDescription);

Behaviour b = new SubscriptionInitiator(this, DFService.createSubscriptionMessage(this, getDefaultDF(), serviceTemplate, null)){
protected void handleInform(ACLMessage inform) {
try {
DFAgentDescription[] dfds = DFService.decodeNotification(inform.getPayload());
System.out.println("Agent Name: " +dfds[0].getName());
}
catch (FIPAException fe) {
fe.printStackTrace();
}
}

};
addBehaviour(b);

Kind Regards,

Marius Claassen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140721/1416ee93/attachment.html>
Caire Giovanni
2014-07-21 10:59:28 UTC
Permalink
Hi,

The DFSubscriber class introduced in the latest JADE version (4.3.2) further simplifies DF subscription.
Below an example: we subscribe to be notified when an agent providing a service of type TTT registers with the DF.

DFAgentDescription template = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType("TTT");
template.addServices(sd);
addBehaviour(new DFSubscriber(this, template) {
public void onRegister(DFAgentDescription dfd) {
// An agent providing a service of type TTT is available
...
}

public void onDeregister() {
// An agent that was providing a service of type TTT is no longer available
...
}
});

Bye,

Giovanni


Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di Claassen, M, Mnr <15490289 at sun.ac.za>
Inviato: lunedì 21 luglio 2014 12:52
A: jade-develop at avalon.tilab.com
Oggetto: Re: [jade-develop] DF Subscription

Good day,

I have solved my own problem. I made the silly mistake of using jade.domain.introspection.ACLMessage instead of jade.lang.acl.ACLMessage.

Silly...silly mistake. :)
________________________________
From: Claassen, M, Mnr <15490289 at sun.ac.za>
Sent: 21 July 2014 12:00 PM
To: jade-develop at avalon.tilab.com
Subject: DF Subscription
Good day,

I would like to get an inform message from the DF when a specific service ("CLAMP") has been registered with the DF. I implemented the code below. I registered an agent that provided a "CLAMP" service with the DF. I sniffed the DF agent and the agent who was supposed to receive the inform message and saw that it successfully received the inform message. However, it does not seem that the program goes into the "handleInform" method. I confirmed this through debugging and through the fact that it does not print the agent name to the console....any ideas why?

DFAgentDescription serviceTemplate = new DFAgentDescription();
ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.setType(AgentConstants.CLAMP);
serviceTemplate.addServices(serviceDescription);

Behaviour b = new SubscriptionInitiator(this, DFService.createSubscriptionMessage(this, getDefaultDF(), serviceTemplate, null)){
protected void handleInform(ACLMessage inform) {
try {
DFAgentDescription[] dfds = DFService.decodeNotification(inform.getPayload());
System.out.println("Agent Name: " +dfds[0].getName());
}
catch (FIPAException fe) {
fe.printStackTrace();
}
}

};
addBehaviour(b);

Kind Regards,

Marius Claassen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140721/6c133aee/attachment-0001.html>
15490289 at sun.ac.za (Claassen, M, Mnr )
2014-07-21 21:53:31 UTC
Permalink
Thank you for the hint. I have used the simplified way you suggested and works well.

The onRegister method receives a single DFAgentDescription corresponding to the agent that was registered in the Directory Facilitator. I would like to add the agents that register a particular service with the DF in a global DFAgentDescription array so that I can use the ContractNetResponder class to send cfp's to all the agents with these specific services. Roughly, this is what I have done:

//Declare a global DFAgentDescripton array to store all the agents descriptions with a 'clamp' service.
protected DFAgentDescription[] fClampAgents;
//Global counter to specify fClampAgents element position.
protected int j = 0;
.....

@Override
public void onRegister(DFAgentDescription dfad) {
Iterator it = dfad.getAllServices();
while (it.hasNext()) {
ServiceDescription sd = (ServiceDescription) it.next();
if(sd.getType().equals(AgentConstants.CLAMP)){
fClampAgents[j] = dfad;
j++;
}

However, it unfortunately throws a NULLPointerException pointing to: fClampAgents[j] = dfad.

I cannot seem to figure out the error - whether its a simple array assignment mistake or something deeper than that. On another point - is this a good way to collect AgentDescriptions of a particular service to send cfp's to? I previously used the DFService.search(...) method which returns an DFAgentDescription array of all agents with a particular service. However, I ran this in a behaviour which I feel is inefficient/intensive.

Thanks for the help.

Kind regards,
Marius Claassen
M.Eng (Mechatronics)
Design & Mechatronics Division
Mechatronics, Automation and Design Research Group
Universiteit Stellenbosch University
Tel: +27 83 292 8935

________________________________
From: Caire Giovanni [giovanni.caire at telecomitalia.it]
Sent: 21 July 2014 12:59 PM
To: Claassen, M, Mnr <15490289 at sun.ac.za>; jade-develop at avalon.tilab.com
Subject: R: DF Subscription

Hi,

The DFSubscriber class introduced in the latest JADE version (4.3.2) further simplifies DF subscription.
Below an example: we subscribe to be notified when an agent providing a service of type TTT registers with the DF.

DFAgentDescription template = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType(“TTT”);
template.addServices(sd);
addBehaviour(new DFSubscriber(this, template) {
public void onRegister(DFAgentDescription dfd) {
// An agent providing a service of type TTT is available
...
}

public void onDeregister() {
// An agent that was providing a service of type TTT is no longer available
...
}
});

Bye,

Giovanni


Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di Claassen, M, Mnr <15490289 at sun.ac.za>
Inviato: lunedì 21 luglio 2014 12:52
A: jade-develop at avalon.tilab.com
Oggetto: Re: [jade-develop] DF Subscription

Good day,

I have solved my own problem. I made the silly mistake of using jade.domain.introspection.ACLMessage instead of jade.lang.acl.ACLMessage.

Silly...silly mistake. :)
________________________________
From: Claassen, M, Mnr <15490289 at sun.ac.za>
Sent: 21 July 2014 12:00 PM
To: jade-develop at avalon.tilab.com
Subject: DF Subscription
Good day,

I would like to get an inform message from the DF when a specific service ("CLAMP") has been registered with the DF. I implemented the code below. I registered an agent that provided a "CLAMP" service with the DF. I sniffed the DF agent and the agent who was supposed to receive the inform message and saw that it successfully received the inform message. However, it does not seem that the program goes into the "handleInform" method. I confirmed this through debugging and through the fact that it does not print the agent name to the console....any ideas why?

DFAgentDescription serviceTemplate = new DFAgentDescription();
ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.setType(AgentConstants.CLAMP);
serviceTemplate.addServices(serviceDescription);

Behaviour b = new SubscriptionInitiator(this, DFService.createSubscriptionMessage(this, getDefaultDF(), serviceTemplate, null)){
protected void handleInform(ACLMessage inform) {
try {
DFAgentDescription[] dfds = DFService.decodeNotification(inform.getPayload());
System.out.println("Agent Name: " +dfds[0].getName());
}
catch (FIPAException fe) {
fe.printStackTrace();
}
}

};
addBehaviour(b);

Kind Regards,

Marius Claassen
Questo messaggio e i suoi allegati sono indirizzati esclusivamente alle persone indicate. La diffusione, copia o qualsiasi altra azione derivante dalla conoscenza di queste informazioni sono rigorosamente vietate. Qualora abbiate ricevuto questo documento per errore siete cortesemente pregati di darne immediata comunicazione al mittente e di provvedere alla sua distruzione, Grazie.

This e-mail and any attachments is confidential and may contain privileged information intended for the addressee(s) only. Dissemination, copying, printing or use by anybody else is unauthorised. If you are not the intended recipient, please delete this message and any attachments and advise the sender by return e-mail, Thanks.

[rispetta l'ambiente]Rispetta l'ambiente. Non stampare questa mail se non Ú necessario.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140721/365f48cd/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logo Ambiente_foglia2.jpg
Type: image/jpeg
Size: 677 bytes
Desc: logo Ambiente_foglia2.jpg
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140721/365f48cd/attachment-0001.jpg>
Caire Giovanni
2014-07-24 21:16:45 UTC
Permalink
Hi,

The approach is absolutely correct. The NUllPointerException is likely due to the fact that the fClampAgents array is not initialized.
Furthermore if you don't know a-priori how many agents with the CLAMP service will be there in the system I would suggest using an ArrayList instead of an Arrayto keep them.

Bye,

Giovanni

Da: Claassen, M, Mnr <15490289 at sun.ac.za> [mailto:15490289 at sun.ac.za]
Inviato: lunedì 21 luglio 2014 23:54
A: Caire Giovanni; jade-develop at avalon.tilab.com
Oggetto: RE: DF Subscription

Thank you for the hint. I have used the simplified way you suggested and works well.

The onRegister method receives a single DFAgentDescription corresponding to the agent that was registered in the Directory Facilitator. I would like to add the agents that register a particular service with the DF in a global DFAgentDescription array so that I can use the ContractNetResponder class to send cfp's to all the agents with these specific services. Roughly, this is what I have done:

//Declare a global DFAgentDescripton array to store all the agents descriptions with a 'clamp' service.
protected DFAgentDescription[] fClampAgents;
//Global counter to specify fClampAgents element position.
protected int j = 0;
.....

@Override
public void onRegister(DFAgentDescription dfad) {
Iterator it = dfad.getAllServices();
while (it.hasNext()) {
ServiceDescription sd = (ServiceDescription) it.next();
if(sd.getType().equals(AgentConstants.CLAMP)){
fClampAgents[j] = dfad;
j++;
}

However, it unfortunately throws a NULLPointerException pointing to: fClampAgents[j] = dfad.

I cannot seem to figure out the error - whether its a simple array assignment mistake or something deeper than that. On another point - is this a good way to collect AgentDescriptions of a particular service to send cfp's to? I previously used the DFService.search(...) method which returns an DFAgentDescription array of all agents with a particular service. However, I ran this in a behaviour which I feel is inefficient/intensive.

Thanks for the help.

Kind regards,
Marius Claassen
M.Eng (Mechatronics)
Design & Mechatronics Division
Mechatronics, Automation and Design Research Group
Universiteit Stellenbosch University
Tel: +27 83 292 8935

________________________________
From: Caire Giovanni [giovanni.caire at telecomitalia.it]
Sent: 21 July 2014 12:59 PM
To: Claassen, M, Mnr <15490289 at sun.ac.za>; jade-develop at avalon.tilab.com
Subject: R: DF Subscription
Hi,

The DFSubscriber class introduced in the latest JADE version (4.3.2) further simplifies DF subscription.
Below an example: we subscribe to be notified when an agent providing a service of type TTT registers with the DF.

DFAgentDescription template = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType("TTT");
template.addServices(sd);
addBehaviour(new DFSubscriber(this, template) {
public void onRegister(DFAgentDescription dfd) {
// An agent providing a service of type TTT is available
...
}

public void onDeregister() {
// An agent that was providing a service of type TTT is no longer available
...
}
});

Bye,

Giovanni


Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di Claassen, M, Mnr <15490289 at sun.ac.za>
Inviato: lunedì 21 luglio 2014 12:52
A: jade-develop at avalon.tilab.com
Oggetto: Re: [jade-develop] DF Subscription

Good day,

I have solved my own problem. I made the silly mistake of using jade.domain.introspection.ACLMessage instead of jade.lang.acl.ACLMessage.

Silly...silly mistake. :)
________________________________
From: Claassen, M, Mnr <15490289 at sun.ac.za>
Sent: 21 July 2014 12:00 PM
To: jade-develop at avalon.tilab.com
Subject: DF Subscription
Good day,

I would like to get an inform message from the DF when a specific service ("CLAMP") has been registered with the DF. I implemented the code below. I registered an agent that provided a "CLAMP" service with the DF. I sniffed the DF agent and the agent who was supposed to receive the inform message and saw that it successfully received the inform message. However, it does not seem that the program goes into the "handleInform" method. I confirmed this through debugging and through the fact that it does not print the agent name to the console....any ideas why?

DFAgentDescription serviceTemplate = new DFAgentDescription();
ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.setType(AgentConstants.CLAMP);
serviceTemplate.addServices(serviceDescription);

Behaviour b = new SubscriptionInitiator(this, DFService.createSubscriptionMessage(this, getDefaultDF(), serviceTemplate, null)){
protected void handleInform(ACLMessage inform) {
try {
DFAgentDescription[] dfds = DFService.decodeNotification(inform.getPayload());
System.out.println("Agent Name: " +dfds[0].getName());
}
catch (FIPAException fe) {
fe.printStackTrace();
}
}

};
addBehaviour(b);

Kind Regards,

Marius Claassen
Questo messaggio e i suoi allegati sono indirizzati esclusivamente alle persone indicate. La diffusione, copia o qualsiasi altra azione derivante dalla conoscenza di queste informazioni sono rigorosamente vietate. Qualora abbiate ricevuto questo documento per errore siete cortesemente pregati di darne immediata comunicazione al mittente e di provvedere alla sua distruzione, Grazie.

This e-mail and any attachments is confidential and may contain privileged information intended for the addressee(s) only. Dissemination, copying, printing or use by anybody else is unauthorised. If you are not the intended recipient, please delete this message and any attachments and advise the sender by return e-mail, Thanks.
[cid:image001.gif at 01CFA795.566662F0]Rispetta l'ambiente. Non stampare questa mail se non Ú necessario.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140724/94c66f20/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 677 bytes
Desc: image001.gif
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140724/94c66f20/attachment-0001.gif>
Continue reading on narkive:
Loading...