public abstract class AbstractSharedWorldView extends Object implements ISharedWorldView
Modifier and Type | Field and Description |
---|---|
static cz.cuni.amis.utils.token.Token |
COMPONENT_ID |
protected ISharedComponentControlHelper |
control |
protected ISharedComponentController<ISharedWorldView> |
controller |
protected cz.cuni.amis.utils.maps.HashTriMap<ITeamId,WorldObjectId,PropertyId,ISharedProperty> |
currentSharedProperties
SharedProperties currently considered most-recent.
|
protected HashMap<WorldObjectId,Class> |
idClassMap |
protected HashMap<TeamedAgentId,ILocalWorldView> |
localWorldViews
LocalWorldViews registered with this sharedWorldView
|
protected Logger |
log |
protected cz.cuni.amis.utils.maps.WeakHashQuadMap<TimeKey,ITeamId,WorldObjectId,PropertyId,ISharedProperty> |
sharedProperties
Holds all sharedProperties in the world weakly-referenced by timeKey, this map is used for storing shadowCopies of properties.
|
protected cz.cuni.amis.utils.maps.WeakHashTriMap<TimeKey,ITeamId,WorldObjectId,ISharedWorldObject> |
sharedWorldObjects
Cached sharedWorldObjects.
|
protected Map<WorldObjectId,IStaticWorldObject> |
staticWorldObjects
Map of staticWorldObjects, these objects never change, so there is no need for shadow copies.
|
protected Map<ITeamId,Map<WorldObjectId,Map<PropertyId,ISharedProperty>>> |
syncCurrentSharedProperties
Synchronized version of currentSharedProperties.
|
protected Map<WorldObjectId,Class> |
syncIdClassMap |
protected Map<TimeKey,Map<ITeamId,Map<WorldObjectId,Map<PropertyId,ISharedProperty>>>> |
syncSharedProperties
Synchronized version of sharedProperties.
|
protected Map<TimeKey,Map<ITeamId,Map<WorldObjectId,ISharedWorldObject>>> |
syncSharedWorldObjects
Synchronized version of cached sharedWorldObjects.
|
Constructor and Description |
---|
AbstractSharedWorldView(Logger logger) |
Modifier and Type | Method and Description |
---|---|
void |
addComponentBus(IAgentId agentId,
ILifecycleBus bus,
ComponentDependencies dependencies)
Informs the component that it is part of another
ILifecycleBus , i.e., it has become used by new agent with 'agentId'. |
void |
addEventListener(Class<?> event,
IWorldEventListener<?> listener)
Adds listener to a specific event (Level A listeners).
|
void |
addObjectListener(Class<?> objectClass,
Class<?> eventClass,
IWorldObjectEventListener<?,?> listener)
Adds listener to a specified 'event' that occurs on the specific 'objectClass' (Level C listeners).
|
void |
addObjectListener(Class<?> objectClass,
IWorldObjectEventListener<?,?> listener)
Adds listener to all events that happens on any object of the 'objectClass' (Level B listeners).
|
void |
addObjectListener(WorldObjectId objectId,
Class<?> eventClass,
IWorldObjectEventListener<?,?> listener)
Adds listener to a specified 'event' that occurs on the specific object with 'objectId' (Level E listeners).
|
void |
addObjectListener(WorldObjectId objectId,
IWorldObjectEventListener<?,?> listener)
Adds listener to all events that happens on object with specific 'objectId' (Level D listeners).
|
protected void |
addOldSharedProperty(ISharedProperty property,
ITeamId teamId,
long eventTime)
Adds the provided sharedProperty for all currently held timeKeys.
|
protected void |
addSharedProperty(ISharedProperty property)
adds this shared property for all teams
|
protected void |
addSharedProperty(ISharedProperty property,
ITeamId teamId)
adds this shared property only for the specified team
|
protected void |
addSharedWorldObject(ISharedWorldObject object)
adds all shared properties from this object for all teams
|
protected void |
addStaticWorldObject(IStaticWorldObject object)
if the object already exists, no changes are made
|
protected void |
cleanUp()
Cleans up internal data structures, called from start/stop/kill/reset methods.
|
protected abstract ISharedWorldObject |
createSharedObject(Class msgClass,
WorldObjectId id,
ITeamId teamId,
TimeKey time)
Creates a sharedWorldObject of the specified id.
|
cz.cuni.amis.utils.token.Token |
getComponentId()
Unique identification of the component.
|
ISharedWorldObject |
getShared(ITeamId teamId,
WorldObjectId objectId,
TimeKey time)
Returns the shared part of a requested object.
|
protected Collection<ISharedProperty> |
getSharedProperties(WorldObjectId objectId,
ITeamId teamId,
TimeKey time)
Returns all shared properties belonging to the specified object.
|
protected ISharedProperty |
getSharedProperty(PropertyId id,
ITeamId teamId,
TimeKey time)
Returns exactly the requested property
|
IStaticWorldObject |
getStatic(WorldObjectId id)
Returns only the static part of a requested object, static part of each objects only contains properties,
that will NOT be changed over time.
|
boolean |
isListening(Class<?> objectClass,
Class<?> eventClass,
IWorldObjectEventListener<?,?> listener)
Tests whether the 'listener' is listening at specified 'objectClass' for specified 'event' (Level C listeners).
|
boolean |
isListening(Class<?> eventClass,
IWorldEventListener<?> listener)
Tests whether the 'listener' is listening to a specific event (Level A listeners).
|
boolean |
isListening(Class<?> objectClass,
IWorldObjectEventListener<?,?> listener)
Tests whether the 'listener' is listening at specified 'objectClass' (Level B listeners).
|
boolean |
isListening(IWorldEventListener<?> listener)
Checks whether this listener is hooked to the world view (at any listener level).
|
boolean |
isListening(WorldObjectId objectId,
Class<?> eventClass,
IWorldObjectEventListener<?,?> listener)
Tests whether the 'listener' is listening to a specified 'event' that occurs on the specific object with 'objectId' (Level E listeners).
|
boolean |
isListening(WorldObjectId objectId,
IWorldObjectEventListener<?,?> listener)
Tests whether the 'listener' is listening at specified 'objectId' (Level D Listeners).
|
protected boolean |
isPaused() |
protected boolean |
isRunning() |
protected void |
kill()
Kills the world view.
|
protected void |
pause()
Pauses the world view.
|
protected void |
prePause()
Pre-pauses the world view.
|
protected void |
preStop()
Pre-stops the world view.
|
protected void |
raiseEvent(IWorldEvent event)
Process new IWorldEvent - notify all the listeners about it.
|
void |
registerLocalWorldView(ILocalWorldView localWV,
ILifecycleBus bus)
This method is called when a new localWorldView is created and wants to use this sharedWorldView,
the method registers the LocalWorldView with the sharedWorldView's sharedComponentBus and also
internally stores the information about which WorldViews are registered to it.
|
void |
removeComponentBus(IAgentId agentId,
ILifecycleBus bus)
Informs the component that it ceased to be the part of the
ILifecycleBus , i.e., it has stopped to be used by agent with 'agentId'. |
void |
removeEventListener(Class<?> eventClass,
IWorldEventListener<?> listener)
Removes listener from a specific event (Level A listeners).
|
void |
removeListener(IWorldEventListener<?> listener)
Removes listener from every listeners category (from every listener level).
|
void |
removeObjectListener(Class<?> objectClass,
Class<?> eventClass,
IWorldObjectEventListener<?,?> listener)
Removes listener from specific 'objectClass' listening for specified 'event' (Level C listeners).
|
void |
removeObjectListener(Class<?> objectClass,
IWorldObjectEventListener<?,?> listener)
Removes listener from specific 'objectClass' listening for specified 'event' (Level B listeners).
|
void |
removeObjectListener(WorldObjectId objectId,
Class<?> eventClass,
IWorldObjectEventListener<?,?> listener)
Removes listener to a specified 'event' that occurs on the specific object with 'objectId' (Level E listeners).
|
void |
removeObjectListener(WorldObjectId objectId,
IWorldObjectEventListener<?,?> listener)
Removes listener from objects with specified 'objectId' (Level D Listeners).
|
protected void |
removeSharedProperty(ISharedProperty property) |
protected void |
removeSharedProperty(ISharedProperty property,
ITeamId teamId) |
protected void |
removeStaticWorldObject(IStaticWorldObject object) |
protected void |
removeStaticWorldObject(WorldObjectId id) |
protected void |
reset()
Resets the world view so it is start()able again.
|
protected void |
resume()
Resumes the world view.
|
protected void |
start()
Starts the world view.
|
protected void |
stop()
Stops the world view.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
notify
public static final cz.cuni.amis.utils.token.Token COMPONENT_ID
protected HashMap<TeamedAgentId,ILocalWorldView> localWorldViews
protected cz.cuni.amis.utils.maps.WeakHashQuadMap<TimeKey,ITeamId,WorldObjectId,PropertyId,ISharedProperty> sharedProperties
protected Map<TimeKey,Map<ITeamId,Map<WorldObjectId,Map<PropertyId,ISharedProperty>>>> syncSharedProperties
protected cz.cuni.amis.utils.maps.HashTriMap<ITeamId,WorldObjectId,PropertyId,ISharedProperty> currentSharedProperties
protected Map<ITeamId,Map<WorldObjectId,Map<PropertyId,ISharedProperty>>> syncCurrentSharedProperties
protected Map<WorldObjectId,IStaticWorldObject> staticWorldObjects
protected cz.cuni.amis.utils.maps.WeakHashTriMap<TimeKey,ITeamId,WorldObjectId,ISharedWorldObject> sharedWorldObjects
protected Map<TimeKey,Map<ITeamId,Map<WorldObjectId,ISharedWorldObject>>> syncSharedWorldObjects
protected HashMap<WorldObjectId,Class> idClassMap
protected Map<WorldObjectId,Class> syncIdClassMap
protected Logger log
protected ISharedComponentController<ISharedWorldView> controller
protected ISharedComponentControlHelper control
public AbstractSharedWorldView(Logger logger)
public void registerLocalWorldView(ILocalWorldView localWV, ILifecycleBus bus)
registerLocalWorldView
in interface ISharedWorldView
localWV
- The local WorldView to to register.bus
- ILifecycleBus of the corresponding LocalWorldViewprotected ISharedProperty getSharedProperty(PropertyId id, ITeamId teamId, TimeKey time)
protected Collection<ISharedProperty> getSharedProperties(WorldObjectId objectId, ITeamId teamId, TimeKey time)
objectId
- teamId
- time
- protected abstract ISharedWorldObject createSharedObject(Class msgClass, WorldObjectId id, ITeamId teamId, TimeKey time)
id
- teamId
- time
- public ISharedWorldObject getShared(ITeamId teamId, WorldObjectId objectId, TimeKey time)
ISharedWorldView
getShared
in interface ISharedWorldView
public IStaticWorldObject getStatic(WorldObjectId id)
ISharedWorldView
getStatic
in interface ISharedWorldView
id
- - WorldObjectId of the entire WorldObjectprotected void addStaticWorldObject(IStaticWorldObject object)
protected void removeStaticWorldObject(WorldObjectId id)
protected void removeStaticWorldObject(IStaticWorldObject object)
protected void addSharedProperty(ISharedProperty property, ITeamId teamId)
property
- teamId
- protected void addSharedProperty(ISharedProperty property)
property
- protected void removeSharedProperty(ISharedProperty property, ITeamId teamId)
protected void removeSharedProperty(ISharedProperty property)
protected void addSharedWorldObject(ISharedWorldObject object)
object
- protected void addOldSharedProperty(ISharedProperty property, ITeamId teamId, long eventTime)
property
- teamId
- eventTime
- time of the event causing the property updatepublic void addComponentBus(IAgentId agentId, ILifecycleBus bus, ComponentDependencies dependencies)
ISharedComponent
ILifecycleBus
, i.e., it has become used by new agent with 'agentId'.
The component is obliged to register to that bus a watch for the lifecycle state of various components inside the bus.
addComponentBus
in interface ISharedComponent
public void removeComponentBus(IAgentId agentId, ILifecycleBus bus)
ISharedComponent
ILifecycleBus
, i.e., it has stopped to be used by agent with 'agentId'.removeComponentBus
in interface ISharedComponent
protected void cleanUp()
If you override this method, do not forget to call super.cleanUp().
protected void start()
If you override this method, do not forget to call super.start().
protected void prePause()
If you override this method, do not forget to call super.preStop().
protected void pause()
If you override this method, do not forget to call super.start().
protected void resume()
If you override this method, do not forget to call super.start().
protected void preStop()
If you override this method, do not forget to call super.preStop().
protected void stop()
If you override this method, do not forget to call super.stop().
protected void kill()
If you override this method, do not forget to call super.stop().
protected void reset()
If you override this method, do not forget to call super.reset().
protected boolean isRunning()
protected boolean isPaused()
public cz.cuni.amis.utils.token.Token getComponentId()
IComponent
getComponentId
in interface IComponent
public void addEventListener(Class<?> event, IWorldEventListener<?> listener)
ISharedWorldView
It is the most general type of listener-registration allowing you to sniff any type of events.
Events passed to the listener are filtered only according to the 'event' class.
WARNING: even though the method does not require templated class and listener, you must be sure that 'listener' can accept 'eventClass'.
addEventListener
in interface ISharedWorldView
event
- which event types you want to receivelistener
- where you want to handle these eventspublic void addObjectListener(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
Events passed to the listener are filtered according to the 'objectClass'.
WARNING: even though the method does not require templated classes and listener, you must be sure that 'listener' accepts all events (IWorldObjectEvent) for objects of 'objectClass'.
addObjectListener
in interface ISharedWorldView
objectClass
- which object class you want to listen atlistener
- where you want to handle these eventspublic void addObjectListener(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
Events passed to the listener are filtered according to the 'event' and 'objectClass' of the object the event happened upon.
WARNING: even though the method does not require templated classes and listener, you must be sure that 'listener' accepts 'eventClass' for objects of 'objectClass'.
eventClass can be any implementor of IWorldObjectEvent
. E.g.
WorldObjectAppearedEvent
, WorldObjectDestroyedEvent
, WorldObjectDisappearedEvent
,
WorldObjectFirstEncounteredEvent
or WorldObjectUpdatedEvent
.
addObjectListener
in interface ISharedWorldView
objectClass
- which object class you want to listen ateventClass
- which event class you want to receivelistener
- where you want to handle these eventspublic void addObjectListener(WorldObjectId objectId, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
Events passed to the listener are filtered according to the 'objectId' of the object.
WARNING: you must ensure that 'listener' can accept the event raised on object of specified 'objectId'.
addObjectListener
in interface ISharedWorldView
objectId
- which object you want to listen atlistener
- where you want to handle eventspublic void addObjectListener(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
Events passed to the listener are filtered according to the 'event' and 'objectId' of the object.
WARNING: even though the method does not require templated classes and listener, you must be sure that 'listener' accepts 'eventClass' for objects of specified 'objectId'.
addObjectListener
in interface ISharedWorldView
objectId
- which object you want to listen ateventClass
- which event classes you want to receivelistener
- where you want to handle these eventspublic boolean isListening(Class<?> eventClass, IWorldEventListener<?> listener)
ISharedWorldView
isListening
in interface ISharedWorldView
eventClass
- which events you want to receivelistener
- that is testedpublic boolean isListening(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
isListening
in interface ISharedWorldView
objectClass
- where the listener is testedlistener
- that is testedpublic boolean isListening(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
isListening
in interface ISharedWorldView
objectClass
- where the listener is testedeventClass
- where the listener is testedlistener
- that is testedpublic boolean isListening(WorldObjectId objectId, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
isListening
in interface ISharedWorldView
objectId
- where the listener is testedlistener
- that is testedpublic boolean isListening(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
isListening
in interface ISharedWorldView
objectId
- where the listener is testedeventClass
- what class is testedlistener
- that is testedpublic boolean isListening(IWorldEventListener<?> listener)
ISharedWorldView
WARNING: Can be time consuming! (Iterating through all levels of listeners.)
isListening
in interface ISharedWorldView
public void removeEventListener(Class<?> eventClass, IWorldEventListener<?> listener)
ISharedWorldView
removeEventListener
in interface ISharedWorldView
eventClass
- which events class you want to remove the listener fromlistener
- you want to removepublic void removeObjectListener(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
removeObjectListener
in interface ISharedWorldView
objectClass
- class of objects you want the listener to remove fromlistener
- you want to removepublic void removeObjectListener(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
removeObjectListener
in interface ISharedWorldView
objectClass
- class of objects you want the listener to remove fromeventClass
- which events class you want to remove the listener fromlistener
- you want to removepublic void removeObjectListener(WorldObjectId objectId, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
removeObjectListener
in interface ISharedWorldView
objectId
- id of object you want the listener to remove fromlistener
- you want to removepublic void removeObjectListener(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ISharedWorldView
removeObjectListener
in interface ISharedWorldView
objectId
- id of object you want the listener to remove fromeventClass
- event class you want to stop receiving in the listenerlistener
- you want to removepublic void removeListener(IWorldEventListener<?> listener)
ISharedWorldView
WARNING: Can be time consuming! (Iterating through all levels of listeners.)
removeListener
in interface ISharedWorldView
listener
- you want to remove from all listener levelsprotected void raiseEvent(IWorldEvent event)
Use in the descendants to process new IWorldChangeEvent.
Does not catch any exceptions!
Synchronized!
event
- Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.