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

Package class diagram package EventDrivenSharedWorldView
java.lang.Object
  extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractSharedWorldView
      extended by cz.cuni.amis.pogamut.multi.communication.worldview.impl.EventDrivenSharedWorldView
All Implemented Interfaces:
IComponent, ISharedComponent, ISharedWorldChangeEventInput, ISharedWorldView
Direct Known Subclasses:
BatchAwareSharedWorldView

public abstract class EventDrivenSharedWorldView
extends AbstractSharedWorldView

SharedWorldView implementing basic event management (notyfying listeners --- not yet fully functional) and updating shared objects using the events. While some synchronization is done here, this worlview does not consider the events to come in batches and thus may create incosistent data structures. (this is addressed by BatchAwareSharedWorldView)

Author:
srlok

Field Summary
protected  PriorityBlockingQueue<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.
protected  Collection<IWorldChangeEvent> syncEventList
           
static String WORLDVIEW_DEPENDENCY
           
 
Fields inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractSharedWorldView
COMPONENT_ID, control, controller, currentSharedProperties, idClassMap, localWorldViews, log, sharedProperties, sharedWorldObjects, staticWorldObjects, syncCurrentSharedProperties, syncIdClassMap, syncSharedProperties, syncSharedWorldObjects
 
Constructor Summary
EventDrivenSharedWorldView(Logger logger)
           
 
Method Summary
 void addMsgClass(WorldObjectId id, Class msgClass)
           
protected  void innerNotify(IWorldChangeEvent event)
          Used to process IWorldChangeEvent - it has to be either IWorldChangeEvent or IWorldObjectUpdateEvent.
 void notify(IWorldChangeEvent event)
           
protected  void objectCreated(ISharedWorldObject obj, long time)
          Must be called whenever an object was created, raises correct events.
protected  void objectDestroyed(IWorldObject obj, long time)
          Must be called whenever an object was destroyed - raises correct events.
protected  void objectUpdated(ITeamId teamId, WorldObjectId objectId, long time)
          Must be called whenever an object was updated - raises correct event.
protected  void propertyCreated(ISharedProperty property, ITeamId team)
          If team is null, the property will be created for all teams.
protected  void propertyUpdated(ISharedProperty property, ITeamId team)
          Updates the property.
protected  void propertyUpdatedEvent(ISharedPropertyUpdatedEvent event)
          MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY!
protected  void raiseEvent(IWorldEvent event)
          Catches exceptions.
protected  void sharedObjectUpdatedEvent(ISharedWorldObjectUpdatedEvent updateEvent)
          Called from EventDrivenWorldView.innerNotify(IWorldChangeEvent) if the event is IWorldObjectUpdatedEvent to process it.
protected  void staticObjectUpdatedEvent(IStaticWorldObjectUpdatedEvent event)
          Manages updating static objects, only possible event types are CREATED and DESTROYED, any other event type raises an exception.
 
Methods inherited from class cz.cuni.amis.pogamut.multi.communication.worldview.impl.AbstractSharedWorldView
addComponentBus, addEventListener, addObjectListener, addObjectListener, addObjectListener, addObjectListener, addOldSharedProperty, addSharedProperty, addSharedProperty, addSharedWorldObject, addStaticWorldObject, cleanUp, createSharedObject, getComponentId, getShared, getSharedProperties, getSharedProperty, getStatic, isListening, isListening, isListening, isListening, isListening, isListening, isPaused, isRunning, kill, pause, prePause, preStop, registerLocalWorldView, removeComponentBus, removeEventListener, removeListener, removeObjectListener, removeObjectListener, removeObjectListener, removeObjectListener, removeSharedProperty, removeSharedProperty, removeStaticWorldObject, removeStaticWorldObject, reset, resume, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WORLDVIEW_DEPENDENCY

public static final 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 PriorityBlockingQueue<IWorldChangeEvent> notifyEventsList
List of events we have to process.

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


syncEventList

protected Collection<IWorldChangeEvent> syncEventList
Constructor Detail

EventDrivenSharedWorldView

public EventDrivenSharedWorldView(Logger logger)
Method Detail

notify

public void notify(IWorldChangeEvent event)
            throws ComponentNotRunningException,
                   ComponentPausedException
Throws:
ComponentNotRunningException
ComponentPausedException

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.

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
event -

raiseEvent

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

Overrides:
raiseEvent in class AbstractSharedWorldView

addMsgClass

public void addMsgClass(WorldObjectId id,
                        Class msgClass)

sharedObjectUpdatedEvent

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

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
updateEvent -

propertyUpdatedEvent

protected void propertyUpdatedEvent(ISharedPropertyUpdatedEvent event)
MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
event -

staticObjectUpdatedEvent

protected void staticObjectUpdatedEvent(IStaticWorldObjectUpdatedEvent event)
Manages updating static objects, only possible event types are CREATED and DESTROYED, any other event type raises an exception.

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
event -

propertyCreated

protected void propertyCreated(ISharedProperty property,
                               ITeamId team)
If team is null, the property will be created for all teams.

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
property -
team -

propertyUpdated

protected void propertyUpdated(ISharedProperty property,
                               ITeamId team)
Updates the property. This method is not responsible for adding old versions of the object.

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
property -
team -

objectCreated

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

Might be overridden to provide different behavior.

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
obj -

objectUpdated

protected void objectUpdated(ITeamId teamId,
                             WorldObjectId objectId,
                             long time)
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).

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
obj -

objectDestroyed

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

Might be overriden to provide different behavior.

MUST NOT BE CALLED CONCURRENTLY - SINGLE THREAD AT THIS POINT ONLY! MUST BE ENFORCED FROM THE OUTSIDE!

Parameters:
obj -


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