|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knime.core.node.NodeModel
public abstract class NodeModel
Abstract class defining a node's configuration and execution (among others). More specifically, it defines:
execute(PortObject[], ExecutionContext)
and
configure(PortObjectSpec[])
methods for general
port definitions (rarely used) or
execute(BufferedDataTable[], ExecutionContext)
and
configure(DataTableSpec[])
methods for standard data ports
(on both in- and outports).
For a detailed description of this class refer to KNIME's extension guide and the various node implementations.
Constructor Summary | |
---|---|
protected |
NodeModel(int nrInDataPorts,
int nrOutDataPorts)
Creates a new model with the given number of input and output data ports. |
protected |
NodeModel(PortType[] inPortTypes,
PortType[] outPortTypes)
Creates a new model with the given number (and types!) of input and output types. |
Method Summary | |
---|---|
void |
addWarningListener(NodeModelWarningListener listener)
Adds a warning listener to this node. |
(package private) void |
clearLoopStatus()
|
protected DataTableSpec[] |
configure(DataTableSpec[] inSpecs)
This function is called whenever the derived model should re-configure its output DataTableSpecs. |
protected PortObjectSpec[] |
configure(PortObjectSpec[] inSpecs)
Configure method for general port types. |
(package private) PortObjectSpec[] |
configureModel(PortObjectSpec[] inSpecs)
This function is called when something changes that could affect the output DataTableSpec elements. |
protected void |
continueLoop()
Informs WorkflowManager after execute to continue the loop. |
protected BufferedDataTable[] |
execute(BufferedDataTable[] inData,
ExecutionContext exec)
This function is invoked by the 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. |
protected PortObject[] |
execute(PortObject[] inObjects,
ExecutionContext exec)
Execute method for general port types. |
protected PortObject[] |
executeModel(PortObject[] data,
ExecutionContext exec)
Invokes the abstract #execute() method of this model. |
(package private) FlowObjectStack |
getFlowObjectStack()
|
HiLiteHandler |
getInHiLiteHandler(int inIndex)
Returns the HiLiteHandler for the given input index, if the
current in-port hilite handler is null an
HiLiteHandlerAdapter is created and returned. |
(package private) PortType |
getInPortType(int index)
|
protected LoopEndNode |
getLoopEndNode()
Access method for loop start nodes to access their respective loop end. |
protected LoopStartNode |
getLoopStartNode()
Access method for loop end nodes to access their respective loop start. |
(package private) FlowLoopContext |
getLoopStatus()
|
protected int |
getNrInPorts()
Returns the overall number of inputs. |
protected int |
getNrOutPorts()
Returns the overall number of outputs. |
protected HiLiteHandler |
getOutHiLiteHandler(int outIndex)
Returns the HiLiteHandler for the given output index. |
(package private) PortType |
getOutPortType(int index)
|
(package private) int |
getSimulatedHiliteHandlerPortIndex(int portIndex)
Returns the argument. |
(package private) int |
getTrueHiliteHandlerPortIndex(int portIndex)
Returns the argument. |
(package private) Collection<AbstractNodeView<?>> |
getViews()
|
protected String |
getWarningMessage()
Get the most recently set warning message. |
(package private) boolean |
hasContent()
|
protected abstract void |
loadInternals(File nodeInternDir,
ExecutionMonitor exec)
Load internals into the derived NodeModel . |
(package private) void |
loadSettingsFrom(NodeSettingsRO settings)
Validates the specified settings in the model and then loads them into it. |
protected abstract void |
loadValidatedSettingsFrom(NodeSettingsRO settings)
Sets new settings from the passed object in the model. |
protected void |
notifyViews(Object arg)
This method can be called from the derived model in order to inform the views about changes of the settings or during execution, if you want the views to show the progress, and if they can display models half way through the execution. |
void |
notifyWarningListeners(String warning)
Notifies all listeners that the warning of this node has changed. |
protected double |
peekFlowVariableDouble(String name)
Get the value of the double variable with the given name leaving the variable stack unmodified. |
protected int |
peekFlowVariableInt(String name)
Get the value of the integer variable with the given name leaving the variable stack unmodified. |
protected String |
peekFlowVariableString(String name)
Get the value of the String variable with the given name leaving the flow variable stack unmodified. |
protected double |
peekScopeVariableDouble(String name)
Deprecated. This method has been replaced by peekFlowVariableDouble(String) .
It will be removed in future versions. |
protected int |
peekScopeVariableInt(String name)
Deprecated. This method has been replaced by peekFlowVariableInt(String) .
It will be removed in future versions. |
protected String |
peekScopeVariableString(String name)
Deprecated. This method has been replaced by peekFlowVariableString(String) .
It will be removed in future versions. |
protected void |
pushFlowVariableDouble(String name,
double value)
Put a new variable of type double onto the stack. |
protected void |
pushFlowVariableInt(String name,
int value)
Put a new variable of type integer onto the stack. |
protected void |
pushFlowVariableString(String name,
String value)
Put a new variable of type String onto the stack. |
protected void |
pushScopeVariableDouble(String name,
double value)
Deprecated. This method has been replaced by pushFlowVariableDouble(String, double) .
It will be removed in future versions. |
protected void |
pushScopeVariableInt(String name,
int value)
Deprecated. This method has been replaced by pushFlowVariableInt(String, int) .
It will be removed in future versions. |
protected void |
pushScopeVariableString(String name,
String value)
Deprecated. This method has been replaced by pushFlowVariableString(String, String) .
It will be removed in future versions. |
(package private) void |
registerView(AbstractNodeView<?> view)
Registers the given view at the model to receive change events of the underlying model. |
void |
removeWarningListener(NodeModelWarningListener listener)
Removes a warning listener from this node. |
protected abstract void |
reset()
Override this function in the derived model and reset your NodeModel . |
(package private) void |
resetModel()
Invokes the abstract #reset() method of the derived model. |
(package private) void |
restoreWarningMessage(String warningMessage)
Method being called when node is restored. |
protected abstract void |
saveInternals(File nodeInternDir,
ExecutionMonitor exec)
Save internals of the derived NodeModel . |
protected abstract void |
saveSettingsTo(NodeSettingsWO settings)
Adds to the given NodeSettings the model specific
settings. |
(package private) void |
setFlowObjectStack(FlowObjectStack scsc)
|
(package private) void |
setHasContent(boolean hasContent)
Sets the hasContent flag and fires a state change event. |
protected void |
setInHiLiteHandler(int inIndex,
HiLiteHandler hiLiteHdl)
This implementation is empty. |
(package private) void |
setLoopEndNode(LoopEndNode end)
Setter used by framework to update loop end node. |
(package private) void |
setLoopStartNode(LoopStartNode start)
Setter used by framework to update loop start node. |
(package private) void |
setNewInHiLiteHandler(int in,
HiLiteHandler hdl)
Sets a new HiLiteHandler for the given input. |
protected void |
setWarningMessage(String warningMessage)
Sets an optional warning message by the implementing node model. |
protected void |
stateChanged()
Notifies all registered views of a change of the underlying model. |
(package private) void |
unregisterAllViews()
Unregisters all views from the model. |
(package private) void |
unregisterView(AbstractNodeView<?> view)
Unregisters the given view. |
protected abstract void |
validateSettings(NodeSettingsRO settings)
Validates the settings in the passed NodeSettings object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected NodeModel(int nrInDataPorts, int nrOutDataPorts)
nrInDataPorts
- number of input data portsnrOutDataPorts
- number of output data ports
NegativeArraySizeException
- If the number of in- or outputs is
smaller than zero.protected NodeModel(PortType[] inPortTypes, PortType[] outPortTypes)
inPortTypes
- an array of non-null in-port typesoutPortTypes
- an array of non-null out-port typesMethod Detail |
---|
protected abstract 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.
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.saveInternals(File,ExecutionMonitor)
protected abstract 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.
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.loadInternals(File,ExecutionMonitor)
final void registerView(AbstractNodeView<?> view)
view
- The view to register.final void unregisterView(AbstractNodeView<?> view)
view
- The view to unregister.final void unregisterAllViews()
final Collection<AbstractNodeView<?>> getViews()
protected final int getNrInPorts()
protected final int getNrOutPorts()
final PortType getInPortType(int index)
index
-
final PortType getOutPortType(int index)
index
-
final void loadSettingsFrom(NodeSettingsRO settings) throws InvalidSettingsException
settings
- the settings to read
InvalidSettingsException
- if the settings are not valid or cannot
be loaded into the modelprotected abstract void saveSettingsTo(NodeSettingsWO settings)
NodeSettings
the model specific
settings. The settings don't need to be complete or consistent. If, right
after startup, no valid settings are available this method can write
either nothing or invalid settings.
Method is called by the Node
if the current settings need
to be saved or transfered to the node's dialog.
settings
- The object to write settings into.loadValidatedSettingsFrom(NodeSettingsRO)
,
validateSettings(NodeSettingsRO)
protected abstract void validateSettings(NodeSettingsRO settings) throws InvalidSettingsException
NodeSettings
object.
The specified settings should be checked for completeness and
consistency. It must be possible to load a settings object validated
here without any exception in the
#loadValidatedSettings(NodeSettings)
method. The method
must not change the current settings in the model - it is supposed to
just check them. If some settings are missing, invalid, inconsistent, or
just not right throw an exception with a message useful to the user.
settings
- The settings to validate.
InvalidSettingsException
- If the validation of the settings
failed.saveSettingsTo(NodeSettingsWO)
,
loadValidatedSettingsFrom(NodeSettingsRO)
protected abstract void loadValidatedSettingsFrom(NodeSettingsRO settings) throws InvalidSettingsException
#validateSettings(NodeSettings)
method. The model must set
its internal configuration according to the settings object passed.
settings
- The settings to read.
InvalidSettingsException
- If a property is not available.saveSettingsTo(NodeSettingsWO)
,
validateSettings(NodeSettingsRO)
protected final PortObject[] executeModel(PortObject[] data, ExecutionContext exec) throws Exception
#execute()
method of this model. In
addition, this method notifies all assigned views of the model about the
changes.
data
- An array of DataTable
objects holding the data
from the inputs.exec
- The execution monitor which is passed to the execute method
of this model.
DataTable
elements, as many as the node has
outputs.
Exception
- any exception or error that is fired in the derived
model will be just forwarded. It may throw an
CanceledExecutionException if the user pressed cancel during
execution. Even if the derived model doesn't check, the
result will be discarded and the exception thrown.
IllegalStateException
- If the number of PortObject
objects returned by the derived NodeModel
does not match the number of outputs. Or if any of them is
null.execute(PortObject[],ExecutionContext)
final void setHasContent(boolean hasContent)
hasContent
- Flag if this node is configured be executed or not.final boolean hasContent()
true
if this model has been executed and therefore
possibly has content that can be displayed in a view,
false
otherwise.protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception
PortObject classes
that are defined through the
PortTypes
given in the
constructor
.
Similarly, the returned output objects need to comply with their port
types object class (otherwise an error is reported by the framework).
For a general description of the execute method refer to the description
of the specialized
execute(BufferedDataTable[], ExecutionContext)
methods as it
addresses more use cases.
inObjects
- The input objects.exec
- For BufferedDataTable
creation and progress.
Exception
- If the node execution fails for any reason.protected 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
.
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.final void resetModel()
#reset()
method of the derived model.
In addition, this method resets all hilite handlers, and notifies all
views about the changes.
protected abstract void reset()
NodeModel
. All components should unregister themselves
from any observables (at least from the hilite handler right now). All
internally stored data structures should be released. User settings
should not be deleted/reset though.
protected final void stateChanged()
#executeModel()
and #resetModel()
).
protected final void notifyViews(Object arg)
NodeView#updateModel(Object)
is called and needs to
be overridden.
arg
- The argument you want to pass.protected void setInHiLiteHandler(int inIndex, HiLiteHandler hiLiteHdl)
inIndex
- The index of the input.hiLiteHdl
- The HiLiteHandler
at input index.
May be null
when not available, i.e. not properly
connected.
IndexOutOfBoundsException
- If the inIndex
is not in
the range of inputs.final void setNewInHiLiteHandler(int in, HiLiteHandler hdl)
HiLiteHandler
for the given input.
This method is called by the corresponding Node
in order
to set the HiLiteHandler
for the given input port.
in
- The input index.hdl
- The new HiLiteHandler
.setInHiLiteHandler(int, HiLiteHandler)
public final HiLiteHandler getInHiLiteHandler(int inIndex)
HiLiteHandler
for the given input index, if the
current in-port hilite handler is null
an
HiLiteHandlerAdapter
is created and returned.
inIndex
- in-port index
HiLiteHandler
for the given input index
IndexOutOfBoundsException
- if the inIndex
is not in
the range of inputsint getTrueHiliteHandlerPortIndex(int portIndex)
NodeModel
to handle incoming model ports appropriately
(no hilite handlers at deprecated model ports).
portIndex
- The simulated port index
int getSimulatedHiliteHandlerPortIndex(int portIndex)
NodeModel
to handle incoming model ports appropriately
(no hilite handlers at deprecated model ports).
portIndex
- The true port index
protected HiLiteHandler getOutHiLiteHandler(int outIndex)
HiLiteHandler
for the given output index. This
default implementation simply passes on the handler of input port 0 or
generates a new one if this node has no inputs.
outIndex
- The output index.
HiLiteHandler
for the given output port.
IndexOutOfBoundsException
- If the index is not in output's range.final PortObjectSpec[] configureModel(PortObjectSpec[] inSpecs) throws InvalidSettingsException
DataTableSpec
elements. E.g. after a reset,
execute, (dis-)connect, and object creation (model instantiation).
The function calls #configure()
to receive the updated
output DataTableSpecs, if the model is not executed yet. After execution
the DataTableSpecs are simply taken from the output DataTables.
inSpecs
- An array of input DataTableSpec
elements,
either the array or each of its elements can be
null
.
InvalidSettingsException
- if the current settings don't go along
with the table specsprotected PortObjectSpec[] configure(PortObjectSpec[] inSpecs) throws InvalidSettingsException
PortObjectSpecs
that are defined through the
PortTypes
given in the
constructor
.
Similarly, the returned output specs need to comply with their port types
spec class (otherwise an error is reported by the framework). They may
also be null.
For a general description of the configure method refer to the
description of the specialized configure(DataTableSpec[])
methods as it addresses more use cases.
inSpecs
- The input object specs.
InvalidSettingsException
- If this node can't be configured.protected DataTableSpec[] configure(DataTableSpec[] inSpecs) throws InvalidSettingsException
The passed DataTableSpec elements are never null
but can
be empty. The model may return null
data table spec(s) for
the outputs. But still, the model may be in an executable state. Note,
after the model has been executed this function will not be called
anymore, as the output DataTableSpecs are then being pulled from the
output DataTables. A derived NodeModel
that cannot provide
any DataTableSpecs at its outputs before execution (because the table
structure is unknown at this point) can return an array
containing just null
elements.
Implementation note: This method is called from the
configure(PortObjectSpec[])
method unless that method is
overwritten.
inSpecs
- An array of DataTableSpecs (as many as this model has
inputs). Do NOT modify the contents of this array. None of the
DataTableSpecs in the array can be null
but
empty. If the predecessor node is not yet connected, or
doesn't provide a DataTableSpecs at its output port.
null
DataTableSpec elements are changed to empty
once.
InvalidSettingsException
- if the #configure()
failed, that is, the settings are inconsistent with given
DataTableSpec elements.final void restoreWarningMessage(String warningMessage)
warningMessage
- The message as written to the workflow fileprotected final void setWarningMessage(String warningMessage)
warningMessage
- the warning message to setprotected final String getWarningMessage()
public void addWarningListener(NodeModelWarningListener listener)
listener
- The listener to add.public void removeWarningListener(NodeModelWarningListener listener)
listener
- The listener to remove.public void notifyWarningListeners(String warning)
warning
- messageprotected final String peekFlowVariableString(String name)
name
- Name of the variable
NullPointerException
- If the argument is null
NoSuchElementException
- If no such variable with the correct
type is available.protected final void pushFlowVariableDouble(String name, double value)
name
- The name of the variable.value
- The assignment value for the variable
NullPointerException
- If the name argument is null.protected final double peekFlowVariableDouble(String name)
name
- Name of the variable
NullPointerException
- If the argument is null
NoSuchElementException
- If no such variable with the correct
type is available.protected final void pushFlowVariableInt(String name, int value)
name
- The name of the variable.value
- The assignment value for the variable
NullPointerException
- If the name argument is null.protected final int peekFlowVariableInt(String name)
name
- Name of the variable
NullPointerException
- If the argument is null
NoSuchElementException
- If no such variable with the correct
type is available.protected final void pushFlowVariableString(String name, String value)
name
- The name of the variable.value
- The assignment value for the variable
NullPointerException
- If the name argument is null.protected final void continueLoop()
final FlowLoopContext getLoopStatus()
final void clearLoopStatus()
protected final LoopEndNode getLoopEndNode()
getLoopStartNode()
void setLoopEndNode(LoopEndNode end)
end
- The end node of the loop (if this is a start node).protected final LoopStartNode getLoopStartNode()
getLoopEndNode()
void setLoopStartNode(LoopStartNode start)
start
- The start node of the loop (if this is a end node).FlowObjectStack getFlowObjectStack()
void setFlowObjectStack(FlowObjectStack scsc)
@Deprecated protected final void pushScopeVariableString(String name, String value)
pushFlowVariableString(String, String)
.
It will be removed in future versions.
@Deprecated protected final String peekScopeVariableString(String name)
peekFlowVariableString(String)
.
It will be removed in future versions.
@Deprecated protected final void pushScopeVariableDouble(String name, double value)
pushFlowVariableDouble(String, double)
.
It will be removed in future versions.
@Deprecated protected final double peekScopeVariableDouble(String name)
peekFlowVariableDouble(String)
.
It will be removed in future versions.
@Deprecated protected final void pushScopeVariableInt(String name, int value)
pushFlowVariableInt(String, int)
.
It will be removed in future versions.
@Deprecated protected final int peekScopeVariableInt(String name)
peekFlowVariableInt(String)
.
It will be removed in future versions.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |