org.micropsi.nodenet
Class NetEntityManager

java.lang.Object
  extended byorg.micropsi.nodenet.NetEntityManager
All Implemented Interfaces:
NetIntegrityIF

public final class NetEntityManager
extends java.lang.Object
implements NetIntegrityIF

The NetEntityManager keeps record of all existing entities and their states, allowing quick access to all nodes that are currently existing, have recent changes, have been deleted recently, are currently active or are marked "defiant". This is especially important for fast calculation of activation propagation, as, using the NetEntityManager, not all entities have to be regarded when doing the calculations but only those really involved. Besides that, the NetEntityManager allows the observation of the whole net and provides some net-wide services.

It is important to realise that the NetEntityManager is the central management class of a net. Trying to use more than one entity manager within one net would, if possible, be quite pointless.


Field Summary
protected  long netstep
          the current netstep.
 
Fields inherited from interface org.micropsi.nodenet.NetIntegrityIF
BAD_KEY, BAD_LINK, BAD_OUTPUT_FUNCTION, BAD_SLOT, DUPLICATE_KEY, UNKNOWN_ENTITY, UNKNOWN_MODULE
 
Constructor Summary
protected NetEntityManager(Logger logger, LocalNetFacade theFacade)
          Creates a new NetEntityManager
 
Method Summary
protected  java.util.Collection accessActiveEntitiesIDList()
          Returns the (String) IDs of all active entities.
protected  java.util.Collection accessChangedEntitiesIDList()
          Returns the (String) IDs of all changed entities
protected  java.util.Collection accessDefiantEntitiesIDList()
          Returns the (String) IDs of all defiant entities.
protected  java.util.Collection accessDeletedEntitiesIDList()
          Returns the (String) IDs of all deleted entities.
protected  java.util.HashMap accessEntityMap()
          Returns the map of entities.
protected  java.util.Collection accessNewEntitiesIDList()
          Returns the (String) IDs of all new entities.
protected  void addEntity(NetEntity entity)
          Adds an entity to the net.
protected  void buildActiveEntitiesList()
          Rebuilds the list of active entities
protected  void changeParameter(java.lang.String id, int parameterType, int subID, java.lang.String newValue)
          Changes a parameter of an entity or one of it's slots, gates or hidden implementation.
 void checkIntegrity()
          Checks the integrity.
protected  void deleteEntity(NetEntity entity)
          Deletes an entity, unlinking it and preparing the instance for garbage collection.
protected  void deleteEntity(java.lang.String id)
          Deletes an entity, unlinking it and preparing the instance for garbage collection.
protected  void destroy()
          Frees as many references as possible to avoid too much gc activity
protected  void emptyActiveEntityList()
          Clear the list of active entities
 boolean entityExists(java.lang.String id)
          Checks if there is an entity with the given ID
 java.util.Iterator getAllEntities()
          Returns an Iterator with the instances of all NetEntities.
protected  LocalNetFacade getCorrespondingFacade()
          Returns the LocalNetFacade of the net managed by this NetEntityManager.
 NetEntity getEntity(java.lang.String id)
          Retrieves an entity.
protected  Logger getLogger()
          Returns the net's log4j logger.
 long getNetstep()
          Returns the current netstep
protected  long increaseNetStep()
          Increase the net step.
 boolean isDefiant(java.lang.String id)
           
protected  void notifyObservers()
          Notify all observers of all changed, new and deleted entities and clear the list of new and deleted entities.
protected  void prepareLoad(int estimatedNumber)
          Preapares this manager to load a given number of entities
protected  void registerObserver(NetObserverIF newObserver)
          Register an observer for the whole net.
protected  void reportActiveEntity(java.lang.String id)
          Report an entity that has active gates.
protected  void reportChangedEntity(java.lang.String id)
          Report an entity that has changed it's inner state
protected  void reportDefiantEntity(java.lang.String id)
          Mark an entity "defiant"
protected  void reportEndOfDefiance(java.lang.String id)
          End the defiance of the entity.
 java.lang.String reportIntegrityStatus()
          Returns a String with integrity-relevant information about the entity
 void reset()
          Frees as many references as possible to avoid too much gc activity, but keeps the manager intact (for net reload);
protected  void unregisterObserver(NetObserverIF observer)
          Unregister an observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

netstep

protected long netstep
the current netstep. This variable is the mother of all netstep variables - the real one. You know, all the other ones, they are just shadows on the cave's wall.

Constructor Detail

NetEntityManager

protected NetEntityManager(Logger logger,
                           LocalNetFacade theFacade)
Creates a new NetEntityManager

Parameters:
logger - The log4j logger to be used with this net.
Method Detail

prepareLoad

protected void prepareLoad(int estimatedNumber)
Preapares this manager to load a given number of entities

Parameters:
estimatedNumber - the estimated number of entities to be loaded

getCorrespondingFacade

protected LocalNetFacade getCorrespondingFacade()
Returns the LocalNetFacade of the net managed by this NetEntityManager.

Returns:
the facade

addEntity

protected void addEntity(NetEntity entity)
                  throws NetIntegrityException
Adds an entity to the net. Before passed to this method, the entity is not part of the net. Do not link entities that have not been passed to this method, as this will cause NetIntegrityExceptions. Or worse.

Parameters:
entity - the entity - pass all entities here right after creation!
Throws:
NetIntegrityException - if there is already an entity in the net with the same ID.

deleteEntity

protected void deleteEntity(java.lang.String id)
                     throws NetIntegrityException
Deletes an entity, unlinking it and preparing the instance for garbage collection. If the entity is a NodeSpace module, everything contained in the NodeSpace will be deleted also.

