de.cau.cs.kieler.sim.kiem.execution
Class Execution

java.lang.Object
  extended by org.eclipse.core.runtime.PlatformObject
      extended by org.eclipse.core.internal.jobs.InternalJob
          extended by org.eclipse.core.runtime.jobs.Job
              extended by de.cau.cs.kieler.sim.kiem.execution.Execution
All Implemented Interfaces:
Comparable, IAdaptable

public class Execution
extends Job

The Class Execution. This is the base class for the whole execution. It creates and manages the worker threads for pure observer and pure producer components. It also implements the scheduling between all components. Additionally it manages a timeout component that checks whether a component-method exceeds the maximum timeout and then terminates all executions w/ an error log message.

Rating proposed yellow
(2009-01-15)

Field Summary
 
Fields inherited from class org.eclipse.core.runtime.jobs.Job
ASYNC_FINISH, BUILD, DECORATE, INTERACTIVE, LONG, NONE, RUNNING, SHORT, SLEEPING, WAITING
 
Fields inherited from class org.eclipse.core.internal.jobs.InternalJob
manager
 
Constructor Summary
Execution(List<DataComponentWrapper> dataComponentWrapperListParam, EventManager eventManagerParam)
          Instantiates and starts a new execution (thread).
 
Method Summary
 void abortExecutionAsync()
          Aborts the execution.
 void errorTerminate()
          Terminates the execution in case of an error.
protected  void finalize()
           
 int getAimedStepDuration()
          Gets the last set and currently used aimed step duration.
 int getAverageStepDuration()
          Gets the measured average step duration.
 JSONDataPool getDataPool()
          Gets the data pool.
 long getExecutionDuration()
          Gets the execution duration.
 IProgressMonitor getExecutionProgressMonitor()
          Gets the progress monitor.that the user may have canceled.
 long getExecutionStartTime()
          Gets the execution start time.
 int getMaximumStepDuration()
          Gets the measured maximum step duration.
 long getMaximumSteps()
          Gets the maximum step.
 int getMinimumStepDuration()
          Gets the measured minimum step duration.
 int getStepDuration()
          Gets the currently set aimed step duration.
 long getSteps()
          Gets the current step.
 int getWeightedAverageStepDuration()
          Gets the measured weighted average step duration.
 boolean isHistoryStep()
          Checks whether the current step is a history step.
 boolean isPaused()
          Only returns true if no more steps have to be done (forward AND backward).
 boolean isRunning()
          Checks if the execution is in run mode.
 boolean isStarted()
          Checks whether isStarted is true.
 void macroStepExecutionSync()
          Macro step execution sync.
 void pauseExecutionSync()
          Pauses the execution.
protected  IStatus run(IProgressMonitor monitor)
          Run.
 boolean runExecutionPause(long step)
          Run execution to the specific, user defined step number and pause.
 void runExecutionSync()
          Runs the execution.
 void setAimedStepDuration(int aimedStepDurationParam)
          Sets the aimed step duration.
 void showError(String textMessage, String pluginID, Exception e)
          A proxy method for showing an error from within an ObserverExecution, a.
 void showWarning(String textMessage, String pluginID, Exception e)
          A proxy method for showing a warning from within an ObserverExecution, a.
 boolean stepBackExecutionSync()
          Make a backward execution step.
 boolean stepExecutionPause(long step)
          Step execution to the specific, user defined step number and pause.
 boolean stepExecutionSync()
          Make a forward execution step.
 void stopExecutionSync()
          Stops the execution.
 void wrapupComponents(boolean quietmode)
          Wrap-up components after execution was stopped.
 
Methods inherited from class org.eclipse.core.runtime.jobs.Job
addJobChangeListener, belongsTo, cancel, canceling, done, getJobManager, getName, getPriority, getProperty, getResult, getRule, getState, getThread, isBlocking, isSystem, isUser, join, removeJobChangeListener, schedule, schedule, setName, setPriority, setProgressGroup, setProperty, setRule, setSystem, setThread, setUser, shouldRun, shouldSchedule, sleep, toString, wakeUp, wakeUp, yieldRule
 
Methods inherited from class org.eclipse.core.internal.jobs.InternalJob
compareTo
 
Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
 

Constructor Detail

Execution

public Execution(List<DataComponentWrapper> dataComponentWrapperListParam,
                 EventManager eventManagerParam)
Instantiates and starts a new execution (thread).

Parameters:
dataComponentWrapperListParam - the current DataComponentWrapper
eventManagerParam - the evenet manager param
Method Detail

isStarted

public boolean isStarted()
Checks whether isStarted is true. This is the case whenever the execution is up an running (already initialized and not aborted yet).

Returns:
true, if is started

getDataPool

public JSONDataPool getDataPool()
Gets the data pool. Be careful with using the DataPool after starting the thread!

Returns:
the data pool

getStepDuration

public int getStepDuration()
Gets the currently set aimed step duration.

Returns:
the step duration

getMaximumStepDuration

public int getMaximumStepDuration()
Gets the measured maximum step duration.

Returns:
the maximum step duration

getMinimumStepDuration

public int getMinimumStepDuration()
Gets the measured minimum step duration.

Returns:
the minimum step duration

getWeightedAverageStepDuration

public int getWeightedAverageStepDuration()
Gets the measured weighted average step duration.

Returns:
the weighted average step duration

getAverageStepDuration

public int getAverageStepDuration()
Gets the measured average step duration.

