cz.cuni.amis.pogamut.ut2004multi.communication.module
Class SharedKnowledgeDatabase

Package class diagram package SharedKnowledgeDatabase
java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004multi.communication.module.SharedKnowledgeDatabase

public class SharedKnowledgeDatabase
extends Object

Manages shared knowledge for agent teams. The class is managed - meaning only one instance can exist for each team. Beware that this class can only be used when you are running all your agents from a single JVM. This means you have to used the new MultipleAgentRunner to run your team. Then each agent has to register with this database by calling addAgent(IAgentId, IVisionWorldView, int) with the specific parameters. After that, the database should be ready for use.

Author:
srlok, Jimmy

Field Summary
protected  cz.cuni.amis.utils.concurrency.AtomicLongList agentLockTimes
          agentLockTimes[agentNumber] == lock time the agent owns (or -1 for no-lock)
protected  Map<IAgentId,IVisionWorldView> agentWorldViews
          Maps the agentIds to their concrete worldViews - these are then used in getting the local object information and to attach the listeners
protected  Map<IAgentId,TimeKey> currentTimeKeys
          The current TimeKey handled by an agent
protected  cz.cuni.amis.utils.maps.HashMapMap<WorldObjectId,PropertyId,ISharedProperty> currSharedProperties
          The most recent versions of sharedProperties
protected  HashMap<TimeKey,Set<IAgentId>> heldKeys
          Currently 'locked' timeKeys (with agents locking the keys) - we need to keep objects for those
protected static Map<Integer,SharedKnowledgeDatabase> instances
          Team number to instance.
protected  Map<WorldObjectId,Long> lastUpdateTime
          Holds the last time when an update event was recieved from any agent for each object
protected  Map<IAgentId,Set<IWorldObjectEventListener>> listeners
          Remembers all the listeners added for an agent, this is needed to properly remove them when a agent unregisters from the database
protected  cz.cuni.amis.utils.maps.SyncHashMap<IAgentId,Integer> registeredAgents
          Which agents are registered here mapped to their agent-numbers.
protected  Set<Class> registeredClasses
          Classes for which the database processes events
protected  cz.cuni.amis.utils.maps.WeakHashTriMap<TimeKey,WorldObjectId,PropertyId,ISharedProperty> sharedProperties
          Just holds the weakly referenced shared properties for the worldObjects
protected  int team
          Team number for which the shared knowledge database was constructed for.
 
Constructor Summary
protected SharedKnowledgeDatabase(int team)
           
 
Method Summary
 void addAgent(IAgentId id, IVisionWorldView agentWorldView, int team)
          Registers an agent to the database - it will process it's relevant events from now on.
protected  void addClassListener(IVisionWorldView wv, Class c, IAgentId agentId)
          Helper method to add a single objectEventListener for Class c to a specific WorldView
 void addObjectClass(Class c)
          Registers the provided class as a class of interest.
protected  void addTimeLock(TimeKey timeKey, IAgentId id)
          Locks the specified time and all greater times with the agentId
static SharedKnowledgeDatabase get(int team)
          Returns the only instance of SharedKnowledgeDatabase for the specified team.
 IWorldObject getObject(WorldObjectId id, IAgentId agentId)
          Returns the specified object with the team shared knowledge put in
protected  void processObjEvent(IWorldObjectEvent<IWorldObject> event, IAgentId agentId)
          Handles processing of an object event raised on any of the worldViews.
 boolean removeAgent(IAgentId id)
          Unregister the agent from the database -> the database will no longer process events from this agent.
 boolean removeObjectClass(Class c)
          Stops processing events for the specified class.
protected  void removeTimeLock(TimeKey timeKey, IAgentId id)
          Removes a single lock for this timeKey, if it is the last, the whole lock is removed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instances

protected static Map<Integer,SharedKnowledgeDatabase> instances
Team number to instance.


registeredAgents

