Declares that the field of an agent should be preserved between activations.
An agent is persistent if it inherits from the
Agent
class and
sets the attribute
persistent
to true (which can be done either
in the agent code of via the command line). The agent stores the information
in a file according the the LAC's setup. All you have to do to make at
attribute persistent is to mark it's declaration with the
@CasaPersistent
annotation. For example:
// a simple persistent boolean attribute that will be stored in the properties under "myFlag"
@CasaPersistent
boolean myFlag;
//a persistent object that will be stored in the properties under "options.x"
//and "options.y" because it has at least one @CasaPersistent attribute itself.
public class Options {
@CasaPersistent int x = 4;
@CasaPersistent double y = 7.5;
}
@CasaPersistent
Options options;
//a persistent object that will be stored in the properties under "stuff" in
//the standard CASA serial format (because none of it's properties are marked
//@CasaPersistent
). Note that the class Stuff MUST have a
//toString()
method and a corresponding constructor that takes a
//single string.
public class Stuff {
int x = 4;
double y = 7.5;
public Stuff() {...}
public Stuff(String persistData) {...}
@Override
public toString() {...}
}
@CasaPersistent
Stuff stuff = new Stuff();