Parameters:
id - the ID of the entity to be deleted.
Throws:
NetIntegrityException - if there is no such ID or one of the links of the entity is bad.

deleteEntity

protected void deleteEntity(NetEntity entity)
                     throws NetIntegrityException
Deletes an entity, unlinking it and preparing the instance for garbage collection.

Parameters:
entity - the entity to be deleted.
Throws:
NetIntegrityException - if there is no such ID or one of the links of the entity is bad.

getEntity

public NetEntity getEntity(java.lang.String id)
                    throws NetIntegrityException
Retrieves an entity.

Parameters:
id - the ID of the entity
Returns:
NetEntity the entity
Throws:
NetIntegrityException - if there is no such entity

reportChangedEntity

protected void reportChangedEntity(java.lang.String id)
Report an entity that has changed it's inner state

Parameters:
id - the ID of the entity.

reportActiveEntity

protected void reportActiveEntity(java.lang.String id)
Report an entity that has active gates.

Parameters:
id - the ID of the entity.

reportDefiantEntity

protected void reportDefiantEntity(java.lang.String id)
Mark an entity "defiant"

Parameters:
id - the ID of the entity

reportEndOfDefiance

protected void reportEndOfDefiance(java.lang.String id)
End the defiance of the entity.

Parameters:
id - the ID of the entity.

emptyActiveEntityList

protected void emptyActiveEntityList()
Clear the list of active entities


accessEntityMap

protected java.util.HashMap accessEntityMap()
Returns the map of entities. Know what you're doing when using this hashmap. Don't delete anything - that would cause bad integrity violations.

Returns:
HashMap the hashmap of all entities. THE hashmap.

accessActiveEntitiesIDList

protected java.util.Collection accessActiveEntitiesIDList()
Returns the (String) IDs of all active entities.

Returns:
Collection the IDs

accessChangedEntitiesIDList

protected java.util.Collection accessChangedEntitiesIDList()
Returns the (String) IDs of all changed entities

Returns:
Collection the IDs

accessNewEntitiesIDList

protected java.util.Collection accessNewEntitiesIDList()
Returns the (String) IDs of all new entities.

Returns:
Collection the IDs

accessDeletedEntitiesIDList

protected java.util.Collection accessDeletedEntitiesIDList()
Returns the (String) IDs of all deleted entities.

Returns:
Collection the IDs

accessDefiantEntitiesIDList

protected java.util.Collection accessDefiantEntitiesIDList()
Returns the (String) IDs of all defiant entities.

Returns:
Collection the IDs

isDefiant

public boolean isDefiant(java.lang.String id)

increaseNetStep

protected long increaseNetStep()
Increase the net step. (This is not about running the net. It's merely increasing the netstep variable by one and returning it. For information on running a net, see NetCycle.)

Returns:
long the new netstep
See Also:
NetCycle

getNetstep

public long getNetstep()
Returns the current netstep

Returns:
long the current netstep

registerObserver

protected void registerObserver(NetObserverIF newObserver)
Register an observer for the whole net. (Beware of high load!)

Parameters:
newObserver - the observer to be registered

unregisterObserver

protected void unregisterObserver(NetObserverIF observer)
Unregister an observer.

Parameters:
observer - the observer to be unregistered

notifyObservers

protected void notifyObservers()
Notify all observers of all changed, new and deleted entities and clear the list of new and deleted entities.


getAllEntities

public java.util.Iterator getAllEntities()
Returns an Iterator with the instances of all NetEntities. Don't even think of calling remove().

Returns:
Iterator the entities.

entityExists

public boolean entityExists(java.lang.String id)
Checks if there is an entity with the given ID

Parameters:
id - the id to be checked
Returns:
boolean true if there is an entity with that ID

checkIntegrity

public void checkIntegrity()
                    throws NetIntegrityException
Description copied from interface: NetIntegrityIF
Checks the integrity.

Specified by:
checkIntegrity in interface NetIntegrityIF
Throws:
NetIntegrityException - if the implementation violates the net's integrity.
See Also:
NetIntegrityIF.checkIntegrity()

reportIntegrityStatus

public java.lang.String reportIntegrityStatus()
Description copied from interface: NetIntegrityIF
Returns a String with integrity-relevant information about the entity

Specified by:
reportIntegrityStatus in interface NetIntegrityIF
Returns:
String the status
See Also:
NetIntegrityIF.reportIntegrityStatus()

changeParameter

protected void changeParameter(java.lang.String id,
                               int parameterType,
                               int subID,
                               java.lang.String newValue)
                        throws NetIntegrityException
Changes a parameter of an entity or one of it's slots, gates or hidden implementation. Possible values of parameterType can be found in NetParametersIF.

Parameters:
id - the ID of the entity to be changed
parameterType - the parameter to be changed
subID - the subid. Depending on the parameterType used, this can be the type of a slot, a gate or the key of a parameter of a hidden implementation (typically of a NativeModule)
newValue - The new value as String
Throws:
NetIntegrityException - if the slot or gate was not found
See Also:
NetParametersIF

getLogger

protected Logger getLogger()
Returns the net's log4j logger.

Returns:
Logger

buildActiveEntitiesList

protected void buildActiveEntitiesList()
Rebuilds the list of active entities


destroy

protected void destroy()
Frees as many references as possible to avoid too much gc activity


reset

public void reset()
Frees as many references as possible to avoid too much gc activity, but keeps the manager intact (for net reload);


(c) by Micropsi Project: http://www.cognitive-agents.org

.