Package jsl.simulation
Class IterativeProcess<T>
- java.lang.Object
-
- jsl.simulation.IterativeProcess<T>
-
- Type Parameters:
T
- the type that represents the step
- All Implemented Interfaces:
ObservableIfc
,IterativeProcessIfc
,GetNameIfc
- Direct Known Subclasses:
Executive.EventExecutionProcess
,IPRootFinder
,Simulation.ReplicationExecutionProcess
public abstract class IterativeProcess<T> extends java.lang.Object implements ObservableIfc, IterativeProcessIfc
A IterativeProcess is an abstract base class for modeling the execution of a series of steps until some condition is met or until the number of steps have been exhausted. An iterative process will stop when one of the following occurs: a) It has no more steps to execute b) A condition becomes true after a step i) A user supplied (real) time limit has been (approximately) reached ii) Calling the stop() method based on some condition iii) Calling end() when in state Created, Initialized, or StepCompleted An iterative process follows a well defined state transition pattern. An iterative process has the following states: (Created, Initialized, StepCompleted, Ended). An iterative process is first created and placed in the Created state. From the Created state it can transition to Initialized (via initialize()) or Ended (via end()). From the Ended state it can transition to Initialized (via initialize()). From the Initialized state it can transition to StepCompleted (via runNext()) or to Ended (via run() or end()). From the StepCompleted state it can transition back to StepCompleted (via runNext()) or to Ended (via run(), runNext(), or end()). Thus, a common usage of an IterativeProcess is to call initialize() after construction and call runNext() to run each step of the process as needed. An IterativeProcess can also run to completion by calling run(). Subclasses must provide the following abstract protected methods: boolean hasNext(): checks if there is a next step T next(): gets an object that represents the next step void runStep(): causes the next step to execute, if no step exists then a run time exception, NoSuchStepException, will be thrown. If a client attempts an illegal state transition, then a run time exception, IllegalStateException, will be thrown. Sub-classes should also consider overriding initializeIterations() and endIterations() to provide specific initialization logic and logic for after the process ends. When overriding these methods care should be taken to properly call super.initializeIterations() and super.endIterations() otherwise non-determinant behavior will occur. The pattern is general enough to allow IterativeProcesses to run other IterativeProcesses within each step.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
IterativeProcess.Created
protected class
IterativeProcess.Ended
protected class
IterativeProcess.Initialized
protected class
IterativeProcess.IterativeState
protected class
IterativeProcess.ShowElapsedTimeTask
protected class
IterativeProcess.StepCompleted
-
Field Summary
Fields Modifier and Type Field Description static int
COMPLETED_ALL_STEPS
Indicates whether the iterative process has completed running all stepsprotected java.lang.String
COMPLETED_ALL_STEPS_MSG
Message used when process completes all stepsstatic int
EXCEEDED_EXECUTION_TIME
Indicates whether the iterative process has exceeded its maximum execution timeprotected java.lang.String
EXCEEDED_EXECUTION_TIME_MSG
Message used when process exceeds its execution timestatic int
MET_STOPPING_CONDITION
Indicates whether the iterative process ended due to the being stoppedprotected java.lang.String
MET_STOPPING_CONDITION_MSG
Message used when process stops because it met a conditionprotected long
myBeginExecutionTime
The wall clock time in milliseconds that the iterative process startedprotected IterativeProcess.Created
myCreatedState
A reference to the created state for the iterative process A iterative process is in the created state when it is first constructed and can then only transition to the initialized stateprotected T
myCurrentStep
A reference to an object related to the current step of the process It can be passed to observersprotected boolean
myDoneFlag
A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was canceled by a client prior to completing all of its steps 3) it exceeded its maximum allowable execution time before completing all of its steps.protected IterativeProcess.Ended
myEndedState
A reference to the ended state of the iterative process A iterative process is in the ended state after the process is told to endprotected long
myEndExecutionTime
The wall clock time in milliseconds that the iterative process endedprotected int
myEndingStateIndicator
indicates how the iterative process endedprotected long
myId
The id of this objectprotected boolean
myInitFlag
A flag that indicates whether or not the iterative process has already been initialized, false means it has not been initialized, true means that it has been initializedprotected IterativeProcess.Initialized
myInitializedState
A reference to the initialized state of the iterative process A iterative process is in the initialized state after the initialize() method is called from a proper state.protected IPLogReport
myIPLogReport
Used to log state changesprotected long
myMaxAllowedExecutionTime
The maximum allowable execution time "wall" clock time for the iterative process to complete processing in millisecondsprotected java.lang.String
myName
The name of this stepprotected ObservableComponent
myObservableComponent
Allows the IterativeProcess to be observable.protected boolean
myRunningFlag
Indicates that the iterative process is runningprotected boolean
myRunningStepFlag
Indicates if the iterative process is currently running an individual step, true if the step is in progressprotected boolean
mySaveStepOption
A flag to indicate whether or not the iterative process will save the steps as they are created and then run in a Collection The default is FALSE (they will be not be saved).protected IterativeProcess.IterativeState
myState
A reference to the current state of the iterative processprotected IterativeProcess.StepCompleted
myStepCompletedState
A reference to the step completed state of the iterative process A iterative process is in the step completed state after the runNext method is called from a proper stateprotected long
myStepCounter
Counts the number of steps executed since the last time the process was initializedprotected java.util.List<T>
mySteps
A collection of all the steps that have been run by this iterative process.protected long
myTBConsoleUpdates
The time between task invocations for the Timer and its TimerTaskprotected java.util.Timer
myTimer
A Timer used to perform timed task e.g.protected java.util.TimerTask
myTimerTask
The task that the timer usesstatic int
NO_STEPS_EXECUTED
Indicates whether the iterative process haD no steps to runprotected java.lang.String
NO_STEPS_EXECUTED_MSG
Message used when process completes all stepsstatic int
UNFINISHED
Indicates that the iterative process is in progressprotected java.lang.String
UNFINISHED_MSG
Message used when process is not finished
-
Constructor Summary
Constructors Constructor Description IterativeProcess()
Constructs an iterative process with default nameIterativeProcess(java.lang.String name)
Constructs an iterative process with the given name
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addObserver(ObserverIfc observer)
Allows the adding (attaching) of an observer to the observableboolean
allStepsCompleted()
The iterative process may end by a variety of means, this method checks if the iterative process ended because it ran all of its stepsprotected void
checkStoppingCondition()
protected void
checkStoppingCondition_()
protected void
consoleOutput()
Can be overwritten by subclasses to have output when the console flag is onboolean
contains(ObserverIfc observer)
Returns true if the observer is already attachedint
countObservers()
Returns how many observers are currently observing the observablevoid
deleteObserver(ObserverIfc observer)
Allows the deletion (removing) of an observer from the observablevoid
deleteObservers()
Deletes all the observers from the observablevoid
end()
The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first.void
end(java.lang.String msg)
The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first.protected void
endIterations()
boolean
executionTimeExceeded()
The iterative process may end by a variety of means, this method checks if the iterative process ended because it timed outlong
getBeginExecutionTime()
Returns system time in milliseconds that the iterative process startedjava.lang.String
getCurrentStateAsString()
Gets the current state as a stringT
getCurrentStep()
Returns the current step for the iterative process the step that is or has just completed processing Note: Sub-classes are responsible for properly setting the current step when a step is run via runStep()long
getElapsedExecutionTime()
Gets the clock time in milliseconds since the iterative process was initializedlong
getEndExecutionTime()
Returns system time in milliseconds that the iterative process endedint
getEndingStateIndicator()
Returns the ending state indicatorjava.lang.String
getEndingStateIndicatorAsString()
Returns a string representation of the ending state indicator COMPLETED_ALL_STEPS_MSG EXCEEDED_EXECUTION_TIME_MSG MET_STOPPING_CONDITION_MSG UNFINISHED_MSGlong
getId()
Returns the id for this iterative processIPLogReport
getLogReport()
Returns a reference to the current log report.long
getMaximumAllowedExecutionTime()
Returns maximum (real) clock time allocated for the iterative processjava.lang.String
getName()
Gets the name.long
getNumberStepsCompleted()
Returns the number of steps completed since the iterative process was last initializedboolean
getSaveStepOption()
Gets the save step option, true means that the steps will be saved by the iterative process into a Collection after runningjava.util.Iterator<T>
getStepIterator()
Returns an iterator to the saved stepsjava.util.List<T>
getStepList()
Returns an unmodifiable list view of the steps that have been savedboolean
getStoppingFlag()
Returns the stopping flagjava.lang.String
getStoppingMessage()
A string message for why stop() was called.protected abstract boolean
hasNext()
This method should check to see if another step is necessary for the iterative process.void
initialize()
Initializes the iterative process prior to running any steps This must be done prior to calling runNext();protected void
initializeIterations()
boolean
isCreated()
Checks if the iterative process is in the created state.boolean
isDone()
A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was ended by a client prior to completing all of its steps 3) it ended because it exceeded its maximum allowable execution time before completing all of its steps.boolean
isEnded()
Checks if the iterative process is in the ended state After the iterative process has been ended this method will return trueboolean
isExecutionTimeExceeded()
Returns if the elapsed execution time exceeds the maximum time allowed.boolean
isInitialized()
Checks if the iterative process is in the initialized state After the iterative process has been initialized this method will return trueboolean
isRunning()
An iterative process is running if it is been told to run (i.e.boolean
isRunningStep()
Indicates that the iterative process is currently running an individual stepboolean
isStepCompleted()
Checks if the iterative process is in the completed step state After the iterative process has successfully completed a step this method will return trueboolean
isUnfinished()
The iterative process may end by a variety of means, this method checks if the iterative process ended but was unfinished, not all steps completedprotected abstract T
next()
This method should return the next step to be executed in the iterative process or null if no more steps can be executed.boolean
noStepsExecuted()
Indicates that the iterative process ended because of no stepsvoid
run()
Runs all of the steps of the iterative process.protected void
runAll_()
Runs all of the steps.void
runNext()
Runs the next step in the iterative processprotected void
runNext_()
protected abstract void
runStep()
This method tells the iterative process to execute the current step.protected void
setId()
Can be overridden to supply a unique id to the object By default a simple static counter is used to assign a number as instances are createdvoid
setMaximumExecutionTime(long milliseconds)
Set the maximum allotted (suggested) execution (real) clock for the entire iterative process.void
setName(java.lang.String str)
Sets the namevoid
setSaveStepOption(boolean option)
Sets the save step option, true means that the steps will be saved by the iterative process into a Collection after runningprotected void
setState(IterativeProcess.IterativeState state)
The method is used to set the state and notify observers of the changevoid
stop()
This sets a flag to indicate to the process that is should stop after the next step is completed.void
stop(java.lang.String msg)
This sets a flag to indicate to the process that is should stop after the next step is completed.boolean
stoppedByCondition()
The iterative process may end by a variety of means, this method checks if the iterative process ended because it was stoppedjava.lang.String
toString()
Gets a string for the iterative process.void
turnOffLogReport()
Turns off log reporting.void
turnOnLogReport(java.nio.file.Path pathToFile)
Turns on the log report.void
turnOnTimer(long milliseconds)
This method will cause the a timer to start allowing a TimerTask to be scheduled.
-
-
-
Field Detail
-
NO_STEPS_EXECUTED
public static final int NO_STEPS_EXECUTED
Indicates whether the iterative process haD no steps to run
-
COMPLETED_ALL_STEPS
public static final int COMPLETED_ALL_STEPS
Indicates whether the iterative process has completed running all steps
-
EXCEEDED_EXECUTION_TIME
public static final int EXCEEDED_EXECUTION_TIME
Indicates whether the iterative process has exceeded its maximum execution time
-
MET_STOPPING_CONDITION
public static final int MET_STOPPING_CONDITION
Indicates whether the iterative process ended due to the being stopped
-
UNFINISHED
public static final int UNFINISHED
Indicates that the iterative process is in progress
-
NO_STEPS_EXECUTED_MSG
protected java.lang.String NO_STEPS_EXECUTED_MSG
Message used when process completes all steps
-
COMPLETED_ALL_STEPS_MSG
protected java.lang.String COMPLETED_ALL_STEPS_MSG
Message used when process completes all steps
-
EXCEEDED_EXECUTION_TIME_MSG
protected java.lang.String EXCEEDED_EXECUTION_TIME_MSG
Message used when process exceeds its execution time
-
MET_STOPPING_CONDITION_MSG
protected java.lang.String MET_STOPPING_CONDITION_MSG
Message used when process stops because it met a condition
-
UNFINISHED_MSG
protected java.lang.String UNFINISHED_MSG
Message used when process is not finished
-
myId
protected long myId
The id of this object
-
myName
protected java.lang.String myName
The name of this step
-
myBeginExecutionTime
protected long myBeginExecutionTime
The wall clock time in milliseconds that the iterative process started
-
myEndExecutionTime
protected long myEndExecutionTime
The wall clock time in milliseconds that the iterative process ended
-
myMaxAllowedExecutionTime
protected long myMaxAllowedExecutionTime
The maximum allowable execution time "wall" clock time for the iterative process to complete processing in milliseconds
-
myDoneFlag
protected boolean myDoneFlag
A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was canceled by a client prior to completing all of its steps 3) it exceeded its maximum allowable execution time before completing all of its steps.
-
myRunningFlag
protected boolean myRunningFlag
Indicates that the iterative process is running
-
myRunningStepFlag
protected boolean myRunningStepFlag
Indicates if the iterative process is currently running an individual step, true if the step is in progress
-
myEndingStateIndicator
protected int myEndingStateIndicator
indicates how the iterative process ended
-
myCurrentStep
protected T myCurrentStep
A reference to an object related to the current step of the process It can be passed to observers
-
mySteps
protected java.util.List<T> mySteps
A collection of all the steps that have been run by this iterative process.
-
mySaveStepOption
protected boolean mySaveStepOption
A flag to indicate whether or not the iterative process will save the steps as they are created and then run in a Collection The default is FALSE (they will be not be saved).
-
myIPLogReport
protected IPLogReport myIPLogReport
Used to log state changes
-
myState
protected IterativeProcess.IterativeState myState
A reference to the current state of the iterative process
-
myCreatedState
protected final IterativeProcess.Created myCreatedState
A reference to the created state for the iterative process A iterative process is in the created state when it is first constructed and can then only transition to the initialized state
-
myInitializedState
protected final IterativeProcess.Initialized myInitializedState
A reference to the initialized state of the iterative process A iterative process is in the initialized state after the initialize() method is called from a proper state.
-
myStepCompletedState
protected final IterativeProcess.StepCompleted myStepCompletedState
A reference to the step completed state of the iterative process A iterative process is in the step completed state after the runNext method is called from a proper state
-
myEndedState
protected final IterativeProcess.Ended myEndedState
A reference to the ended state of the iterative process A iterative process is in the ended state after the process is told to end
-
myTimer
protected java.util.Timer myTimer
A Timer used to perform timed task e.g. displaying information about the IterativeProcess
-
myTBConsoleUpdates
protected long myTBConsoleUpdates
The time between task invocations for the Timer and its TimerTask
-
myTimerTask
protected java.util.TimerTask myTimerTask
The task that the timer uses
-
myInitFlag
protected boolean myInitFlag
A flag that indicates whether or not the iterative process has already been initialized, false means it has not been initialized, true means that it has been initialized
-
myStepCounter
protected long myStepCounter
Counts the number of steps executed since the last time the process was initialized
-
myObservableComponent
protected ObservableComponent myObservableComponent
Allows the IterativeProcess to be observable. Observers are notified when the state changes Created, Initialized, StepCompleted, Ended Observers have access to the IterativeProcess and the current step T
-
-
Method Detail
-
getName
public final java.lang.String getName()
Gets the name.- Specified by:
getName
in interfaceGetNameIfc
- Returns:
- The name of object.
-
setName
public final void setName(java.lang.String str)
Sets the name- Parameters:
str
- The name as a string.
-
getId
public final long getId()
Returns the id for this iterative process- Returns:
- the id
-
setId
protected final void setId()
Can be overridden to supply a unique id to the object By default a simple static counter is used to assign a number as instances are created
-
toString
public java.lang.String toString()
Gets a string for the iterative process.- Overrides:
toString
in classjava.lang.Object
- Returns:
- Yields the name and other facts for the iterative process.
-
getCurrentStateAsString
public final java.lang.String getCurrentStateAsString()
Gets the current state as a string- Returns:
- the current state as a string
-
getEndingStateIndicator
public final int getEndingStateIndicator()
Returns the ending state indicator- Returns:
- an integer representing the ending state
-
getEndingStateIndicatorAsString
public java.lang.String getEndingStateIndicatorAsString()
Returns a string representation of the ending state indicator COMPLETED_ALL_STEPS_MSG EXCEEDED_EXECUTION_TIME_MSG MET_STOPPING_CONDITION_MSG UNFINISHED_MSG- Returns:
- the string
-
isDone
public final boolean isDone()
A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was ended by a client prior to completing all of its steps 3) it ended because it exceeded its maximum allowable execution time before completing all of its steps. 4) its end condition was satisfied- Specified by:
isDone
in interfaceIterativeProcessIfc
- Returns:
- true if done
-
isCreated
public final boolean isCreated()
Description copied from interface:IterativeProcessIfc
Checks if the iterative process is in the created state. If the iterative process is in the created state this method will return true- Specified by:
isCreated
in interfaceIterativeProcessIfc
- Returns:
- true if in the created state
-
getBeginExecutionTime
public final long getBeginExecutionTime()
Returns system time in milliseconds that the iterative process started- Specified by:
getBeginExecutionTime
in interfaceIterativeProcessIfc
- Returns:
- the number as a long
-
getElapsedExecutionTime
public final long getElapsedExecutionTime()
Description copied from interface:IterativeProcessIfc
Gets the clock time in milliseconds since the iterative process was initialized- Specified by:
getElapsedExecutionTime
in interfaceIterativeProcessIfc
- Returns:
- a long representing the elapsed time
-
getEndExecutionTime
public final long getEndExecutionTime()
Description copied from interface:IterativeProcessIfc
Returns system time in milliseconds that the iterative process ended- Specified by:
getEndExecutionTime
in interfaceIterativeProcessIfc
- Returns:
- the number as a long
-
getMaximumAllowedExecutionTime
public final long getMaximumAllowedExecutionTime()
Description copied from interface:IterativeProcessIfc
Returns maximum (real) clock time allocated for the iterative process- Specified by:
getMaximumAllowedExecutionTime
in interfaceIterativeProcessIfc
- Returns:
- the number as long representing milliseconds
-
setMaximumExecutionTime
public final void setMaximumExecutionTime(long milliseconds)
Description copied from interface:IterativeProcessIfc
Set the maximum allotted (suggested) execution (real) clock for the entire iterative process. This is a suggested time because the execution time requirement is only checked after the completion of an individual step After it is discovered that cumulative time for executing the step has exceeded the maximum time, then the iterative process will be ended (perhaps) not completing other steps.- Specified by:
setMaximumExecutionTime
in interfaceIterativeProcessIfc
- Parameters:
milliseconds
- the time
-
getStoppingMessage
public final java.lang.String getStoppingMessage()
Description copied from interface:IterativeProcessIfc
A string message for why stop() was called.- Specified by:
getStoppingMessage
in interfaceIterativeProcessIfc
- Returns:
- the message
-
getSaveStepOption
public final boolean getSaveStepOption()
Gets the save step option, true means that the steps will be saved by the iterative process into a Collection after running- Returns:
- flag indicating the option
-
setSaveStepOption
public final void setSaveStepOption(boolean option)
Sets the save step option, true means that the steps will be saved by the iterative process into a Collection after running- Parameters:
option
- true if option is on
-
getStepIterator
public final java.util.Iterator<T> getStepIterator()
Returns an iterator to the saved steps- Returns:
- an iterator
-
getStepList
public final java.util.List<T> getStepList()
Returns an unmodifiable list view of the steps that have been saved- Returns:
- the list
-
getCurrentStep
public final T getCurrentStep()
Returns the current step for the iterative process the step that is or has just completed processing Note: Sub-classes are responsible for properly setting the current step when a step is run via runStep()- Returns:
- the current step
-
getNumberStepsCompleted
public final long getNumberStepsCompleted()
Description copied from interface:IterativeProcessIfc
Returns the number of steps completed since the iterative process was last initialized- Specified by:
getNumberStepsCompleted
in interfaceIterativeProcessIfc
- Returns:
- the number of steps completed
-
turnOnLogReport
public void turnOnLogReport(java.nio.file.Path pathToFile)
Description copied from interface:IterativeProcessIfc
Turns on the log report. This report yields a text file of the state changes for the iterative process- Specified by:
turnOnLogReport
in interfaceIterativeProcessIfc
- Parameters:
pathToFile
- specifies a prefix name for the report
-
turnOffLogReport
public void turnOffLogReport()
Description copied from interface:IterativeProcessIfc
Turns off log reporting.- Specified by:
turnOffLogReport
in interfaceIterativeProcessIfc
-
getLogReport
public final IPLogReport getLogReport()
Description copied from interface:IterativeProcessIfc
Returns a reference to the current log report.- Specified by:
getLogReport
in interfaceIterativeProcessIfc
- Returns:
- The log report
-
turnOnTimer
public final void turnOnTimer(long milliseconds)
Description copied from interface:IterativeProcessIfc
This method will cause the a timer to start allowing a TimerTask to be scheduled. This method causes a print to console task to be run which prints the elapsed time since initializing the iterative process.- Specified by:
turnOnTimer
in interfaceIterativeProcessIfc
- Parameters:
milliseconds
- the time for the timer
-
isInitialized
public final boolean isInitialized()
Description copied from interface:IterativeProcessIfc
Checks if the iterative process is in the initialized state After the iterative process has been initialized this method will return true- Specified by:
isInitialized
in interfaceIterativeProcessIfc
- Returns:
- true if initialized
-
isRunning
public final boolean isRunning()
Description copied from interface:IterativeProcessIfc
An iterative process is running if it is been told to run (i.e. runNext()) but has not yet been told to end().- Specified by:
isRunning
in interfaceIterativeProcessIfc
- Returns:
- true if running
-
isRunningStep
public final boolean isRunningStep()
Description copied from interface:IterativeProcessIfc
Indicates that the iterative process is currently running an individual step- Specified by:
isRunningStep
in interfaceIterativeProcessIfc
- Returns:
- true if the step is in progress
-
isStepCompleted
public final boolean isStepCompleted()
Description copied from interface:IterativeProcessIfc
Checks if the iterative process is in the completed step state After the iterative process has successfully completed a step this method will return true- Specified by:
isStepCompleted
in interfaceIterativeProcessIfc
- Returns:
- true if the iterative process completed the step
-
isEnded
public final boolean isEnded()
Description copied from interface:IterativeProcessIfc
Checks if the iterative process is in the ended state After the iterative process has been ended this method will return true- Specified by:
isEnded
in interfaceIterativeProcessIfc
- Returns:
- true if ended
-
noStepsExecuted
public final boolean noStepsExecuted()
Description copied from interface:IterativeProcessIfc
Indicates that the iterative process ended because of no steps- Specified by:
noStepsExecuted
in interfaceIterativeProcessIfc
- Returns:
- True if no steps are executed
-
allStepsCompleted
public final boolean allStepsCompleted()
Description copied from interface:IterativeProcessIfc
The iterative process may end by a variety of means, this method checks if the iterative process ended because it ran all of its steps- Specified by:
allStepsCompleted
in interfaceIterativeProcessIfc
- Returns:
- true if all completed
-
executionTimeExceeded
public final boolean executionTimeExceeded()
Description copied from interface:IterativeProcessIfc
The iterative process may end by a variety of means, this method checks if the iterative process ended because it timed out- Specified by:
executionTimeExceeded
in interfaceIterativeProcessIfc
- Returns:
- true if exceeded
-
stoppedByCondition
public final boolean stoppedByCondition()
Description copied from interface:IterativeProcessIfc
The iterative process may end by a variety of means, this method checks if the iterative process ended because it was stopped- Specified by:
stoppedByCondition
in interfaceIterativeProcessIfc
- Returns:
- true if it was stopped via stop()
-
isUnfinished
public final boolean isUnfinished()
Description copied from interface:IterativeProcessIfc
The iterative process may end by a variety of means, this method checks if the iterative process ended but was unfinished, not all steps completed- Specified by:
isUnfinished
in interfaceIterativeProcessIfc
- Returns:
- true if the process is not finished
-
initialize
public final void initialize()
Description copied from interface:IterativeProcessIfc
Initializes the iterative process prior to running any steps This must be done prior to calling runNext();- Specified by:
initialize
in interfaceIterativeProcessIfc
-
runNext
public final void runNext()
Description copied from interface:IterativeProcessIfc
Runs the next step in the iterative process- Specified by:
runNext
in interfaceIterativeProcessIfc
-
run
public final void run()
Description copied from interface:IterativeProcessIfc
Runs all of the steps of the iterative process. If the iterative process has not been initialized, then it will automatically be initialized. After attempting to run the steps, the process will be in the end() state. The process may or may not complete all of its steps.- Specified by:
run
in interfaceIterativeProcessIfc
-
stop
public final void stop(java.lang.String msg)
Description copied from interface:IterativeProcessIfc
This sets a flag to indicate to the process that is should stop after the next step is completed. This is different than end(). Calling end() immediately places the process in the End state. The process needs to be in a valid state before end() can be used. Calling stop tells the process to eventually get into the end state. stop() can be used to arbitrarily stop the process based on some user defined condition.- Specified by:
stop
in interfaceIterativeProcessIfc
- Parameters:
msg
- A string to represent the reason for the stopping
-
stop
public final void stop()
Description copied from interface:IterativeProcessIfc
This sets a flag to indicate to the process that is should stop after the next step is completed. This is different than end(). Calling end() immediately places the process in the End state. The process needs to be in a valid state before end() can be used. Calling stop tells the process to eventually get into the end state. stop() can be used to arbitrarily stop the process based on some user defined condition.- Specified by:
stop
in interfaceIterativeProcessIfc
-
getStoppingFlag
public final boolean getStoppingFlag()
Description copied from interface:IterativeProcessIfc
Returns the stopping flag- Specified by:
getStoppingFlag
in interfaceIterativeProcessIfc
- Returns:
- true if the process has been told to stop via stop()
-
end
public final void end(java.lang.String msg)
The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first. If this method is called the iterative process will end processing (terminate) before the next step and not process the next step in the process. The current step will be completed. This method can be used to end the process at an arbitrary step. Once ended, the process must be initialized to run again.- Specified by:
end
in interfaceIterativeProcessIfc
- Parameters:
msg
- an option message to indicate the reason for stopping
-
end
public final void end()
The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first. If this method is called the iterative process will end processing (terminate) before the next step and not process the next step in the process. The current step will be completed. This method can be used to end the process at an arbitrary step. Once ended, the process must be restarted via initialize().- Specified by:
end
in interfaceIterativeProcessIfc
-
hasNext
protected abstract boolean hasNext()
This method should check to see if another step is necessary for the iterative process. True means that the process has another step to be executed. False, means that no more steps are available for execution.- Returns:
- true if another step is present
-
next
protected abstract T next()
This method should return the next step to be executed in the iterative process or null if no more steps can be executed. It should advance the current step to the next step if it is available- Returns:
- the type of the step
-
runStep
protected abstract void runStep()
This method tells the iterative process to execute the current step. Typical usage is to call this after calling next() to advance to the next step. This method should throw a NoSuchStepException if there are no more steps to run and it is told to run the step.
-
consoleOutput
protected void consoleOutput()
Can be overwritten by subclasses to have output when the console flag is on
-
contains
public boolean contains(ObserverIfc observer)
Description copied from interface:ObservableIfc
Returns true if the observer is already attached- Specified by:
contains
in interfaceObservableIfc
- Parameters:
observer
- the observer to check- Returns:
- true if attached
-
deleteObservers
public final void deleteObservers()
Description copied from interface:ObservableIfc
Deletes all the observers from the observable- Specified by:
deleteObservers
in interfaceObservableIfc
-
deleteObserver
public final void deleteObserver(ObserverIfc observer)
Description copied from interface:ObservableIfc
Allows the deletion (removing) of an observer from the observable- Specified by:
deleteObserver
in interfaceObservableIfc
- Parameters:
observer
- the observer to delete
-
countObservers
public final int countObservers()
Description copied from interface:ObservableIfc
Returns how many observers are currently observing the observable- Specified by:
countObservers
in interfaceObservableIfc
- Returns:
- number of observers
-
addObserver
public final void addObserver(ObserverIfc observer)
Description copied from interface:ObservableIfc
Allows the adding (attaching) of an observer to the observable- Specified by:
addObserver
in interfaceObservableIfc
- Parameters:
observer
- the observer to attach
-
isExecutionTimeExceeded
public final boolean isExecutionTimeExceeded()
Returns if the elapsed execution time exceeds the maximum time allowed. Only true if the maximum was set and elapsed time is greater than or equal to getMaximumAllowedExecutionTime()- Specified by:
isExecutionTimeExceeded
in interfaceIterativeProcessIfc
- Returns:
- true if the execution time exceeds getMaximumAllowedExecutionTime()
-
setState
protected final void setState(IterativeProcess.IterativeState state)
The method is used to set the state and notify observers of the change- Parameters:
state
- the state
-
initializeIterations
protected void initializeIterations()
-
runAll_
protected final void runAll_()
Runs all of the steps. Each step is run, and finally the iterative process is ended.
-
runNext_
protected void runNext_()
-
checkStoppingCondition
protected void checkStoppingCondition()
-
checkStoppingCondition_
protected void checkStoppingCondition_()
-
endIterations
protected void endIterations()
-
-