games.strategy.engine.delegate
Class DelegateExecutionManager

java.lang.Object
  extended by games.strategy.engine.delegate.DelegateExecutionManager

public class DelegateExecutionManager
extends java.lang.Object

Manages when delegates are allowed to execute.

When saving a game, we want to ensure that no delegate is executing, otherwise the delegate could modify the state of the game while the game is being saved, resulting in an invalid save game.

This class effectivly keeps a count of how many threads are executing in the delegates, and provides a way of blocking further threads from starting execution in a delegate.

Author:
sgb

Constructor Summary
DelegateExecutionManager()
           
 
Method Summary
 boolean blockDelegateExecution(int timeToWaitMS)
          When this method returns true, threads will not be able to enter delegates until a call to resumeDelegateExecution is made.
 java.lang.Object createInboundImplementation(java.lang.Object implementor, java.lang.Class<?>[] interfaces)
          Use to create an object that begins delegate execution.
 java.lang.Object createOutboundImplementation(java.lang.Object implementor, java.lang.Class<?>[] interfaces)
          Used to create an object the exits delegate execution.
 void enterDelegateExecution()
           
 void leaveDelegateExecution()
           
 void resumeDelegateExecution()
          Allow delegate execution to resume.
 void setGameOver()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegateExecutionManager

public DelegateExecutionManager()
Method Detail

setGameOver

public void setGameOver()

blockDelegateExecution

public boolean blockDelegateExecution(int timeToWaitMS)
                               throws java.lang.InterruptedException
When this method returns true, threads will not be able to enter delegates until a call to resumeDelegateExecution is made.

When delegateExecution is blocked, it also blocks subsequent cals to blockDelegateExecution(...)

If timeToWaitMS is > 0, we will give up trying to block delegate execution after timeTiWaitMS has elapsed.

Parameters:
timeToWait -
Returns:
Throws:
java.lang.InterruptedException

resumeDelegateExecution

public void resumeDelegateExecution()
Allow delegate execution to resume.


createOutboundImplementation

public java.lang.Object createOutboundImplementation(java.lang.Object implementor,
                                                     java.lang.Class<?>[] interfaces)
Used to create an object the exits delegate execution.

Objects on this method will decrement the thread lock count when called, and will increment it again when execution is finished.


createInboundImplementation

public java.lang.Object createInboundImplementation(java.lang.Object implementor,
                                                    java.lang.Class<?>[] interfaces)
Use to create an object that begins delegate execution.

Objects on this method will increment the thread lock count when called, and will decrement it again when execution is finished.


leaveDelegateExecution

public void leaveDelegateExecution()

enterDelegateExecution

public void enterDelegateExecution()