cz.cuni.amis.pogamut.ut2004.communication.worldview
Class UT2004SyncLockableWorldView

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
          extended by cz.cuni.amis.pogamut.base3d.worldview.impl.VisionWorldView
              extended by cz.cuni.amis.pogamut.base3d.worldview.impl.BatchAwareWorldView
                  extended by cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004WorldView
                      extended by cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004SyncLockableWorldView
All Implemented Interfaces:
ILockableWorldView, IWorldChangeEventInput, IWorldView, IComponent, ILockableVisionWorldView, IVisionWorldView

public class UT2004SyncLockableWorldView
extends UT2004WorldView
implements ILockableVisionWorldView

Lockable word view.

Contains GameBots2004 correct locking of the worldview.

All messages are processed always in batches (all messages between EndMessages are one batch) meaning that the world view is always correct!

When worldview is lock()ed it postpones the events until unlock()ed, which is triggering raising all events that came from the lock().

lock() method here blocks until the END message of the batch is hit, then the world view is considered to be fully locked and let the lock() continue. You may use it to create correct sync bot. (just lock() the world view before your logic and unlock() the world view after the logic finishes)

The world view is unlocked from the beginning.

The locking mechanism starts to work with the first BeginMessage. (To let all other events to be processed automatically during the handshake.)

See Also:
UT2004LockableWorldView

Field Summary
static java.lang.String WORLDVIEW_DEPENDENCY
           
 
Fields inherited from class cz.cuni.amis.pogamut.base.communication.worldview.impl.EventDrivenWorldView
notifyEventsList, receiveEventProcessing
 
Fields inherited from class cz.cuni.amis.pogamut.base.communication.worldview.impl.AbstractWorldView
COMPONENT_ID, control, controller, eventBus, log
 
Constructor Summary
UT2004SyncLockableWorldView(ComponentDependencies dependencies, IMediator mediator, IComponentBus bus, IAgentLogger log)
           
 
Method Summary
 boolean isInLock()
           
 boolean isLocked()
          Whether the worldview is locked.
 void lock()
          When the world view is locked - no batches are processes until unlocked.
 void notify(IWorldChangeEvent event)
          Implements locking logic.
protected  void prePause()
          Pre-pauses the world view.
protected  void preStop()
          Pre-stops the world view.
protected  void resume()
          Resumes the world view.
protected  void start(boolean startPaused)
          Starts the world view.
protected  void stop()
          Stops the world view.
 void unlock()
          Unlocks the world view - triggers processing of all events till the last EndMessage that came between lock() / unlock() calls.
 
Methods inherited from class cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004WorldView
isBatchBeginEvent, isBatchEndEvent, setDisappearedFlag
 
Methods inherited from class cz.cuni.amis.pogamut.base3d.worldview.impl.BatchAwareWorldView
batchAwareWorldViewNotify, hasObjectsToProcess, notifyImmediately, objectAppeared, objectDisappeared
 
Methods inherited from class cz.cuni.amis.pogamut.base3d.worldview.impl.VisionWorldView
addVisibleObject, cleanUp, getAllVisible, getAllVisible, getVisible, getVisible, objectCreated, objectDestroyed, objectUpdatedEvent, removeVisibleObject
 
Methods inherited from class cz.cuni.amis.pogamut.base.communication.worldview.impl.EventDrivenWorldView
innerNotify, objectUpdated, raiseEvent
 
Methods inherited from class cz.cuni.amis.pogamut.base.communication.worldview.impl.AbstractWorldView
addEventListener, addObjectListener, addObjectListener, addObjectListener, addObjectListener, addWorldObject, get, get, getAll, getAll, getComponentId, getEventBus, getLog, getSingle, isListening, isListening, isListening, isListening, isListening, isListening, isPaused, isRunning, kill, pause, removeEventListener, removeListener, removeObjectListener, removeObjectListener, removeObjectListener, removeObjectListener, removeWorldObject, reset, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.base3d.worldview.IVisionWorldView
getAllVisible, getAllVisible, getVisible, getVisible
 
Methods inherited from interface cz.cuni.amis.pogamut.base.communication.worldview.IWorldView
addEventListener, addObjectListener, addObjectListener, addObjectListener, addObjectListener, get, get, getAll, getAll, getEventBus, getSingle, isListening, isListening, isListening, isListening, isListening, isListening, removeEventListener, removeListener, removeObjectListener, removeObjectListener, removeObjectListener, removeObjectListener
 
Methods inherited from interface cz.cuni.amis.pogamut.base.communication.worldview.IWorldChangeEventInput
notifyImmediately
 
Methods inherited from interface cz.cuni.amis.pogamut.base.component.IComponent
getComponentId
 

Field Detail

WORLDVIEW_DEPENDENCY

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

UT2004SyncLockableWorldView

@Inject
public UT2004SyncLockableWorldView(ComponentDependencies dependencies,
                                          IMediator mediator,
                                          IComponentBus bus,
                                          IAgentLogger log)
Method Detail

lock

public void lock()
          throws PogamutInterruptedException,
                 ComponentNotRunningException
When the world view is locked - no batches are processes until unlocked.

Specified by:
lock in interface ILockableWorldView
Throws:
PogamutInterruptedException
ComponentNotRunningException

unlock

public void unlock()
            throws ComponentNotRunningException
Unlocks the world view - triggers processing of all events till the last EndMessage that came between lock() / unlock() calls.

Specified by:
unlock in interface ILockableWorldView
Throws:
ComponentNotRunningException

isLocked

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

Specified by:
isLocked in interface ILockableWorldView
Returns:

isInLock

public boolean isInLock()

notify

public void notify(IWorldChangeEvent event)
Implements locking logic.

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

start

protected void start(boolean startPaused)
Description copied from class: AbstractWorldView
Starts the world view.

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

Overrides:
start in class AbstractWorldView

preStop

protected void preStop()
Description copied from class: AbstractWorldView
Pre-stops the world view.

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

Overrides:
preStop in class AbstractWorldView

prePause

protected void prePause()
Description copied from class: AbstractWorldView
Pre-pauses the world view.

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

Overrides:
prePause in class AbstractWorldView

resume

protected void resume()
Description copied from class: AbstractWorldView
Resumes the world view.

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

Overrides:
resume in class AbstractWorldView

stop

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

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

Overrides:
stop in class AbstractWorldView