public abstract class AbstractLocalWorldView extends Object implements ILocalWorldView
| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractLocalWorldView.LazyCompositeObjectMap<T extends ICompositeWorldObject>
This is a class for lazy maps holding CompositeWorldObjects .
|
| Modifier and Type | Field and Description |
|---|---|
protected Map<WorldObjectId,ILocalWorldObject> |
actLocalWorldObjects |
protected ITeamedAgentId |
agentId |
protected cz.cuni.amis.utils.maps.HashMapSet<Class,WorldObjectId> |
classMap |
static cz.cuni.amis.utils.token.Token |
COMPONENT_ID |
protected IComponentControlHelper |
control |
protected ComponentController<IComponent> |
controller |
protected ILifecycleBus |
eventBus |
protected LogCategory |
log |
protected ISharedWorldView |
sharedWorldView |
protected Map<Class,Set<WorldObjectId>> |
syncClassMap |
| Constructor and Description |
|---|
AbstractLocalWorldView(ComponentDependencies dependencies,
ILifecycleBus bus,
IAgentLogger logger,
ISharedWorldView sharedWV,
ITeamedAgentId agentId) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(Class<?> event,
IWorldEventListener<?> listener)
Adds listener to a specific event (Level A listeners).
|
protected void |
addLocalWorldObject(ILocalWorldObject obj)
Helper method for adding a new object into all object maps.
|
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 |
addOldLocalWorldObject(ILocalWorldObject obj,
long eventTime)
Adds this object as old for all heldTimeKeys that currently hold no old copy of this object.
|
protected void |
cleanUp()
Cleans up internal data structures, called from start/stop/kill/reset methods.
|
protected abstract ICompositeWorldObject |
createCompositeObject(ILocalWorldObject localObject,
ISharedWorldObject sharedObject,
IStaticWorldObject staticObject)
Method used for returning the appropriate CompositeObject type made from the three provided object parts.
|
Map<WorldObjectId,ICompositeWorldObject> |
get()
Returns a map of all CompositeWorldObjects in the world.
|
protected Map<WorldObjectId,ICompositeWorldObject> |
get(TimeKey time)
Returns a map of all CompositeWorldObjects in the world.
|
ICompositeWorldObject |
get(WorldObjectId objectId) |
<T extends ICompositeWorldObject> |
get(WorldObjectId objectId,
Class<T> clazz)
Returns object with specific id and class, if it exists.
|
protected ICompositeWorldObject |
get(WorldObjectId objectId,
TimeKey time)
Returns the object actual to the specified TimeKey.
|
ITeamedAgentId |
getAgentId()
Returns agentId of the agent associated with this WorldView.
|
Map<Class,Map<WorldObjectId,ICompositeWorldObject>> |
getAll()
Returns all objects sorted according to class.
|
<T extends IWorldObject> |
getAll(Class<T> type) |
protected <T extends IWorldObject> |
getAll(Class<T> type,
TimeKey time)
Returns a lazy-implemented classMap containing CompositeWorldObjects current to the specified TimeKey.
|
protected Map<Class,Map<WorldObjectId,ICompositeWorldObject>> |
getAll(TimeKey time)
Returns all objects sorted according to class.
|
cz.cuni.amis.utils.token.Token |
getComponentId()
Unique identification of the component.
|
TimeKey |
getCurrentTimeKey() |
ILifecycleBus |
getEventBus() |
ILocalWorldObject |
getLocal(WorldObjectId objectId)
Returns the most current LocalObject.
|
protected ILocalWorldObject |
getLocal(WorldObjectId objectId,
TimeKey time)
Returns the LocalObject associated with the provided TimeKey.
|
protected ILocalWorldObject |
getMostRecentLocalWorldObject(WorldObjectId id)
Returns the most recent instance of object with the specified id.
|
<T extends IWorldObject> |
getSingle(Class<T> cls) |
protected <T extends IWorldObject> |
getSingle(Class<T> cls,
TimeKey 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.
|
void |
lockTime(long time) |
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 |
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).
|
protected void |
removeLocalWorldObject(ILocalWorldObject obj)
Helper method to remove a localWorldObject from all corresponding object maps (used in DESTROYED events).
|
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 |
reset()
Resets the world view so it is start()able again.
|
protected void |
resume()
Resumes the world view.
|
boolean |
setCurrentTime(TimeKey key) |
boolean |
setInitialTime(TimeKey key)
Method for initializing the first timeKey, returns false if the
TimeKey is already set.s
|
protected void |
start()
Starts the world view.
|
protected void |
stop()
Stops the world view.
|
void |
unlockTime(long time) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnotifyImmediatelynotify, notifyAfterPropagationpublic static final cz.cuni.amis.utils.token.Token COMPONENT_ID
protected ISharedWorldView sharedWorldView
protected ITeamedAgentId agentId
protected Map<WorldObjectId,ILocalWorldObject> actLocalWorldObjects
protected cz.cuni.amis.utils.maps.HashMapSet<Class,WorldObjectId> classMap
protected Map<Class,Set<WorldObjectId>> syncClassMap
protected LogCategory log
protected ILifecycleBus eventBus
protected ComponentController<IComponent> controller
protected IComponentControlHelper control
public AbstractLocalWorldView(ComponentDependencies dependencies, ILifecycleBus bus, IAgentLogger logger, ISharedWorldView sharedWV, ITeamedAgentId agentId)
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()
IComponentgetComponentId in interface IComponentprotected abstract ICompositeWorldObject createCompositeObject(ILocalWorldObject localObject, ISharedWorldObject sharedObject, IStaticWorldObject staticObject)
Method used for returning the appropriate CompositeObject type made from the three provided object parts. All parts must share the same WorldObjectId and must belong to the same CompositeObject class. Also, none of the parts may be null.
The method should return a proxy-type CompositeObject, meaning that the object will only wrap all objectParts and no data will actually be copied.
This method must be overriden by a object-awareWorldView which has information about all the object classes in the world and is able to call the correct constructors
localObject - local part of the objectsharedObject - shared part of the objectstaticObject - static part of the objectpublic ITeamedAgentId getAgentId()
getAgentId in interface ILocalWorldViewpublic ILocalWorldObject getLocal(WorldObjectId objectId)
ILocalWorldViewgetLocal in interface ILocalWorldViewprotected ILocalWorldObject getLocal(WorldObjectId objectId, TimeKey time)
objectId - time - protected ICompositeWorldObject get(WorldObjectId objectId, TimeKey time)
objectId - time - public ICompositeWorldObject get(WorldObjectId objectId)
get in interface ILocalWorldViewpublic <T extends ICompositeWorldObject> T get(WorldObjectId objectId, Class<T> clazz)
ILocalWorldViewget in interface ILocalWorldViewprotected Map<Class,Map<WorldObjectId,ICompositeWorldObject>> getAll(TimeKey time)
time - public Map<Class,Map<WorldObjectId,ICompositeWorldObject>> getAll()
ILocalWorldViewgetAll in interface ILocalWorldViewprotected <T extends IWorldObject> Map<WorldObjectId,T> getAll(Class<T> type, TimeKey time)
WARNING : do not store this map, always use the getAll() method or copy the map if you really need it stored somewhere. The TimeKey can be overriden by calling another getAll( Class==Class, time!=time) .
T - type - time - public <T extends IWorldObject> Map<WorldObjectId,T> getAll(Class<T> type)
getAll in interface ILocalWorldViewpublic Map<WorldObjectId,ICompositeWorldObject> get()
ILocalWorldViewget in interface ILocalWorldViewprotected Map<WorldObjectId,ICompositeWorldObject> get(TimeKey time)
time - public <T extends IWorldObject> T getSingle(Class<T> cls)
getSingle in interface ILocalWorldViewprotected <T extends IWorldObject> T getSingle(Class<T> cls, TimeKey time)
protected ILocalWorldObject getMostRecentLocalWorldObject(WorldObjectId id)
id - id of the objectprotected void addOldLocalWorldObject(ILocalWorldObject obj, long eventTime)
protected void addLocalWorldObject(ILocalWorldObject obj)
obj - protected void removeLocalWorldObject(ILocalWorldObject obj)
obj - public boolean setInitialTime(TimeKey key)
setInitialTime in interface ILocalWorldViewkey - public boolean setCurrentTime(TimeKey key)
setCurrentTime in interface ILocalWorldViewpublic TimeKey getCurrentTimeKey()
getCurrentTimeKey in interface ILocalWorldViewpublic void lockTime(long time)
lockTime in interface ILocalWorldViewpublic void unlockTime(long time)
unlockTime in interface ILocalWorldViewpublic void addEventListener(Class<?> event, IWorldEventListener<?> listener)
ILocalWorldViewIt 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 ILocalWorldViewevent - which event types you want to receivelistener - where you want to handle these eventspublic void addObjectListener(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewEvents 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 ILocalWorldViewobjectClass - which object class you want to listen atlistener - where you want to handle these eventspublic void addObjectListener(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewEvents 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 ILocalWorldViewobjectClass - 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)
ILocalWorldViewEvents 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 ILocalWorldViewobjectId - which object you want to listen atlistener - where you want to handle eventspublic void addObjectListener(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewEvents 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 ILocalWorldViewobjectId - 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)
ILocalWorldViewisListening in interface ILocalWorldVieweventClass - which events you want to receivelistener - that is testedpublic boolean isListening(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewisListening in interface ILocalWorldViewobjectClass - where the listener is testedlistener - that is testedpublic boolean isListening(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewisListening in interface ILocalWorldViewobjectClass - where the listener is testedeventClass - where the listener is testedlistener - that is testedpublic boolean isListening(WorldObjectId objectId, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewisListening in interface ILocalWorldViewobjectId - where the listener is testedlistener - that is testedpublic boolean isListening(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewisListening in interface ILocalWorldViewobjectId - where the listener is testedeventClass - what class is testedlistener - that is testedpublic boolean isListening(IWorldEventListener<?> listener)
ILocalWorldViewWARNING: Can be time consuming! (Iterating through all levels of listeners.)
isListening in interface ILocalWorldViewpublic void removeEventListener(Class<?> eventClass, IWorldEventListener<?> listener)
ILocalWorldViewremoveEventListener in interface ILocalWorldVieweventClass - which events class you want to remove the listener fromlistener - you want to removepublic void removeObjectListener(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewremoveObjectListener in interface ILocalWorldViewobjectClass - class of objects you want the listener to remove fromlistener - you want to removepublic void removeObjectListener(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewremoveObjectListener in interface ILocalWorldViewobjectClass - 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)
ILocalWorldViewremoveObjectListener in interface ILocalWorldViewobjectId - id of object you want the listener to remove fromlistener - you want to removepublic void removeObjectListener(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
ILocalWorldViewremoveObjectListener in interface ILocalWorldViewobjectId - 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)
ILocalWorldViewWARNING: Can be time consuming! (Iterating through all levels of listeners.)
removeListener in interface ILocalWorldViewlistener - 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 - public ILifecycleBus getEventBus()
getEventBus in interface ILocalWorldViewCopyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.