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

SNAP-1548_SNAP-1502_snap-gpf #410

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -58,14 +58,11 @@ public GraphContext(Graph graph) throws GraphException {
this(graph, null);
}

public GraphContext(Graph graph, boolean init) throws GraphException {
this(graph, null, init);
}

/**
* Creates a GraphContext for the given {@code graph} and a {@code logger}.
*
* @param graph the {@link Graph} to create the context for
* @throws GraphException if the graph context could not be created
*/
public GraphContext(Graph graph, Operator graphOp) throws GraphException {
public GraphContext(Graph graph, Operator graphOp, boolean init) throws GraphException {
if (graph.getNodeCount() == 0) {
throw new GraphException("Empty graph.");
}
Expand All @@ -82,6 +79,22 @@ public GraphContext(Graph graph, Operator graphOp) throws GraphException {

initNodeContextDeque = new ArrayDeque<>(graph.getNodeCount());
initNodeDependencies();
if (init) {
init(graphOp);
}
}

/**
* Creates a GraphContext for the given {@code graph} and a {@code logger}.
*
* @param graph the {@link Graph} to create the context for
* @throws GraphException if the graph context could not be created
*/
public GraphContext(Graph graph, Operator graphOp) throws GraphException {
this(graph, graphOp, true);
}

public void init(Operator graphOp) throws GraphException {
initOutput(graphOp);
}

Expand Down Expand Up @@ -192,6 +205,7 @@ private void initNodeContext(final NodeContext nodeContext, Operator graphOp) th
nodeContext.addSourceProduct(source.getName(), sourceProduct);
}
Node node = nodeContext.getNode();
node.updateGraphNode(nodeContext);
DomElement configuration = node.getConfiguration();
OperatorConfiguration opConfiguration = this.createOperatorConfiguration(configuration,
new HashMap<String, Object>());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.esa.snap.core.gpf.graph;

/**
* A helper class used to command the update of the GraphNode object from SNAP Graph Builder by Graph Processing Framework (GPF)
*
* @author Adrian Drăghici
*/
public abstract class GraphNodeUpdater {

/**
* The commander method used to update the GraphNode object from SNAP Graph Builder by Graph Processing Framework (GPF) using the NodeContext object with the latest changes
*
* @param nodeContext the NodeContext object with the latest changes from Graph Processing Framework (GPF)
* @throws GraphException if any error occurs during execution
*/
public abstract void doUpdate(NodeContext nodeContext) throws GraphException;
}
11 changes: 11 additions & 0 deletions snap-gpf/src/main/java/org/esa/snap/core/gpf/graph/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Node {
private String operatorName;
private SourceList sourceList;
private DomElement configuration;
private GraphNodeUpdater graphNodeUpdater;

/**
* Constructs a new <code>Node</code> instance.
Expand All @@ -56,6 +57,16 @@ public Node(String id, String operatorName) {
init();
}

public void attachGraphNodeUpdater(GraphNodeUpdater graphNodeUpdater){
this.graphNodeUpdater = graphNodeUpdater;
}

public void updateGraphNode(NodeContext nodeContext) throws GraphException {
if (this.graphNodeUpdater != null) {
this.graphNodeUpdater.doUpdate(nodeContext);
}
}

/**
* Gets the uniqe node identifier.
*
Expand Down