Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 20 – April 2, 2002 Bond Objects.

Similar presentations


Presentation on theme: "Lecture 20 – April 2, 2002 Bond Objects."— Presentation transcript:

1 Lecture 20 – April 2, 2002 Bond Objects

2 Bond objects extend Java objects
Every Bond object is assigned a unique identifier for the lifetime of the object. An entire collection of Bond objects can be identified by an alias. Communication support: All Bond objects are capable of receiving messages. Active objects can also send messages.

3 Bond objects extend Java objects
Bond objects are registered at the creation time with a local directory. They can be found using either the unique identifier or the alias. Lightweight Bond objects (messages and shadows) are registered on demand. All Bond objects are serializable and clonable, while only some Java objects are.

4 Bond objects extend Java objects
Bond objects may have dynamic properties created at run-time, in addition to the regular fields of a Java object. The Bond system extends the Java object model with multiple inheritance using a preprocessor of Java files. All Bond objects can be visually edited.

5 Bond Identifiers bondID= ``bondID'' + bondIPaddress + commEnginePort +
localMillisecondSinceStartOfResident + timeAndDate

6 Bond object registration
public class bondObject implements Serializable, Cloneable { public bondObject() { maybeInformDirectory(); if (bondID != null) { setName(bondID); } } protected void maybeInformDirectory() { try { bondID = dir.getBondID(); dir.register(this); } catch (NullPointerException e) }

7 Bond Resident Initialization
public static void initbond() { bondConfiguration.initSysProperties(); loader = new bondLoader(); dir = new bondDirectory(); com = new bondCommunicator(); conf = new bondConfiguration(); bondMessage.initMessage(); return; }

8 Bond shadows

9 Bond shadows /** Create shadow from bondID and address of object*/ public bondShadow(String remote_bondID, String rem_address){ super(false); this.remote_bondID= remote_bondID; remote_address = new bondIPAddress(rem_address); }

10 Make a local copy of a remote object
public bondObject realize() { bondID = dir.getBondID(); dir.register(this); bondObject bo = null; if (local != null) { return local; } else { bondMessage m =new bondMessage( "(tell :content realize)", "PropertyAccess"); m.setNeedsReply(); say(m, this); m.waitReply(30000); return m.bo; } }

11 Reflection and Introspection in Java
The compilers and linkers for programming languages such as C or C++ usually discard the names of the variables, keeping only their addresses in the compiled code. Java, keeps this information in the compiled class files and allows access to it through a mechanism called reflection. Introspection, the ability to change dynamically the static properties of an object. E.g. Java beans.

12 Dynamic Properties of Bond Objects
Dynamic properties are important for software agents, their functionality makes it difficult to anticipate all the fields of an agent at the instance the agent is created. For efficiency reasons regular Java fields should be used whenever possible, and we should resort to dynamic fields only when the name and/or type of the field is not known at compile time. Dynamic properties have a longer access time than regular Java fields. For remote object}s this difference is masked by the network latency. Compile-time type checking cannot be done for dynamic properties; thus, the programmer looses important type-safety information.

13 Dynamic Properties of Bond Objects
All dynamic properties are considered to be of type Object and any value can be set for them. To delete a dynamic property, the value is set to null. Bond objects implement a common interface with two methods: get and set to access static fields and dynamic properties.

14 get get(String name); -- returns the value of the field or dynamic property called ``name''. Numerical values, which are not objects in Java, are first converted to their object counterpart, e.g., an int is converted to an Integer object. The get function returns null when there is no object or field with the given name.

15 set set(String name, Object value);-- sets the value of the field or dynamic property called name to the value specified by value. If there is no field or dynamic property with the given name, a new dynamic property is created. If there is a field with the given name but its type conflicts with the type of the object value, a casting exception is thrown.

16 Example Assume we have a Bond object foo with boo as a field: foo.set(``boo.name'', ``hector'')}. String val =foo.get(``boo.name'')}

17

18


Download ppt "Lecture 20 – April 2, 2002 Bond Objects."

Similar presentations


Ads by Google