cz.cuni.amis.pogamut.base.communication.worldview.impl
Class EventDrivenWorldView

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.communication.worldview.impl.AbstractWorldView
      extended by cz.cuni.amis.pogamut.base.communication.worldview.impl.EventDrivenWorldView
All Implemented Interfaces:
IWorldChangeEventInput, IWorldView, IComponent
Direct Known Subclasses:
LockableWorldView, VisionWorldView

public class EventDrivenWorldView
extends AbstractWorldView

Schema: "real" world | ... some communication ... | IWorldViewEventInput - EventDrivenWorldView | Agent (most probably listening for events)

EventDrivenWorldView assumes that everything is driven by the events that are received through IWorldChangeEventInput - those events surely must contains "new object appears event", "object update event", "object disappear event". Those three events are wrapped in one interface IWorldObjectUpdateEvent that has three types of behavior (see its javadoc).

The EDWV uses IWorldChangeEventFilters to process incoming events. During the construction of the EDWV the filters should be registered into it (see method initFilters). Subclass this EDWV to provide a different set of filters.

Used filters: TODO! finish the documentation Handling of events (that is incoming):

Note that the implementation of raising / receiving / notifying about event is strictly time-ordered. Every event is fully processed before another is raised/received. There is a possibility that raising one event may produce another one - in that case processing of this new one is postponed until the previous event has been fully processed (e.g. all listeners has been notified about it). That means that recursion of events is forbidden.

Note that we rely on method update() of the IWorldObjectUpdateEvent to be called as the first before the event is propagated further. An original object must be passed to the update() method and that method should save it as the original so the event can return correct object via getObject() method.


Field Summary
protected  java.util.Queue<IWorldChangeEvent> notifyEventsList
          List of events we have to process.
protected  boolean receiveEventProcessing
          Flag that is telling us whether there is an event being processed or not.
static java.lang.String WORLDVIEW_DEPENDENCY
           
 
Fields inherited from class cz.cuni.amis.pogamut.base.communication.worldview.impl.AbstractWorldView
COMPONENT_ID, control, controller, eventBus, log
 
Constructor Summary
EventDrivenWorldView(ComponentDependencies dependencies, IComponentBus bus, IAgentLogger log)
           
 
Method Summary
protected  void innerNotify(IWorldChangeEvent event)
          Used to process IWorldChangeEvent - it has to be either IWorldChangeEvent or IWorldObjectUpdateEvent.
 void notify(IWorldChangeEvent event)
          New event was generated from the world.
 void notifyImmediately(IWorldChangeEvent event)
          Notify immediately will process the event right away, it won't use "event recoursion buffer" to postpone the processing of the event.
protected  void objectCreated(IWorldObject obj)
          Must be called whenever an object was created, raises correct events.
protected  void objectDestroyed(IWorldObject obj)
          Must be called whenever an object was destroyed - raises correct events.
protected  void objectUpdated(IWorldObject obj)
          Must be called whenever an object was updated - raises correct event.
protected  void objectUpdatedEvent(IWorldObjectUpdatedEvent updateEvent)
          Called from innerNotify(IWorldChangeEvent) if the event is IWorldObjectUpdatedEvent to process it.
protected  void raiseEvent(IWorldEvent event)
          Catches exceptions.
 
Methods inherited from class cz.cuni.amis.pogamut.base.communication.worldview.impl.AbstractWorldView
addEventListener, addObjectListener, addObjectListener, addObjectListener, addObjectListener, addWorldObject, cleanUp, get, get, getAll, getAll, getComponentId, getEventBus, getLog, getSingle, isListening, isListening, isListening, isListening, isListening, isListening, isPaused, isRunning, kill, pause, prePause, preStop, removeEventListener, removeListener, removeObjectListener, removeObjectListener, removeObjectListener, removeObjectListener, removeWorldObject, reset, resume, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WORLDVIEW_DEPENDENCY

public static final java.lang.String WORLDVIEW_DEPENDENCY
See Also:
Constant Field Values

receiveEventProcessing

protected boolean receiveEventProcessing
Flag that is telling us whether there is an event being processed or not.

It is managed only by notify() method - DO NOT MODIFY OUTSIDE IT!


notifyEventsList

protected java.util.Queue<IWorldChangeEvent> notifyEventsList
List of events we have to process.

It is managed only by notify() method - DO NOT MODIFY OUTSIDE IT!

Constructor Detail

EventDrivenWorldView

@Inject
public EventDrivenWorldView(ComponentDependencies dependencies,
                                   IComponentBus bus,
                                   IAgentLogger log)
Method Detail

raiseEvent

protected void raiseEvent(IWorldEvent event)
Catches exceptions. If exception is caught, it calls ComponentController.fatalError() and this.kill().

Overrides:
raiseEvent in class AbstractWorldView

innerNotify

protected void innerNotify(IWorldChangeEvent event)
Used to process IWorldChangeEvent - it has to be either IWorldChangeEvent or IWorldObjectUpdateEvent. Forbids recursion.

DO NOT CALL SEPARATELY - should be called only from notifyEvent().

You may override it to provide event-specific processing behavior.

Parameters:
event -

objectUpdatedEvent

protected void objectUpdatedEvent(IWorldObjectUpdatedEvent updateEvent)
Called from innerNotify(IWorldChangeEvent) if the event is IWorldObjectUpdatedEvent to process it.

Parameters:
updateEvent -

objectCreated

protected void objectCreated(IWorldObject obj)
Must be called whenever an object was created, raises correct events.

Might be overridden to provide different behavior.

Parameters:
obj -

objectUpdated

protected void objectUpdated(IWorldObject obj)
Must be called whenever an object was updated - raises correct event.

Might be overridden to provide a mechanism that will forbid update of certain objects (like items that can't move).

Parameters:
obj -

objectDestroyed

protected void objectDestroyed(IWorldObject obj)
Must be called whenever an object was destroyed - raises correct events.

Might be overriden to provide different behavior.

Parameters:
obj -

notify

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

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 recoursion buffer" to postpone the processing of the event.

This will work even if the world view is locked!

Throws:
ComponentNotRunningException
ComponentPausedException