Package cmion.storage

Class CmionStorageContainer

java.lang.Object
ion.Meta.Element
cmion.architecture.CmionComponent
cmion.storage.CmionStorageContainer
Direct Known Subclasses:
BlackBoard, WorldModel

public class CmionStorageContainer extends CmionComponent
a storage container is used for storing data that is shared between the components. The world model and the black board are examples of storage containers. The way the stored data is organised is as following: A storage container can contain properties and sub containers. Sub Containers in turn contain properties and sub containers again, etc. This way hierarchical knowledge can be stored. Write access to all data is through scheduling requests only (RequestAddSubContainer, RequestRemoveSubContainer, RequestSetProperty, RequestRemoveProperty). All data can be read any time though, but many times registering event handlers will be the preferred method. All sub containers and sub properties are identified through their name, which needs to be unique (among the sibling sub containers and properties respectively). So storage container worldModel cannot have 2 sub containers "John" or 2 properties "date" but Storage containers "John" and "Paul" can both have property "age". Storage containers additionally have a type field (if not needed it should just contain ""), so that the storage hierarchy itself can also contain information about the type of information stored. For example if there are containers for Agents and Objects as in WorldModel, the type can help distinguishing them. For properties the type is not stored explicitly but implicit through the class of the property object.
  • Field Details

    • persistentProperties

      public HashSet<String> persistentProperties
      by default properties are non persistent, if the container has a persistent property it will be in this set here
  • Constructor Details

    • CmionStorageContainer

      protected CmionStorageContainer(IArchitecture architecture, String name, String type, CmionStorageContainer parentContainer)
      create a new CMION Storage Container (this constructor is protected because it should not be accessed from outside) to create a new top level container, use the public constructor)
      Parameters:
      name - the name of this container, should be unique along siblings in storage hierarchy
      type - the type/class of this container
      parentContainer - the container that owns this container or null for a top container in a hierarchy
      architecture - reference to the architecture object
    • CmionStorageContainer

      public CmionStorageContainer(IArchitecture architecture, String name, String type)
      create a new CMION Storage Container
      Parameters:
      name - the name of this container, should be unique along siblings in storage hierarchy
      type - the type/class of this container
      architecture - reference to the architecture object
  • Method Details

    • registerEventHandlerWithSubContainers

      public void registerEventHandlerWithSubContainers(ion.Meta.EventHandler handler)
      registers an Event Handler with all entities this storage component possesses or will possess eventually. This method works recursively, so will also register with all sub containers of sub containers, etc.
    • getSubContainer

      public CmionStorageContainer getSubContainer(String subContainerName)
      returns the sub container with the provided name or null, if there is no such container in this storage container
    • getParentContainer

      public CmionStorageContainer getParentContainer()
      returns the parent container or null if this is the top container of a storage hierarchy
    • getPropertyValue

      public Object getPropertyValue(String propertyName)
      returns the value of the property with the specified name or null if such a property does not exist in this container
    • getContainerName

      public String getContainerName()
      returns the name (identifier) of this container
    • getContainerType

      public String getContainerType()
      returns the type (class) of this container
    • getSubContainerNames

      public ArrayList<String> getSubContainerNames()
      returns a list of all sub container names
    • getSubContainerNames

      public ArrayList<String> getSubContainerNames(String type)
      returns a list of names of all sub containers that have a certain type
    • getPropertyNames

      public ArrayList<String> getPropertyNames()
      returns a list of all property names
    • isPropertyPersistent

      public boolean isPropertyPersistent(String propertyName)
      returns whether a property is persistent or not
      Returns:
      true if persistent, false if not
    • getPropertyNames

      public <T> ArrayList<String> getPropertyNames(Class<T> propertyClass)
      returns a list of names of all properties that are of a certain class
      Type Parameters:
      T - the class we want to find properties of
      Parameters:
      propertyClass - the class represented as a dynamic Class object
      Returns:
      list of names of all properties that are of class T
    • registerHandlers

      public final void registerHandlers()
      registers the request handlers of this storage component class
      Specified by:
      registerHandlers in class CmionComponent
    • hasProperty

      public boolean hasProperty(String name)
      returns whether the container has a property with the specified name
    • hasProperty

      public <T> boolean hasProperty(String name, Class<T> propertyClass)
      returns whether the container has a property with the specified name and of the specified class
    • hasSubContainer

      public boolean hasSubContainer(String name)
      returns whether the container has a sub container with the specified name
    • hasSubContainer

      public boolean hasSubContainer(String name, String type)
      returns whether the container has a sub container with the specified name and of the specified type
    • requestAddSubContainer

      public void requestAddSubContainer(String name, String type, HashMap<String,Object> initialProperties, HashSet<String> persistentProperties)
      convenience method for scheduling a requestAddSubContainer with this container
    • requestAddSubContainer

      public void requestAddSubContainer(String name, String type, HashMap<String,Object> initialProperties)
      convenience method for scheduling a requestAddSubContainer with this container
    • requestAddSubContainer

      public void requestAddSubContainer(String name, String type)
      convenience method for scheduling a requestAddSubContainer with this container
    • requestRemoveSubContainer

      public void requestRemoveSubContainer(String name)
      convenience method for scheduling a requestRemoveSubContainer with this container
    • requestSetProperty

      public void requestSetProperty(String name, Object value)
      convenience method for scheduling a requestSetProperty with this container
    • requestSetProperty

      public void requestSetProperty(String name, Object value, boolean persistent)
      convenience method for scheduling a requestSetProperty with this container
    • requestRemoveProperty

      public void requestRemoveProperty(String name)
      convenience method for scheduling a requestRemoveProperty with this container
    • getTopContainer

      public CmionStorageContainer getTopContainer()
      returns the top container of the storage hierarchy that this container is part of, so typically this should return either the blackboard or the world model object
    • toString

      public String toString()
      Overrides:
      toString in class Object