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

Package class diagram package BatchAwareLocalWorldView
java.lang.Object
  extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractLocalWorldView
      extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.EventDrivenLocalWorldView
          extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.VisionLocalWorldView
              extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.BatchAwareLocalWorldView
All Implemented Interfaces:
IWorldChangeEventInput, IComponent, ILocalWorldView, IVisionLocalWorldView

public abstract class BatchAwareLocalWorldView
extends VisionLocalWorldView

Implements the batch logic into the worldView.

Author:
srlok

Nested Class Summary
 
Nested classes/interfaces inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractLocalWorldView
AbstractLocalWorldView.LazyCompositeObjectMap<T extends ICompositeWorldObject>
 
Field Summary
protected  Map<WorldObjectId,Set<DummyObjectEvent.EventType>> bufferedEvents
           
protected  List<DummyObjectEvent> eventBuffer
           
 
Fields inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.VisionLocalWorldView
syncVisibleClassMap, syncVisibleMap, visibleClassMap, visibleMap
 
Fields inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.EventDrivenLocalWorldView
notifyEventsList, receiveEventProcessing, WORLDVIEW_DEPENDENCY
 
Fields inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractLocalWorldView
actLocalWorldObjects, agentId, classMap, COMPONENT_ID, control, controller, eventBus, log, sharedWorldView, syncClassMap
 
Constructor Summary
BatchAwareLocalWorldView(ComponentDependencies dependencies, ILifecycleBus bus, IAgentLogger logger, ISharedWorldView parentWorldView, ITeamedAgentId agentId)
           
 
Method Summary
protected  void bufferObjectEvent(WorldObjectId id, DummyObjectEvent.EventType eventType, long time)
          This is used for raising object events safely by buffering the object events, we make sure that when the events are raised and listeners notified, the update event has been fully processed and the object contains correct and consistent data.
protected abstract  void disappearObject(WorldObjectId id, long time)
          Sets the visible property on the object to false by creating a disappeared event also raises correct events
protected  void flushEvents()
          Raises all events from this batch
protected abstract  boolean isBatchBeginEvent(IWorldChangeEvent event)
          Used to identify events marking beginning of batches.
protected abstract  boolean isBatchEndEvent(IWorldChangeEvent event)
          Used to detect batch end events, needs to be overriden to detect the events properly.
 boolean isLocked()
           
protected  void kill()
          Kills the world view.
 void lock()
          Must be called before starting logic.
 void notify(IWorldChangeEvent event)
          New event was generated from the world.
protected  void notifySharedBegin(long time)
          Notifies sharedWorldView that a beginEvent has been recieved with with the specified time and the sharedWorldView should notify this worldView back, when all events for the time have been processed.
protected  void objectAppeared(ILocalViewable obj, long time)
          Handles events for making the object visible.
protected  void objectCreated(ILocalWorldObject obj, long time)
          Must be called whenever an object was created, raises correct events.
protected  void objectDestroyed(ILocalWorldObject obj, long time)
          Must be called whenever an object was destroyed - raises correct events.
protected  void objectDisappeared(ILocalViewable obj, long time)
          Handles events for making the object not visible.
protected  void objectUpdated(ILocalWorldObject obj, long time)
          Must be called whenever an object was updated - raises correct event.
protected  void sharedBatchFinished(long time)
          This method is called when the SharedBatchFinishedEvent is recieved from the sharedWorldView, notifying us that all sharedEvents for the specified time have been processed and it is safe to run logic on the time.
protected  void stop()
          Stops the world view.
 void unlock()
          Called after the logic has finished.
 
Methods inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.VisionLocalWorldView
addVisible, getAllVisible, getAllVisible, getVisible, getVisible, objectUpdatedEvent, removeVisible
 
Methods inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.EventDrivenLocalWorldView
innerNotify, notifyAfterPropagation, notifyImmediately, raiseEvent
 
Methods inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractLocalWorldView
addEventListener, addLocalWorldObject, addObjectListener, addObjectListener, addObjectListener, addObjectListener, addOldLocalWorldObject, cleanUp, createCompositeObject, get, get, get, get, get, getAgentId, getAll, getAll, getAll, getAll, getComponentId, getCurrentTimeKey, getEventBus, getLocal, getLocal, getMostRecentLocalWorldObject, getSingle, getSingle, isListening, isListening, isListening, isListening, isListening, isListening, isPaused, isRunning, lockTime, pause, prePause, preStop, removeEventListener, removeListener, removeLocalWorldObject, removeObjectListener, removeObjectListener, removeObjectListener, removeObjectListener, reset, resume, setCurrentTime, setInitialTime, start, unlockTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.multi.communication.worldview.ILocalWorldView
addEventListener, addObjectListener, addObjectListener, addObjectListener, addObjectListener, get, get, get, getAgentId, getAll, getAll, getCurrentTimeKey, getEventBus, getLocal, getSingle, isListening, isListening, isListening, isListening, isListening, isListening, lockTime, notifyImmediately, removeEventListener, removeListener, removeObjectListener, removeObjectListener, removeObjectListener, removeObjectListener, setCurrentTime, setInitialTime, unlockTime
 
