Agents and the Serializable Interface

In developing Concordia Agents, the programmer should be familiar with the java.io.Serializable interface. Java Object Serialization allows a Java object to be written to and read from standard Java IO streams. Java Object Serialization is utilized internally by Concordia to perform some file and network IO of agents and related objects. Any object which is to be used in conjunction with Java Object Serialization must implement either the Serializable interface or the similar Externalizable interface. These interfaces indicate that the class is compatible with the Object Serialization facility and can provide methods through which a programmer can control the serialization process.

Within Concordia, it is required that agents, all objects stored within the member variables of agent, and any other object contained within those member objects must implement either the Serializable interface or the Externalizable interface. The base class COM.meitca.concordia.Agent already implements the Serializable interface, so any derived agents will automatically inherit Serializable. Because of this, in general agent programmers will not have to be concerned with ensuring that their agents are Serializable or Externalizable. Agent programmers must, however, ensure that any objects stored in the member variables of an agent are Serializable or Externalizable.

In the above example, the DBAccessAgent contains one member variable, a QueryResult object called itsResult. Since the QueryResult object travels with the agent, the programmer must guarantee that it is serializable. In the above example, QueryResult implements the Serializable interface, and thus is compatible with Java Object Serialization. Further, each QueryResult object contains two member variables both of which are String objects. String objects are themselves serializable and are compatible with Java Object Serialization.