Defining Multiple Object Types on One Class

In annotation style, you can use one Java class to model two or more managed object types.

Procedure

  1. Annotate the class as @TeaObjectTypes, and include within it a separate @TeaObjectType annotation for each of the object types that the class can represent.

    For example,

    @TeaObjectTypes({
        @TeaObjectType(name = "TOMCAT_SERVER",
            concept = TeaConcept.PROCESS,
            description = "Tomcat Server"),
        @TeaObjectType(name = "TOMCAT_WEBAPP",
            concept = TeaConcept.APPLICATION,
            description = "Tomcat Web Application") })
    public class TomcatServerManager {
        ...
    }
  2. For each object type, define a method that translates from an object key to basic information about the object, and annotate that method as @TeaGetInfo. You must include the objectType attribute in the annotation, to distinguish the object type to which each such method applies.
    @TeaObjectTypes({
        @TeaObjectType(name = "TOMCAT_SERVER",
            concept = TeaConcept.PROCESS,
            description = "Tomcat Server"),
        @TeaObjectType(name = "TOMCAT_WEBAPP",
            concept = TeaConcept.APPLICATION,
            description = "Tomcat Web Application") })
    public class TomcatServerManager {
     
        @TeaGetInfo(objectType = "TOMCAT_SERVER")
        AgentObjectInfo getServerInfo(@KeyParam final String key) {
            ...
        }
     
        @TeaGetInfo(objectType = "TOMCAT_WEBAPP")
        AgentObjectInfo getWebappInfo(@KeyParam final String key) {
            ...
        }
    }
  3. Similarly, include the objectType attribute when modeling aspects such as state, configuration, members, operations and references.