Methods inherited from interface cz.cuni.amis.pogamut.base.communication.worldview.IWorldChangeEventInput
notifyAfterPropagation
 
Methods inherited from interface cz.cuni.amis.pogamut.base.component.IComponent
getComponentId
 

Field Detail

bufferedEvents

protected Map<WorldObjectId,Set<DummyObjectEvent.EventType>> bufferedEvents

eventBuffer

protected List<DummyObjectEvent> eventBuffer
Constructor Detail

BatchAwareLocalWorldView

public BatchAwareLocalWorldView(ComponentDependencies dependencies,
                                ILifecycleBus bus,
                                IAgentLogger logger,
                                ISharedWorldView parentWorldView,
                                ITeamedAgentId agentId)
Method Detail

isBatchBeginEvent

protected abstract boolean isBatchBeginEvent(IWorldChangeEvent event)
Used to identify events marking beginning of batches. Override to provide correct behavior.

Parameters:
event -
Returns:

isBatchEndEvent

protected abstract boolean isBatchEndEvent(IWorldChangeEvent event)
Used to detect batch end events, needs to be overriden to detect the events properly.

Parameters:
event -
Returns:

notifySharedBegin

protected void notifySharedBegin(long time)
Notifies sharedWorldView that a beginEvent has been recieved with with the specified time and the sharedWorldView should notify this worldView back, when all events for the time have been processed.

Parameters:
time -

objectCreated

protected void objectCreated(ILocalWorldObject obj,
                             long time)
Description copied from class: EventDrivenLocalWorldView
Must be called whenever an object was created, raises correct events.

Might be overridden to provide different behavior.

Overrides:
objectCreated in class VisionLocalWorldView

objectUpdated

protected void objectUpdated(ILocalWorldObject obj,
                             long time)
Description copied from class: EventDrivenLocalWorldView
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).

Overrides:
objectUpdated in class EventDrivenLocalWorldView

objectDestroyed

protected void objectDestroyed(ILocalWorldObject obj,
                               long time)
Description copied from class: EventDrivenLocalWorldView
Must be called whenever an object was destroyed - raises correct events.

Might be overriden to provide different behavior.

Overrides:
objectDestroyed in class VisionLocalWorldView

objectAppeared

protected void objectAppeared(ILocalViewable obj,
                              long time)
Description copied from class: VisionLocalWorldView
Handles events for making the object visible.

Overrides:
objectAppeared in class VisionLocalWorldView

objectDisappeared

protected void objectDisappeared(ILocalViewable obj,
                                 long time)
Description copied from class: VisionLocalWorldView
Handles events for making the object not visible.

Overrides:
objectDisappeared in class VisionLocalWorldView

disappearObject

protected abstract void disappearObject(WorldObjectId id,
                                        long time)
Sets the visible property on the object to false by creating a disappeared event also raises correct events

Parameters:
id -
time -

bufferObjectEvent

protected void bufferObjectEvent(WorldObjectId id,
                                 DummyObjectEvent.EventType eventType,
                                 long time)
This is used for raising object events safely by buffering the object events, we make sure that when the events are raised and listeners notified, the update event has been fully processed and the object contains correct and consistent data. If you need to update objects manually and then want to raise events for whatever reason, always use this method.

Parameters:
id -
eventType -
time -

flushEvents

protected void flushEvents()
Raises all events from this batch


sharedBatchFinished

protected void sharedBatchFinished(long time)
This method is called when the SharedBatchFinishedEvent is recieved from the sharedWorldView, notifying us that all sharedEvents for the specified time have been processed and it is safe to run logic on the time.

Parameters:
time -

isLocked

public boolean isLocked()

lock

public void lock()
Must be called before starting logic.


unlock

public void unlock()
Called after the logic has finished.


notify

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

Specified by:
notify in interface IWorldChangeEventInput
Overrides:
notify in class VisionLocalWorldView

stop

protected void stop()
Description copied from class: AbstractLocalWorldView
Stops the world view.

If you override this method, do not forget to call super.stop().

Overrides:
stop in class AbstractLocalWorldView

kill

protected void kill()
Description copied from class: AbstractLocalWorldView
Kills the world view.

If you override this method, do not forget to call super.stop().

Overrides:
kill in class AbstractLocalWorldView


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