cz.cuni.amis.pogamut.multi.communication.worldview.impl
Class LocalWorldViewAdapter

Package class diagram package LocalWorldViewAdapter
java.lang.Object
  extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.LocalWorldViewAdapter
All Implemented Interfaces:
ILockableWorldView, IWorldChangeEventInput, IWorldView, IComponent, ILockableVisionWorldView, IVisionWorldView

public class LocalWorldViewAdapter
extends Object
implements IWorldView, ILockableVisionWorldView

This class serves as an adapter for ILocalWorldView to satisfy the IWorldView interface, all methods of this worldView only call the appropriate methods on the backing localWorldView

Author:
srlok

Constructor Summary
LocalWorldViewAdapter(BatchAwareLocalWorldView localWV)
           
 
Method Summary
 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>
T
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>
Map<WorldObjectId,T>
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>
Map<WorldObjectId,T>
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>
T
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalWorldViewAdapter

@Inject
public LocalWorldViewAdapter(BatchAwareLocalWorldView localWV)
Method Detail

getSimTime

public long getSimTime()

notify

public void notify(IWorldChangeEvent event)
            throws ComponentNotRunningException,
                   ComponentPausedException
Description copied from interface: IWorldChangeEventInput
New event was generated from the world.

Specified by:
notify in interface IWorldChangeEventInput
Throws:
ComponentNotRunningException
ComponentPausedException

notifyAfterPropagation

public void notifyAfterPropagation(IWorldChangeEvent event)
                            throws ComponentNotRunningException,
                                   ComponentPausedException
Description copied from interface: IWorldChangeEventInput
Raise another event after current one finishes its propagation.

Won't propagate the event if the world view is locked!.

Specified by:
notifyAfterPropagation in interface IWorldChangeEventInput
Throws:
ComponentNotRunningException
ComponentPausedException

notifyImmediately

public void notifyImmediately(IWorldChangeEvent event)
                       throws ComponentNotRunningException,
                              ComponentPausedException
Description copied from interface: IWorldChangeEventInput
Notify immediately will process the event right away, it won't use "event recursion buffer" to postpone the processing of the event.

This will work even if the world view is locked!

Specified by:
notifyImmediately in interface IWorldChangeEventInput
Throws:
ComponentNotRunningException
ComponentPausedException

getComponentId

public cz.cuni.amis.utils.token.IToken getComponentId()
Description copied from interface: IComponent
Unique identification of the component.

Specified by:
getComponentId in interface IComponent
Returns:

getEventBus

public IComponentBus getEventBus()
Specified by:
getEventBus in interface IWorldView

addEventListener

public void addEventListener(Class<?> eventClass,
                             IWorldEventListener<?> listener)
Description copied from interface: IWorldView
Adds listener to a specific event (Level A listeners). Note that the event listener must be able to handle events of the class 'event'.

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'.

Specified by:
addEventListener in interface IWorldView
Parameters:
eventClass - which event types you want to receive
listener - where you want to handle these events

addObjectListener