protected cz.cuni.amis.utils.maps.SyncHashMap<IAgentId,Integer> registeredAgents
Which agents are registered here mapped to their agent-numbers.


team

protected int team
Team number for which the shared knowledge database was constructed for.


agentLockTimes

protected cz.cuni.amis.utils.concurrency.AtomicLongList agentLockTimes
agentLockTimes[agentNumber] == lock time the agent owns (or -1 for no-lock)


agentWorldViews

protected Map<IAgentId,IVisionWorldView> agentWorldViews
Maps the agentIds to their concrete worldViews - these are then used in getting the local object information and to attach the listeners


listeners

protected Map<IAgentId,Set<IWorldObjectEventListener>> listeners
Remembers all the listeners added for an agent, this is needed to properly remove them when a agent unregisters from the database


sharedProperties

protected cz.cuni.amis.utils.maps.WeakHashTriMap<TimeKey,WorldObjectId,PropertyId,ISharedProperty> sharedProperties
Just holds the weakly referenced shared properties for the worldObjects


currSharedProperties

protected cz.cuni.amis.utils.maps.HashMapMap<WorldObjectId,PropertyId,ISharedProperty> currSharedProperties
The most recent versions of sharedProperties


lastUpdateTime

protected Map<WorldObjectId,Long> lastUpdateTime
Holds the last time when an update event was recieved from any agent for each object


heldKeys

protected HashMap<TimeKey,Set<IAgentId>> heldKeys
Currently 'locked' timeKeys (with agents locking the keys) - we need to keep objects for those


currentTimeKeys

protected Map<IAgentId,TimeKey> currentTimeKeys
The current TimeKey handled by an agent


registeredClasses

protected Set<Class> registeredClasses
Classes for which the database processes events

Constructor Detail

SharedKnowledgeDatabase

protected SharedKnowledgeDatabase(int team)
Method Detail

get

public static SharedKnowledgeDatabase get(int team)
Returns the only instance of SharedKnowledgeDatabase for the specified team.

Parameters:
team -
Returns:

addTimeLock

protected void addTimeLock(TimeKey timeKey,
                           IAgentId id)
Locks the specified time and all greater times with the agentId


removeTimeLock

protected void removeTimeLock(TimeKey timeKey,
                              IAgentId id)
Removes a single lock for this timeKey, if it is the last, the whole lock is removed

Parameters:
timeKey -
id -

addAgent

public void addAgent(IAgentId id,
                     IVisionWorldView agentWorldView,
                     int team)
Registers an agent to the database - it will process it's relevant events from now on.

Parameters:
id -
agentWorldView -
team -

addObjectClass

public void addObjectClass(Class c)
Registers the provided class as a class of interest. The knowledge database will register listeners on all agent worldViews and will start processing events from the worldViews to collect shared information.

Parameters:
c -

removeObjectClass

public boolean removeObjectClass(Class c)
Stops processing events for the specified class. If the class is not registered, no change is made.

Parameters:
c - class to process events for
Returns:
false if the class was not registered

removeAgent

public boolean removeAgent(IAgentId id)
Unregister the agent from the database -> the database will no longer process events from this agent. The method also removes all listeners created by the database on the agent's worldview.

Parameters:
id -
team -
Returns:

getObject

public IWorldObject getObject(WorldObjectId id,
                              IAgentId agentId)
Returns the specified object with the team shared knowledge put in

Parameters:
id -
agentId -
Returns:

addClassListener

protected void addClassListener(IVisionWorldView wv,
                                Class c,
                                IAgentId agentId)
Helper method to add a single objectEventListener for Class c to a specific WorldView

Parameters:
wv -
c -
agentId -

processObjEvent

protected void processObjEvent(IWorldObjectEvent<IWorldObject> event,
                               IAgentId agentId)
Handles processing of an object event raised on any of the worldViews. This method will update all the shared properties correctly and also uses the event information to adjust the heldTimeKeys

Parameters:
event -


Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.