ch.tatool.core.executable
Class BlockingExecutable

java.lang.Object
  extended by ch.tatool.core.element.AbstractPropertyHolder
      extended by ch.tatool.core.element.NodeImpl
          extended by ch.tatool.core.executable.BlockingExecutable
All Implemented Interfaces:
PropertyHolder, Executable, Node, KeyEventDispatcher
Direct Known Subclasses:
BlockingAWTExecutable

public abstract class BlockingExecutable
extends NodeImpl
implements Executable, KeyEventDispatcher

Blocking executable element implementation This implementation blocks the executable thread until finishExecution is called. Prior to calling finishExecution, a lock needs to be acquired. This way each thread finishing can first check whether it is "the first" or simply abort its operation in case it is not.

Author:
Michael Ruflin

Constructor Summary
BlockingExecutable()
           
BlockingExecutable(String defaultId)
           
 
Method Summary
 void cancel()
          Cancels the task.
protected  void cancelExecution()
          Called when cancel successfully acquires the finish execution lock.
 boolean dispatchKeyEvent(KeyEvent e)
           
 void execute()
          Implementation of execute.
protected  void finishExecution()
          Call this method to finish execution.
 ExecutionContext getExecutionContext()
           
protected  boolean getFinishExecutionLock()
          Request the lock to finish execution.
 void setExecutionContext(ExecutionContext executionContext)
           
protected abstract  void startExecution()
          Start actual execution.
 
Methods inherited from class ch.tatool.core.element.NodeImpl
assignParent, assignParent, assignParents, getId, getLocalId, getParent, setId, setLocalId, setParent
 
Methods inherited from class ch.tatool.core.element.AbstractPropertyHolder
clearProperties, getKeys, getProperty, removeProperty, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.tatool.element.Node
getParent, setParent
 
Methods inherited from interface ch.tatool.data.PropertyHolder
clearProperties, getId, getKeys, getProperty, removeProperty, setProperty
 

Constructor Detail

BlockingExecutable

public BlockingExecutable()

BlockingExecutable

public BlockingExecutable(String defaultId)
Method Detail

getExecutionContext

public ExecutionContext getExecutionContext()

setExecutionContext

public void setExecutionContext(ExecutionContext executionContext)
Specified by:
setExecutionContext in interface Executable

execute

public final void execute()
Implementation of execute. Will call startExecution on the awt thread and then block the caller thread until finishExecution is called

Specified by:
execute in interface Executable

startExecution

protected abstract void startExecution()
Start actual execution.


getFinishExecutionLock

protected boolean getFinishExecutionLock()
Request the lock to finish execution. This method needs to be called prior to calling finishExecution. Calling finishExecution is only allowed for the thread that receives true as a result.


finishExecution

protected void finishExecution()
Call this method to finish execution. Note that you need to request a lock from getFInishExecutionLock before calling this method. This method will release the Executors thread, so finish any work *before* calling this method.


cancel

public void cancel()
Cancels the task. This method fetches the finish execution lock and if successful calls cancelExecution. Once cancelExecution returns finishExecution is called

Specified by:
cancel in interface Executable

cancelExecution

protected void cancelExecution()
Called when cancel successfully acquires the finish execution lock.


dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent e)
Specified by:
dispatchKeyEvent in interface KeyEventDispatcher


Copyright © 2012. All Rights Reserved.