public void addObjectListener(Class<?> objectClass,
                              IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Adds listener to all events that happens on any object of the 'objectClass' (Level B listeners).

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'.

Specified by:
addObjectListener in interface IWorldView
Parameters:
objectClass - which object class you want to listen at
listener - where you want to handle these events

addObjectListener

public void addObjectListener(Class<?> objectClass,
                              Class<?> eventClass,
                              IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Adds listener to a specified 'event' that occurs on the specific 'objectClass' (Level C listeners).

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.

Specified by:
addObjectListener in interface IWorldView
Parameters:
objectClass - which object class you want to listen at
eventClass - which event class you want to receive
listener - where you want to handle these events

addObjectListener

public void addObjectListener(WorldObjectId objectId,
                              IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Adds listener to all events that happens on object with specific 'objectId' (Level D listeners).

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'.

Specified by:
addObjectListener in interface IWorldView
Parameters:
objectId - which object you want to listen at
listener - where you want to handle events

addObjectListener

public void addObjectListener(WorldObjectId objectId,
                              Class<?> eventClass,
                              IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Adds listener to a specified 'event' that occurs on the specific object with 'objectId' (Level E listeners).

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'.

Specified by:
addObjectListener in interface IWorldView
Parameters:
objectId - which object you want to listen at
eventClass - which event classes you want to receive
listener - where you want to handle these events

removeEventListener

public void removeEventListener(Class<?> eventClass,
                                IWorldEventListener<?> listener)
Description copied from interface: IWorldView
Removes listener from a specific event (Level A listeners).

Specified by:
removeEventListener in interface IWorldView
Parameters:
eventClass - which events class you want to remove the listener from
listener - you want to remove

removeObjectListener

public void removeObjectListener(Class<?> objectClass,
                                 IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Removes listener from specific 'objectClass' listening for specified 'event' (Level B listeners).

Specified by:
removeObjectListener in interface IWorldView
Parameters:
objectClass - class of objects you want the listener to remove from
listener - you want to remove

removeObjectListener

public void removeObjectListener(Class<?> objectClass,
                                 Class<?> eventClass,
                                 IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Removes listener from specific 'objectClass' listening for specified 'event' (Level C listeners).

Specified by:
removeObjectListener in interface IWorldView
Parameters:
objectClass - class of objects you want the listener to remove from
eventClass - which events class you want to remove the listener from
listener - you want to remove

removeObjectListener

public void removeObjectListener(WorldObjectId objectId,
                                 IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Removes listener from objects with specified 'objectId' (Level D Listeners).

Specified by:
removeObjectListener in interface IWorldView
Parameters:
objectId - id of object you want the listener to remove from
listener - you want to remove

removeObjectListener

public void removeObjectListener(WorldObjectId objectId,
                                 Class<?> eventClass,
                                 IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Removes listener to a specified 'event' that occurs on the specific object with 'objectId' (Level E listeners).

Specified by:
removeObjectListener in interface IWorldView
Parameters:
objectId - id of object you want the listener to remove from
eventClass - event class you want to stop receiving in the listener
listener - you want to remove

removeListener

public void removeListener(IWorldEventListener<?> listener)
Description copied from interface: IWorldView
Removes listener from every listeners category (from every listener level).

WARNING: Can be time consuming! (Iterating through all levels of listeners.)

Specified by:
removeListener in interface IWorldView
Parameters:
listener - you want to remove from all listener levels

isListening

public boolean isListening(Class<?> eventClass,
                           IWorldEventListener<?> listener)
Description copied from interface: IWorldView
Tests whether the 'listener' is listening to a specific event (Level A listeners).

Specified by:
isListening in interface IWorldView
Parameters:
eventClass - which events you want to receive
listener - that is tested
Returns:
whether the listener is listening

isListening

public boolean isListening(Class<?> objectClass,
                           IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Tests whether the 'listener' is listening at specified 'objectClass' (Level B listeners).

Specified by:
isListening in interface IWorldView
Parameters:
objectClass - where the listener is tested
listener - that is tested
Returns:
whether the listener is listening

isListening

public boolean isListening(Class<?> objectClass,
                           Class<?> eventClass,
                           IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Tests whether the 'listener' is listening at specified 'objectClass' for specified 'event' (Level C listeners).

Specified by:
isListening in interface IWorldView
Parameters:
objectClass - where the listener is tested
eventClass - where the listener is tested
listener - that is tested
Returns:
whether the listener is listening

isListening

public boolean isListening(WorldObjectId objectId,
                           IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Tests whether the 'listener' is listening at specified 'objectId' (Level D Listeners).

Specified by:
isListening in interface IWorldView
Parameters:
objectId - where the listener is tested
listener - that is tested
Returns:
whether the listener is listening

isListening

public boolean isListening(WorldObjectId objectId,
                           Class<?> eventClass,
                           IWorldObjectEventListener<?,?> listener)
Description copied from interface: IWorldView
Tests whether the 'listener' is listening to a specified 'event' that occurs on the specific object with 'objectId' (Level E listeners).

Specified by:
isListening in interface IWorldView
Parameters:
objectId - where the listener is tested
eventClass - what class is tested
listener - that is tested
Returns:
whether the listener is listening

isListening

public boolean isListening(IWorldEventListener<?> listener)
Description copied from interface: IWorldView
Checks whether this listener is hooked to the world view (at any listener level).

WARNING: Can be time consuming! (Iterating through all levels of listeners.)

Specified by:
isListening in interface IWorldView
Returns:

getAll

public Map<Class,Map<WorldObjectId,IWorldObject>> getAll()
Description copied from interface: IWorldView
Returns map of all objects that are present in the world view.

WARNING: If you will do iteration over the map, you must synchronize on it.

Specified by:
getAll in interface IWorldView

getAll

public <T extends IWorldObject> Map<WorldObjectId,T> getAll(Class<T> type)
Description copied from interface: IWorldView
Returns map of all objects of a specific type that are present in the world view.

WARNING: If you will do iteration over the map, you must synchronize on it.

Specified by:
getAll in interface IWorldView
Returns:

getSingle

public <T extends IWorldObject> T getSingle(Class<T> cls)
Description copied from interface: IWorldView
Returns the only instance of required object if present, if there are more instances of this object then IllegalArgumentException 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".

Specified by:
getSingle in interface IWorldView
Parameters:
cls - Class of object to be retrieved
Returns:
the only object of given class

get

public Map<WorldObjectId,IWorldObject> get()
Description copied from interface: IWorldView
Returns map with objects inserted according to their id.

WARNING: 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.

Specified by:
get in interface IWorldView
Returns:

get

public IWorldObject get(WorldObjectId id)
Description copied from interface: IWorldView
Returns a world object of the specific id (if exists inside the world view). Otherwise, null is returned.

Note that there is no way to tell the correct type of returned object - you have to cast it to a correct class yourself.

Specified by:
get in interface IWorldView
Parameters:
id - objects's id
Returns:

get

public <T extends IWorldObject> T get(WorldObjectId objectId,
                                      Class<T> clazz)
Description copied from interface: IWorldView
Returns a world object of the specific id and class (if exists inside the world view). Otherwise, null is returned.

Specified by:
get in interface IWorldView
Parameters:
objectId - objects's id
clazz - the class of the object to be returned
Returns:
the object or null if not found

getAllVisible

public Map<Class,Map<WorldObjectId,IViewable>> getAllVisible()
Description copied from interface: IVisionWorldView
Returns map of all visible objects (IViewable instances} - those that the agent can currently see.

WARNING: If you will do iteration over the map, you must synchronize on it.

Specified by:
getAllVisible in interface IVisionWorldView

getAllVisible

public <T extends IViewable> Map<WorldObjectId,T> getAllVisible(Class<T> type)
Description copied from interface: IVisionWorldView
Returns map of all visible objects (IViewable instances} - those that the agent can currently see.

WARNING: If you will do iteration over the map, you must synchronize on it.

Specified by:
getAllVisible in interface IVisionWorldView
Returns:

getVisible

public Map<WorldObjectId,IViewable> getVisible()
Description copied from interface: IVisionWorldView
Returns map of all visible objects (IViewable 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.

Specified by:
getVisible in interface IVisionWorldView
Returns:

getVisible

public IViewable getVisible(WorldObjectId id)
Description copied from interface: IVisionWorldView
Returns a visible world object of the specific id (if exists inside the world view and is visible).

Otherwise, null is returned.

Specified by:
getVisible in interface IVisionWorldView
Parameters:
id - objects's id
Returns:

lock

public void lock()
          throws cz.cuni.amis.utils.exception.PogamutInterruptedException,
                 ComponentNotRunningException,
                 ComponentPausedException
Description copied from interface: ILockableWorldView
Lock the worldview, preventing it from raising any new events.

When 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.

Specified by:
lock in interface ILockableWorldView
Throws:
cz.cuni.amis.utils.exception.PogamutInterruptedException
ComponentNotRunningException
ComponentPausedException

unlock

public void unlock()
            throws ComponentNotRunningException,
                   ComponentPausedException
Description copied from interface: ILockableWorldView
Unlock the worldview, processing all events that came between lock() / unlock() calls.

Specified by:
unlock in interface ILockableWorldView
Throws:
ComponentNotRunningException
ComponentPausedException

isLocked

public boolean isLocked()
Description copied from interface: ILockableWorldView
Whether the worldview is locked.

Specified by:
isLocked in interface ILockableWorldView
Returns:


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