Returns:
the average step duration

getExecutionStartTime

public long getExecutionStartTime()
Gets the execution start time.

Returns:
the execution start time

getExecutionDuration

public long getExecutionDuration()
Gets the execution duration.

Returns:
the execution duration

getSteps

public long getSteps()
Gets the current step.

Returns:
the step

getMaximumSteps

public long getMaximumSteps()
Gets the maximum step. This usually not differs by more than 1 from the current step (

Returns:
the maximum step getSteps()), unless the current step is a history step.

isHistoryStep

public boolean isHistoryStep()
Checks whether the current step is a history step.

Returns:
true, if the current step is a history step

setAimedStepDuration

public void setAimedStepDuration(int aimedStepDurationParam)
Sets the aimed step duration. This is usually called from outside during the execution, if the user modifies the value in the GUI.

Parameters:
aimedStepDurationParam - the new aimed step duration

getAimedStepDuration

public int getAimedStepDuration()
Gets the last set and currently used aimed step duration.

Returns:
the aimed step duration

stepExecutionPause

public boolean stepExecutionPause(long step)
Step execution to the specific, user defined step number and pause. If this is a step number in the future then run the execution until the stepCounter has reached this number. If this is a step number in the history, then just jump (backwards/forwards) to it.

Parameters:
step - the step to jump/run to
Returns:
true, if step is being processed

runExecutionPause

public boolean runExecutionPause(long step)
Run execution to the specific, user defined step number and pause. If this is a step number in the future then run the execution until the stepCounter has reached this number. If this is a step number back in the history, then just jump to it. If this is a step number somewhere later in the history, then also run to it.

Parameters:
step - the step to jump/run to
Returns:
true, if step is being processed

stepBackExecutionSync

public boolean stepBackExecutionSync()
Make a backward execution step. Because we do not want to block the GUI or a calling master component, if the currently processed step is not yet done, this method returns false and no processes another step. Otherwise, if the last step was already processed, the method will schedule the next step but will return asynchronously. It will first synchronously inform all components about the step command.

Returns:
true, if step is being processed

stepExecutionSync

public boolean stepExecutionSync()
Make a forward execution step. Because we do not want to block the GUI or a calling master component, if the currently processed step is not yet done, this method returns false and no processes another step. Otherwise, if the last step was already processed, the method will schedule the next step but will return asynchronously. It will first synchronously inform all components about the step command.

Returns:
true, if step is being processed

macroStepExecutionSync

public void macroStepExecutionSync()
Macro step execution sync.

NOTE: This method has not been implemented yet!


pauseExecutionSync

public void pauseExecutionSync()
Pauses the execution. The pauseCommand flag is set to true to immediately pause the execution. Before the steps are being set to NO_STEPS the DataComponents are informed about the pause command.


runExecutionSync

public void runExecutionSync()
Runs the execution. The pausedCommand flag is set to false and the steps are being set to infinity, which is interpreted by the run(IProgressMonitor) method. Before that is done the DataComponents are informed about the run command.


stopExecutionSync

public void stopExecutionSync()
Stops the execution. In this case the stop flag is immediately set so that no further step is made. The data components are then being informed about the stop command. For safety reasons we again set the stop flag in synchronized monitor of this object and then stop all worker threads that where started. The latter includes the timeout thread.


abortExecutionAsync

public void abortExecutionAsync()
Aborts the execution. In this case the stop flag is immediately set so that no further step is made. The data components are then being informed about the stop command. For safety reasons we again set the stop flag in synchronized monitor of this object and then stop all worker threads that where started. The latter includes the timeout thread.


isPaused

public boolean isPaused()
Only returns true if no more steps have to be done (forward AND backward). This is *NOT* necessary equivalent to the term "!isRunning()"!

Returns:
true, if is no further steps have to be done

isRunning

public boolean isRunning()
Checks if the execution is in run mode. This means forward steps are produced automatically with the given (aimed) step duration.

Returns:
true, if execution is running

errorTerminate

public void errorTerminate()
Terminates the execution in case of an error. This will also (try) to terminate all created helper threads. They may not finish immediately and in case of a deadlock they won't do so ever, but the user will get a response. This function is called by the TimeoutThread. Hence the call of this method should only happen during the development of a new component.


finalize

protected void finalize()
Overrides:
finalize in class Object

wrapupComponents

public void wrapupComponents(boolean quietmode)
Wrap-up components after execution was stopped. The quietmode should only be used if the wrapupComponents is called by the handleComponentError to not get any recusive call!

Parameters:
quietmode - the quietmode ommits any errors

getExecutionProgressMonitor

public IProgressMonitor getExecutionProgressMonitor()
Gets the progress monitor.that the user may have canceled.

Returns:
the progress monitor

run

protected IStatus run(IProgressMonitor monitor)
Run.

Specified by:
run in class Job
Parameters:
monitor - the monitor
Returns:
the i status

showError

public void showError(String textMessage,
                      String pluginID,
                      Exception e)
A proxy method for showing an error from within an ObserverExecution, a.

Parameters:
textMessage - the text message to display
pluginID - the plug-in id
e - the original Exception ProducerExecution or the TimeoutThread.

showWarning

public void showWarning(String textMessage,
                        String pluginID,
                        Exception e)
A proxy method for showing a warning from within an ObserverExecution, a.

Parameters:
textMessage - the text message to display
pluginID - the plug-in id
e - the original Exception ProducerExecution or the TimeoutThread.