Package cmion.storage

Class 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 Summary

      Fields 
      Modifier and Type Field Description
      java.util.HashSet<java.lang.String> persistentProperties
      by default properties are non persistent, if the container has a persistent property it will be in this set here
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        CmionStorageContainer​(IArchitecture architecture, java.lang.String name, java.lang.String type)
      create a new CMION Storage Container
      protected CmionStorageContainer​(IArchitecture architecture, java.lang.String name, java.lang.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)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getContainerName()
      returns the name (identifier) of this container
      java.lang.String getContainerType()
      returns the type (class) of this container
      CmionStorageContainer getParentContainer()
      returns the parent container or null if this is the top container of a storage hierarchy
      java.util.ArrayList<java.lang.String> getPropertyNames()
      returns a list of all property names
      <T> java.util.ArrayList<java.lang.String> getPropertyNames​(java.lang.Class<T> propertyClass)
      returns a list of names of all properties that are of a certain class
      java.lang.Object getPropertyValue​(java.lang.String propertyName)
      returns the value of the property with the specified name or null if such a property does not exist in this container
      CmionStorageContainer getSubContainer​(java.lang.String subContainerName)
      returns the sub container with the provided name or null, if there is no such container in this storage container
      java.util.ArrayList<java.lang.String> getSubContainerNames()
      returns a list of all sub container names
      java.util.ArrayList<java.lang.String> getSubContainerNames​(java.lang.String type)
      returns a list of names of all sub containers that have a certain type
      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
      boolean hasProperty​(java.lang.String name)
      returns whether the container has a property with the specified name
      <T> boolean hasProperty​(java.lang.String name, java.lang.Class<T> propertyClass)
      returns whether the container has a property with the specified name and of the specified class
      boolean hasSubContainer​(java.lang.String name)
      returns whether the container has a sub container with the specified name
      boolean hasSubContainer​(java.lang.String name, java.lang.String type)
      returns whether the container has a sub container with the specified name and of the specified type
      boolean isPropertyPersistent​(java.lang.String propertyName)
      returns whether a property is persistent or not
      void registerEventHandlerWithSubContainers​(ion.Meta.EventHandler handler)
      registers an Event Handler with all entities this storage component possesses or will possess eventually.
      void registerHandlers()
      registers the request handlers of this storage component class
      void requestAddSubContainer​(java.lang.String name, java.lang.String type)
      convenience method for scheduling a requestAddSubContainer with this container
      void requestAddSubContainer​(java.lang.String name, java.lang.String type, java.util.HashMap<java.lang.String,​java.lang.Object> initialProperties)
      convenience method for scheduling a requestAddSubContainer with this container
      void requestAddSubContainer​(java.lang.String name, java.lang.String type, java.util.HashMap<java.lang.String,​java.lang.Object> initialProperties, java.util.HashSet<java.lang.String> persistentProperties)
      convenience method for scheduling a requestAddSubContainer with this container
      void requestRemoveProperty​(java.lang.String name)
      convenience method for scheduling a requestRemoveProperty with this container
      void requestRemoveSubContainer​(java.lang.String name)
      convenience method for scheduling a requestRemoveSubContainer with this container
      void requestSetProperty​(java.lang.String name, java.lang.Object value)
      convenience method for scheduling a requestSetProperty with this container
      void requestSetProperty​(java.lang.String name, java.lang.Object value, boolean persistent)
      convenience method for scheduling a requestSetProperty with this container
      java.lang.String toString()  
      • Methods inherited from class ion.Meta.Element

        destroy, getEventFilters, getEventHandlers, getRequestFilters, getRequestHandlers, getSimulation, getUID, schedule, wasDestroyed
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • persistentProperties

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

      • CmionStorageContainer

        protected CmionStorageContainer​(IArchitecture architecture,
                                        java.lang.String name,
                                        java.lang.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,
                                     java.lang.String name,
                                     java.lang.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 Detail

      • 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​(java.lang.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 java.lang.Object getPropertyValue​(java.lang.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 java.lang.String getContainerName()
        returns the name (identifier) of this container
      • getContainerType

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

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

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

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

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

        public <T> java.util.ArrayList<java.lang.String> getPropertyNames​(java.lang.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​(java.lang.String name)
        returns whether the container has a property with the specified name
      • hasProperty

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

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

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

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

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

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

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

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

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

        public void requestRemoveProperty​(java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object