public class LocalWorldViewAdapter extends Object implements IWorldView, ILockableVisionWorldView
| Constructor and Description |
|---|
LocalWorldViewAdapter(BatchAwareLocalWorldView localWV) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(Class<?> eventClass,
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).
|
Map<WorldObjectId,IWorldObject> |
get()
Returns map with objects inserted according to their id.
|
IWorldObject |
get(WorldObjectId id)
Returns a world object of the specific id (if exists inside the world view).
|
<T extends IWorldObject> |
get(WorldObjectId objectId,
Class<T> clazz)
Returns a world object of the specific id and class (if exists inside the world view).
|
Map<Class,Map<WorldObjectId,IWorldObject>> |
getAll()
Returns map of all objects that are present in the world view.
|
<T extends IWorldObject> |
getAll(Class<T> type)
Returns map of all objects of a specific type that are present in the world view.
|
Map<Class,Map<WorldObjectId,IViewable>> |
getAllVisible()
Returns map of all visible objects (
IViewable instances} - those that the agent can currently see. |
<T extends IViewable> |
getAllVisible(Class<T> type)
Returns map of all visible objects (
IViewable instances} - those that the agent can currently see. |
cz.cuni.amis.utils.token.IToken |
getComponentId()
Unique identification of the component.
|
IComponentBus |
getEventBus() |
long |
getSimTime() |
<T extends IWorldObject> |
getSingle(Class<T> cls)
Returns the only instance of required object if present, if there are
more instances of this object then
IllegalArgumentException will be thrown. |
Map<WorldObjectId,IViewable> |
getVisible()
Returns map of all visible objects (
IViewable instances} organized according to their WorldObjectId -
those that the agent can currently see. |
IViewable |
getVisible(WorldObjectId id)
Returns a visible world object of the specific id (if exists inside the world view and is visible).
|
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).
|
boolean |
isLocked()
Whether the worldview is locked.
|
void |
lock()
Lock the worldview, preventing it from raising any new events.
|
void |
notify(IWorldChangeEvent event)
New event was generated from the world.
|
void |
notifyAfterPropagation(IWorldChangeEvent event)
Raise another event after current one finishes its propagation.
|
void |
notifyImmediately(IWorldChangeEvent event)
Notify immediately will process the event right away, it won't use "event recursion buffer" to postpone the processing of the event.
|
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).
|
void |
unlock()
Unlock the worldview, processing all events that came between lock() / unlock() calls.
|
@Inject public LocalWorldViewAdapter(BatchAwareLocalWorldView localWV)
public long getSimTime()
public void notify(IWorldChangeEvent event) throws ComponentNotRunningException, ComponentPausedException
IWorldChangeEventInputnotify in interface IWorldChangeEventInputComponentNotRunningExceptionComponentPausedExceptionpublic void notifyAfterPropagation(IWorldChangeEvent event) throws ComponentNotRunningException, ComponentPausedException
IWorldChangeEventInputWon't propagate the event if the world view is locked!.
notifyAfterPropagation in interface IWorldChangeEventInputComponentNotRunningExceptionComponentPausedExceptionpublic void notifyImmediately(IWorldChangeEvent event) throws ComponentNotRunningException, ComponentPausedException
IWorldChangeEventInputThis will work even if the world view is locked!
notifyImmediately in interface IWorldChangeEventInputComponentNotRunningExceptionComponentPausedExceptionpublic cz.cuni.amis.utils.token.IToken getComponentId()
IComponentgetComponentId in interface IComponentpublic IComponentBus getEventBus()
getEventBus in interface IWorldViewpublic void addEventListener(Class<?> eventClass, IWorldEventListener<?> listener)
IWorldViewIt 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 IWorldVieweventClass - which event types you want to receivelistener - where you want to handle these eventspublic void addObjectListener(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
IWorldViewEvents 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 IWorldViewobjectClass - which object class you want to listen atlistener - where you want to handle these eventspublic void addObjectListener(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
IWorldViewEvents 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 IWorldViewobjectClass - 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)
IWorldViewEvents 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 IWorldViewobjectId - which object you want to listen atlistener - where you want to handle eventspublic void addObjectListener(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
IWorldViewEvents 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 IWorldViewobjectId - which object you want to listen ateventClass - which event classes you want to receivelistener - where you want to handle these eventspublic void removeEventListener(Class<?> eventClass, IWorldEventListener<?> listener)
IWorldViewremoveEventListener in interface IWorldVieweventClass - which events class you want to remove the listener fromlistener - you want to removepublic void removeObjectListener(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
IWorldViewremoveObjectListener in interface IWorldViewobjectClass - class of objects you want the listener to remove fromlistener - you want to removepublic void removeObjectListener(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
IWorldViewremoveObjectListener in interface IWorldViewobjectClass - 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)
IWorldViewremoveObjectListener in interface IWorldViewobjectId - id of object you want the listener to remove fromlistener - you want to removepublic void removeObjectListener(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
IWorldViewremoveObjectListener in interface IWorldViewobjectId - 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)
IWorldViewWARNING: Can be time consuming! (Iterating through all levels of listeners.)
removeListener in interface IWorldViewlistener - you want to remove from all listener levelspublic boolean isListening(Class<?> eventClass, IWorldEventListener<?> listener)
IWorldViewisListening in interface IWorldVieweventClass - which events you want to receivelistener - that is testedpublic boolean isListening(Class<?> objectClass, IWorldObjectEventListener<?,?> listener)
IWorldViewisListening in interface IWorldViewobjectClass - where the listener is testedlistener - that is testedpublic boolean isListening(Class<?> objectClass, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
IWorldViewisListening in interface IWorldViewobjectClass - where the listener is testedeventClass - where the listener is testedlistener - that is testedpublic boolean isListening(WorldObjectId objectId, IWorldObjectEventListener<?,?> listener)
IWorldViewisListening in interface IWorldViewobjectId - where the listener is testedlistener - that is testedpublic boolean isListening(WorldObjectId objectId, Class<?> eventClass, IWorldObjectEventListener<?,?> listener)
IWorldViewisListening in interface IWorldViewobjectId - where the listener is testedeventClass - what class is testedlistener - that is testedpublic boolean isListening(IWorldEventListener<?> listener)
IWorldViewWARNING: Can be time consuming! (Iterating through all levels of listeners.)
isListening in interface IWorldViewpublic Map<Class,Map<WorldObjectId,IWorldObject>> getAll()
IWorldViewWARNING: If you will do iteration over the map, you must synchronize on it.
getAll in interface IWorldViewpublic <T extends IWorldObject> Map<WorldObjectId,T> getAll(Class<T> type)
IWorldViewWARNING: If you will do iteration over the map, you must synchronize on it.
getAll in interface IWorldViewpublic <T extends IWorldObject> T getSingle(Class<T> cls)
IWorldViewIllegalArgumentException will be thrown.
Should be used to obtain "utility" world objects such us "informations about the agent" (that is unique for the agent and as the world view should be used by only one agent...) or some "world statistics object".
getSingle in interface IWorldViewcls - Class of object to be retrievedpublic Map<WorldObjectId,IWorldObject> get()
IWorldViewWARNING: If you will do iteration over the map, you must synchronize on it.
Note that this map contains various objects, therefore you will somehow guess the correct class of the object from its id.
get in interface IWorldViewpublic IWorldObject get(WorldObjectId id)
IWorldViewNote that there is no way to tell the correct type of returned object - you have to cast it to a correct class yourself.
get in interface IWorldViewid - objects's idpublic <T extends IWorldObject> T get(WorldObjectId objectId, Class<T> clazz)
IWorldViewget in interface IWorldViewobjectId - objects's idclazz - the class of the object to be returnedpublic Map<Class,Map<WorldObjectId,IViewable>> getAllVisible()
IVisionWorldViewIViewable instances} - those that the agent can currently see.
WARNING: If you will do iteration over the map, you must synchronize on it.
getAllVisible in interface IVisionWorldViewpublic <T extends IViewable> Map<WorldObjectId,T> getAllVisible(Class<T> type)
IVisionWorldViewIViewable instances} - those that the agent can currently see.
WARNING: If you will do iteration over the map, you must synchronize on it.
getAllVisible in interface IVisionWorldViewpublic Map<WorldObjectId,IViewable> getVisible()
IVisionWorldViewIViewable instances} organized according to their WorldObjectId -
those that the agent can currently see.
WARNING: If you will do iteration over the map, you must synchronize on it.
getVisible in interface IVisionWorldViewpublic IViewable getVisible(WorldObjectId id)
IVisionWorldViewOtherwise, null is returned.
getVisible in interface IVisionWorldViewid - objects's idpublic void lock()
throws cz.cuni.amis.utils.exception.PogamutInterruptedException,
ComponentNotRunningException,
ComponentPausedException
ILockableWorldViewWhen locked - the worldview must store all incoming events and process them during unlock.
Note that it is implementation-dependent whether this method is blocking or not.
lock in interface ILockableWorldViewcz.cuni.amis.utils.exception.PogamutInterruptedExceptionComponentNotRunningExceptionComponentPausedExceptionpublic void unlock()
throws ComponentNotRunningException,
ComponentPausedException
ILockableWorldViewunlock in interface ILockableWorldViewComponentNotRunningExceptionComponentPausedExceptionpublic boolean isLocked()
ILockableWorldViewisLocked in interface ILockableWorldViewCopyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.