Defining an Object Type in Interface Style

To define an object type in interface style, your agent code models a managed object as a Java class that implements appropriate interfaces. Then it registers an instance, which lets the agent library call the interface methods.

We present the general task of defining an object type that can have more than one instance. Singleton object types and top-level object types are special cases; to see how they differ from this general case, see Defining a Singleton Object Type in Interface Style and Defining a Top-Level Object Type in Interface Style.

Procedure

  1. Define a class that models the managed object type. Your class must implement the interface TeaObject. For example, when modeling a car, we could define a class to represent the wheels.
    public class CarWheel implements TeaObject {
    
        public String getName() {
            // Return the name of the wheel instance,
           // for example, "Wheel 1"
        }
    
        public String getDescription() {
            // Return the description of the wheel instance,
            // for example, "Front-Left Wheel"
        }
    
        public String getKey() {
            // Return the key that corresponds to the wheel instance,
            // for example, "Wheel 1"
        }
    }
  2. Define a corresponding provider class that implements the interface TeaObjectProvider.
    public class CarWheelProvider implements TeaObjectProvider<CarWheel> {
    
        public String getTypeName() {
            // Return the name of the wheel object type.
            return "Wheel";
        }
    
        public String getTypeDescription() {
            // Return the description of the wheel object type.
    						  return "Car wheel";
        }
    
        public TeaConcept getConcept() {
            // Return the concept type of wheels.
            return TeaConcept.RESOURCE;
        }
    
        public CarWheel getInstance(final String key) {
            // Return the wheel instance corresponding to the key argument.
            // For example, look-up the key in a hash table.
            ...
        }
    
    }
  3. Register an instance of the provider class.
    CarAgentServer server = ...
    // Register other instances, including the top-level object type.
    CarWheelProvider myCarWheelProvider = new CarWheelProvider;
    server.registerInstance(myCarWheelProvider);
     ...
    server.start();