|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knime.core.node.NodeModel
org.knime.core.node.interrupt.InterruptibleNodeModel
public abstract class InterruptibleNodeModel
This class provides a generic implementation of a node that can be stopped and resumed during execution. Therefore a derived class has to provide a method which realizes one iteration of the algorithm that should be processed interruptible.
Field Summary | |
---|---|
static int |
INITIAL_DELAY
A constant to define the initial delay, so the algorithm and the slider have the same initial values. |
static int |
SLEEPING_MILLIS
A constant defining how long the execute thread should sleep, while waiting to resume again. |
Constructor Summary | |
---|---|
InterruptibleNodeModel(int nrInPorts,
int nrOutPorts)
Constructs a NodeModel with the desired in- and out-ports, setting the state to paused, that is waiting for an initial event to start executing. |
Method Summary | |
---|---|
BufferedDataTable[] |
execute(BufferedDataTable[] inData,
ExecutionContext exec)
Initialises the NodeModel, starts the execution, pauses it, resumes it and finishes it. |
abstract void |
executeOneIteration(ExecutionContext exec)
This method is assumed to implement one iteration of an interruptible algorithm. |
void |
finish()
Forces the algorithm to finish its execution. |
int |
getDelay()
Returns the current delay, that is the number of iterations until the view is refreshed. |
BufferedDataTable[] |
getInputData()
Returns the input data that was connected to the node at the beginning of the execute method as a whole. |
DataTable |
getInputData(int portNr)
Provides access to the input data the node is passed to at the beginning of the execute method. |
int |
getNumberOfIterations()
Returns the number of processed iterations so far. |
abstract BufferedDataTable[] |
getOutput(ExecutionContext exec)
Is called at the end of the execute method when it is finished and the data should be available. |
abstract void |
init(BufferedDataTable[] inData,
ExecutionContext exec)
Do here the initialisation of the model. |
boolean |
isFinished()
Indicates whether the state of the algorithm is finished or not. |
boolean |
isPaused()
Indicates whether the execution of the algorithm is paused or not. |
protected void |
loadInternals(File nodeInternDir,
ExecutionMonitor exec)
Load internals into the derived NodeModel . |
void |
next(int numberOfIterations)
Causes the execution of the next (n) iteration(s). |
void |
pause()
Causes the execution to pause until either next(int) or
run() is called. |
protected void |
reset()
Resets the status of the Node to paused and not finished so it can be triggered to start again. |
void |
run()
Causes the node to run for an unlimited number of iterations. |
protected void |
saveInternals(File nodeInternDir,
ExecutionMonitor exec)
Save internals of the derived NodeModel . |
void |
setDelay(int delay)
Sets the delay, that is the number of iterations until the view is refreshed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INITIAL_DELAY
public static final int SLEEPING_MILLIS
Constructor Detail |
---|
public InterruptibleNodeModel(int nrInPorts, int nrOutPorts)
nrInPorts
- - the desired number of in-ports.nrOutPorts
- - the desired number of out-ports.Method Detail |
---|
public int getNumberOfIterations()
public void setDelay(int delay)
delay
- - the number of iterations until the view is refreshed.public int getDelay()
public boolean isPaused()
public void pause()
next(int)
or
run()
is called.
public boolean isFinished()
public void finish()
public void next(int numberOfIterations)
numberOfIterations
- number of iterations to performpublic void run()
public DataTable getInputData(int portNr)
portNr
- - the referring inport number
public BufferedDataTable[] getInputData()
public final BufferedDataTable[] execute(BufferedDataTable[] inData, ExecutionContext exec) throws Exception
Node#executeNode()
method
of the node (through the
#executeModel(BufferedDataTable[],ExecutionMonitor)
method)only after all predecessor nodes have been successfully executed
and all data is therefore available at the input ports. Implement this
function with your task in the derived model.
The input data is available in the given array argument
inData
and is ensured to be neither null
nor contain null
elements.
In order to create output data, you need to create objects of class
BufferedDataTable
. Use the execution context argument to
create BufferedDataTable
.
execute
in class NodeModel
inData
- An array holding DataTable
elements, one for
each input.exec
- The execution monitor for this execute method. It provides us
with means to create new BufferedDataTable
.
Additionally, it should be asked frequently if the execution
should be interrupted and throws an exception then. This
exception might me caught, and then after closing all data
streams, been thrown again. Also, if you can tell the progress
of your task, just set it in this monitor.
null
DataTable elements with the
size of the number of outputs. The result of this execution.
Exception
- If you must fail the execution. Try to provide a
meaningful error message in the exception as it will be
displayed to the user.Please be advised to
check frequently the canceled status by invoking
ExecutionMonitor#checkCanceled
which will
throw an CanceledExcecutionException
and abort
the execution.protected void reset()
reset
in class NodeModel
NodeModel.reset()
protected void loadInternals(File nodeInternDir, ExecutionMonitor exec) throws IOException, CanceledExecutionException
NodeModel
. This method is
only called if the Node
was executed. Read all your
internal structures from the given file directory to create your internal
data structure which is necessary to provide all node functionalities
after the workflow is loaded, e.g. view content and/or hilite mapping.
loadInternals
in class NodeModel
nodeInternDir
- The directory to read from.exec
- Used to report progress and to cancel the load process.
IOException
- If an error occurs during reading from this dir.
CanceledExecutionException
- If the loading has been canceled.NodeModel.saveInternals(File,ExecutionMonitor)
protected void saveInternals(File nodeInternDir, ExecutionMonitor exec) throws IOException, CanceledExecutionException
NodeModel
. This method is
only called if the Node
is executed. Write all your
internal structures into the given file directory which are necessary to
recreate this model when the workflow is loaded, e.g. view content and/or
hilite mapping.
saveInternals
in class NodeModel
nodeInternDir
- The directory to write into.exec
- Used to report progress and to cancel the save process.
IOException
- If an error occurs during writing to this dir.
CanceledExecutionException
- If the saving has been canceled.NodeModel.loadInternals(File,ExecutionMonitor)
public abstract void executeOneIteration(ExecutionContext exec) throws CanceledExecutionException
exec
- the ExecutionContext to cancel the operation or show the
progress.
CanceledExecutionException
- if the operation is canceled by the
user.public abstract void init(BufferedDataTable[] inData, ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException
inData
- - the incoming DataTables at the moment the execute method
starts.exec
- to show the progress of the initialization or to cancel it.
CanceledExecutionException
- if the operation is canceled by the
user.
InvalidSettingsException
- - if the inData doesn't fit the expected
configuration.public abstract BufferedDataTable[] getOutput(ExecutionContext exec) throws CanceledExecutionException
exec
- The execution monitor to show the progress.
CanceledExecutionException
- If writing output tables has been
canceled.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |