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 Summary
Fields Modifier and Type Field Description java.util.HashSet<java.lang.String>persistentPropertiesby default properties are non persistent, if the container has a persistent property it will be in this set here-
Fields inherited from class cmion.architecture.CmionComponent
architecture
-
-
Constructor Summary
Constructors Modifier Constructor Description CmionStorageContainer(IArchitecture architecture, java.lang.String name, java.lang.String type)create a new CMION Storage ContainerprotectedCmionStorageContainer(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.StringgetContainerName()returns the name (identifier) of this containerjava.lang.StringgetContainerType()returns the type (class) of this containerCmionStorageContainergetParentContainer()returns the parent container or null if this is the top container of a storage hierarchyjava.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 classjava.lang.ObjectgetPropertyValue(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 containerCmionStorageContainergetSubContainer(java.lang.String subContainerName)returns the sub container with the provided name or null, if there is no such container in this storage containerjava.util.ArrayList<java.lang.String>getSubContainerNames()returns a list of all sub container namesjava.util.ArrayList<java.lang.String>getSubContainerNames(java.lang.String type)returns a list of names of all sub containers that have a certain typeCmionStorageContainergetTopContainer()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 objectbooleanhasProperty(java.lang.String name)returns whether the container has a property with the specified name<T> booleanhasProperty(java.lang.String name, java.lang.Class<T> propertyClass)returns whether the container has a property with the specified name and of the specified classbooleanhasSubContainer(java.lang.String name)returns whether the container has a sub container with the specified namebooleanhasSubContainer(java.lang.String name, java.lang.String type)returns whether the container has a sub container with the specified name and of the specified typebooleanisPropertyPersistent(java.lang.String propertyName)returns whether a property is persistent or notvoidregisterEventHandlerWithSubContainers(ion.Meta.EventHandler handler)registers an Event Handler with all entities this storage component possesses or will possess eventually.voidregisterHandlers()registers the request handlers of this storage component classvoidrequestAddSubContainer(java.lang.String name, java.lang.String type)convenience method for scheduling a requestAddSubContainer with this containervoidrequestAddSubContainer(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 containervoidrequestAddSubContainer(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 containervoidrequestRemoveProperty(java.lang.String name)convenience method for scheduling a requestRemoveProperty with this containervoidrequestRemoveSubContainer(java.lang.String name)convenience method for scheduling a requestRemoveSubContainer with this containervoidrequestSetProperty(java.lang.String name, java.lang.Object value)convenience method for scheduling a requestSetProperty with this containervoidrequestSetProperty(java.lang.String name, java.lang.Object value, boolean persistent)convenience method for scheduling a requestSetProperty with this containerjava.lang.StringtoString()-
Methods inherited from class cmion.architecture.CmionComponent
getArchitecture, isConnected, onDestroy, raise
-
-
-
-
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 hierarchytype- the type/class of this containerparentContainer- the container that owns this container or null for a top container in a hierarchyarchitecture- 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 hierarchytype- the type/class of this containerarchitecture- 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:
registerHandlersin classCmionComponent
-
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:
toStringin classjava.lang.Object
-
-