Discussion:
[jade-develop] DataStore
王肖
2013-11-21 02:07:17 UTC
Permalink
Hi All
I am developing a multi-agent platform,but the useage of DataStore has stumped me,couuld someone tell me how to use the DataStore.
thanks in advance
WangXiao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://avalon.cselt.it/pipermail/jade-develop/attachments/20131121/c1407f04/attachment.html>
Caire Giovanni
2013-11-25 08:28:49 UTC
Permalink
Hi,

The DataStore is just a Map that you can (not must) use to share information among behaviours. For instance you may have 2 behaviours: B1 that produces a value and B2 that requires that value. B1 and B2 are executed sequentially as child of a Sequential Behaviour.
If you want to keep these behaviours loosely coupled you can organize things so that B1 stores the produced value in the Data store at a given key and B2 reads the value it needs from the DataStore at a given key.

public class B1 extends Behaviour {
private String valueKey;

public B1(String k) {
...
valueKey = k;
}
...
public void action() {
...
compute value V
}

public int onEnd() {
// At the end store the produced value in the data store
getDataStore().put(valueKey, V);
return 0;
}
}

public class B2 extends Behaviour {
private String valueKey;

public B2(String k) {
...
valueKey = k;
}
...
public void onStart() {
// Get the required value V from the data store
V = getDataStore(valueKey);
}

public void action() {
Do the job using V
}
}

Then when you instantiate B1 and B2 you pass the same key and the same DataStore to them as below
SequentialBehaviour sb = new SequentialBehaviour();
String key = ?kkk?;
DataStore ds = new DataStore();

Behaviour b1 = new B1(key);
b1.setDataStore(ds);
sb.addSubBehaviour(b1);

Behaviour b2 = new B2(key);
b2.setDataStore(ds);
sb.addSubBehaviour(b2);

addBehaviour(sb);

NOTE that using the DataStore is an option, but it is NOT mandatory.

Bye,

Giovanni

Da: jade-develop-bounces at avalon.tilab.com [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di ??
Inviato: gioved? 21 novembre 2013 03:07
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] DataStore

Hi All
I am developing a multi-agent platform,but the useage of DataStore has stumped me,couuld someone tell me how to use the DataStore.
thanks in advance
WangXiao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://avalon.cselt.it/pipermail/jade-develop/attachments/20131125/704cb9fa/attachment.html>
Loading...