Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactoring and cleanup #49

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5e223a
Refactor scijava integration
dietzc Aug 29, 2016
ff8a056
Add javadoc to everything and cleanup.
Squareys Sep 12, 2016
82eeeac
Rename ConverterCacheService to KNIMEConverterService
Squareys Sep 12, 2016
3fbb32d
Avoid deprecated setResolved method
Squareys Sep 12, 2016
f23b70d
Always use NodeModuleOutputChangedListener, even for single row outputs
Squareys Sep 12, 2016
b3c4f7a
Pre is never null
Squareys Sep 12, 2016
215d97f
Fix MultiOutputListener @Parameters not being marked resolved
Squareys Sep 12, 2016
fe6e1bb
Avoid deprecated ResourceAwareClassLoader constructor
Squareys Sep 12, 2016
fbd8bef
Move per-node-execution preprocessing into private method.
Squareys Sep 12, 2016
c811481
Fix tiny bug
Squareys Sep 12, 2016
76acbea
Rename KnimeProcessorTest to NodeModuleTest
Squareys Sep 12, 2016
8d9bfd4
Avoid null checking getWidgetStyle()
Squareys Sep 12, 2016
24bc5ad
More javadoc
Squareys Sep 12, 2016
488620f
Use NodeLogger for logging in NodeModules and implement KNIMELogService
Squareys Sep 12, 2016
feeafa9
NodeModuleTest: Adapt to API changes in org.knime.scijava.commands
Squareys Sep 12, 2016
2bd9815
Specify 'manualPush' in constructor instead of setter.
Squareys Sep 12, 2016
6ea385c
Add tests for NodeModule and DefaultNodeModuleService
Squareys Sep 13, 2016
71e1053
Add getPreferredDataType(Class) to KNIMEConverterService
Squareys Sep 13, 2016
d2420bc
Delegate exception during notifyListener()
Squareys Sep 13, 2016
624b28f
Simplyfy getting output DataType for module output.
Squareys Sep 13, 2016
911fe46
Some Code cleanup
Squareys Sep 13, 2016
4e0736e
Remove unused imports
Squareys Sep 13, 2016
255e9fc
Use better way of detecting synthetic "result" ouput
Squareys Sep 26, 2016
321c004
Merge branch 'master' into refactoring-and-cleanup
dietzc Dec 4, 2016
a1480f0
fixes
dietzc Dec 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DefaultNodeModule implements NodeModule {

private final Map<ModuleItem<?>, DataType> outputMapping;

private NodeModuleOutputChangedListener outputListener;
private final NodeModuleOutputChangedListener outputListener;

/**
* Constructor.
Expand Down Expand Up @@ -89,20 +89,19 @@ public DefaultNodeModule(final Context context, final ModuleInfo info,
}
}

outputListener = new NodeModuleOutputChangedListener();
for (final ModuleItem<?> item : info.inputs()) {
if (MultiOutputListener.class.isAssignableFrom(item.getType())) {
module.setInput(item.getName(),
outputListener = new NodeModuleOutputChangedListener());
module.setInput(name, outputListener);
outputListener.enableManualPush(true);
}
}
}

/*
* Pre process inputs
*
* @param input the input row
* Set module input values from the input row.
*/
private void preProcess(final DataRow input) throws Exception {
private void setModuleInput(final DataRow input) throws Exception {
// input can be null if source node
if (input != null) {
for (final Entry<Integer, ModuleItem<?>> entry : inputMapping
Expand All @@ -115,71 +114,92 @@ private void preProcess(final DataRow input) throws Exception {
}
}

/*
* Post process output of the module
*/
private void postProcess(final CellOutput output,
final ExecutionContext ctx) throws Exception {
// output can be null if sink node
if (output != null) {
final List<DataCell> cells = new ArrayList<DataCell>();
for (final ModuleItem<?> entry : module.getInfo().outputs()) {
// FIXME hack because e.g. python script contains
// result log
if (!entry.getName().equals("result")) {
cells.add(cs.convertToKnime(
module.getOutput(entry.getName()), entry.getType(),
outputMapping.get(entry), ctx));
}
}
output.push(cells.toArray(new DataCell[cells.size()]));
}
}

@Override
public void run(final DataRow input, final CellOutput output,
final ExecutionContext ctx) throws Exception {
// FIXME: Nicer logic possible here?
preProcess(input);
setModuleInput(input);

if (outputListener != null) {
outputListener.setCellOutput(output);
outputListener.setExecutionContext(ctx);
}
outputListener.setCellOutput(output);
outputListener.setExecutionContext(ctx);

module.run();

if (outputListener == null) {
postProcess(output, ctx);
}
outputListener.flush();
}

// internal usage only
class NodeModuleOutputChangedListener implements MultiOutputListener {

private class NodeModuleOutputChangedListener
implements MultiOutputListener {
private ExecutionContext ctx;

private CellOutput output;

public NodeModuleOutputChangedListener() {
}
/* true if the modules handles pushes itself, false otherwise */
private boolean manualPush = false;

@Override
public void notifyListener() {
try {
postProcess(output, ctx);
// output can be null if sink node
if (output != null) {
final List<DataCell> cells = new ArrayList<DataCell>();

final ModuleItem<?> result = module.getInfo()
.getOutput("result");
if (result != null) {
// FIXME hack because e.g. python script contains
// result log
cells.add(cs.convertToKnime(
module.getOutput(result.getName()),
result.getType(), outputMapping.get(result),
ctx));
}
output.push(cells.toArray(new DataCell[cells.size()]));
}
} catch (final Exception e) {
// FIXME
e.printStackTrace();
}
}

/**
* Set KNIME Execution Context
*
* @param ctx
* execution context
*/
public void setExecutionContext(final ExecutionContext ctx) {
this.ctx = ctx;
}

/**
* Set CellOutput to push rows to.
*
* @param output
* cell output
*/
public void setCellOutput(final CellOutput output) {
this.output = output;
}

/**
* Final flush. Will push a row in case module does not handle pushing
* output rows.
*/
public void flush() {
if (!manualPush) {
notifyListener();
}
}

/**
* Enable/Disable manual push.
*
* @param b
* if <code>true</code>, signals that the module handles
* pushing rows.
*/
public void enableManualPush(final boolean b) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, this is really state-driven now. can we avoid this method, e.g. by determining in the constructor if manual or not?! just asking, not saying it's nicer.

Copy link
Contributor Author

@Squareys Squareys Sep 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, since it is only called immediately after the constructor, I can put it into the constructor, makes sense :)

manualPush = b;
}
}
}