You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by re...@apache.org on 2015/03/23 17:37:55 UTC
[11/51] [partial] incubator-taverna-engine git commit:
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobEvent.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobEvent.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobEvent.java
new file mode 100644
index 0000000..f55cb95
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobEvent.java
@@ -0,0 +1,105 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.dispatch.events;
+
+import static org.apache.taverna.workflowmodel.processor.dispatch.description.DispatchMessageType.JOB;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.taverna.invocation.InvocationContext;
+import org.apache.taverna.invocation.ProcessIdentifierException;
+import org.apache.taverna.reference.T2Reference;
+import org.apache.taverna.workflowmodel.processor.activity.Activity;
+import org.apache.taverna.workflowmodel.processor.dispatch.description.DispatchMessageType;
+
+/**
+ * An event within the dispatch stack containing a single job's worth of data
+ * along with an ordered list of Activity instances.
+ *
+ * @author Tom Oinn
+ */
+public class DispatchJobEvent extends AbstractDispatchEvent<DispatchJobEvent> {
+ private Map<String, T2Reference> dataMap;
+ private List<? extends Activity<?>> activities;
+
+ /**
+ * Create a new job event, specifying a complete set of input data and a
+ * list of activities which could potentially consume this data
+ *
+ * @param owningProcess
+ * @param index
+ * @param context
+ * @param data
+ * @param activities
+ */
+ public DispatchJobEvent(String owningProcess, int[] index,
+ InvocationContext context, Map<String, T2Reference> data,
+ List<? extends Activity<?>> activities) {
+ super(owningProcess, index, context);
+ this.dataMap = data;
+ this.activities = activities;
+ }
+
+ /**
+ * The actual data carried by this dispatch job event object is in the form
+ * of a map, where the keys of the map are Strings identifying the named
+ * input and the values are Strings containing valid data identifiers within
+ * the context of a visible DataManager object (see CloudOne specification
+ * for further information on the DataManager system)
+ *
+ * @return Map of name to data reference for this Job
+ */
+ public Map<String, T2Reference> getData() {
+ return this.dataMap;
+ }
+
+ /**
+ * Returns a list of activity instances which can be applied to the data
+ * contained by this job event.
+ *
+ * @return ordered list of Activity instances
+ */
+ public List<? extends Activity<?>> getActivities() {
+ return this.activities;
+ }
+
+ @Override
+ public DispatchJobEvent popOwningProcess()
+ throws ProcessIdentifierException {
+ return new DispatchJobEvent(popOwner(), index, context, dataMap,
+ activities);
+ }
+
+ @Override
+ public DispatchJobEvent pushOwningProcess(String localProcessName)
+ throws ProcessIdentifierException {
+ return new DispatchJobEvent(pushOwner(localProcessName), index,
+ context, dataMap, activities);
+ }
+
+ /**
+ * @return Always a {@link DispatchMessageType#JOB}.
+ */
+ @Override
+ public DispatchMessageType getMessageType() {
+ return JOB;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobQueueEvent.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobQueueEvent.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobQueueEvent.java
new file mode 100644
index 0000000..bbdfc4a
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchJobQueueEvent.java
@@ -0,0 +1,94 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.dispatch.events;
+
+import static org.apache.taverna.workflowmodel.processor.dispatch.description.DispatchMessageType.JOB_QUEUE;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+
+import org.apache.taverna.invocation.InvocationContext;
+import org.apache.taverna.invocation.IterationInternalEvent;
+import org.apache.taverna.invocation.ProcessIdentifierException;
+import org.apache.taverna.workflowmodel.processor.activity.Activity;
+import org.apache.taverna.workflowmodel.processor.dispatch.description.DispatchMessageType;
+
+/**
+ * A message within the dispatch stack containing a single reference to the job
+ * queue from the iteration system along with an ordered list of Activity
+ * instances.
+ *
+ * @author Tom Oinn
+ */
+public class DispatchJobQueueEvent extends
+ AbstractDispatchEvent<DispatchJobQueueEvent> {
+ private BlockingQueue<IterationInternalEvent<? extends IterationInternalEvent<?>>> queue;
+ private List<? extends Activity<?>> activities;
+
+ /**
+ * Create a new job queue event, specifying the queue of Completion and Job
+ * objects and the list of activities which will be used to process the
+ * corresponding dispatch events
+ *
+ * @param owner
+ * @param context
+ * @param queue
+ * @param activities
+ */
+ public DispatchJobQueueEvent(
+ String owner,
+ InvocationContext context,
+ BlockingQueue<IterationInternalEvent<? extends IterationInternalEvent<?>>> queue,
+ List<? extends Activity<?>> activities) {
+ super(owner, new int[] {}, context);
+ this.queue = queue;
+ this.activities = activities;
+ }
+
+ public BlockingQueue<IterationInternalEvent<? extends IterationInternalEvent<?>>> getQueue() {
+ return this.queue;
+ }
+
+ public List<? extends Activity<?>> getActivities() {
+ return this.activities;
+ }
+
+ @Override
+ public DispatchJobQueueEvent popOwningProcess()
+ throws ProcessIdentifierException {
+ return new DispatchJobQueueEvent(popOwner(), context, queue, activities);
+ }
+
+ @Override
+ public DispatchJobQueueEvent pushOwningProcess(String localProcessName)
+ throws ProcessIdentifierException {
+ return new DispatchJobQueueEvent(pushOwner(localProcessName), context,
+ queue, activities);
+ }
+
+ /**
+ * @return Always a {@link DispatchMessageType#JOB_QUEUE}.
+ */
+ @Override
+ public DispatchMessageType getMessageType() {
+ return JOB_QUEUE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchResultEvent.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchResultEvent.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchResultEvent.java
new file mode 100644
index 0000000..ffed25e
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/events/DispatchResultEvent.java
@@ -0,0 +1,107 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.dispatch.events;
+
+import static org.apache.taverna.workflowmodel.processor.dispatch.description.DispatchMessageType.RESULT;
+
+import java.util.Map;
+
+import org.apache.taverna.invocation.InvocationContext;
+import org.apache.taverna.invocation.ProcessIdentifierException;
+import org.apache.taverna.reference.T2Reference;
+import org.apache.taverna.workflowmodel.processor.dispatch.description.DispatchMessageType;
+
+/**
+ * Dispatch event containing the results from an invocation. If the event is
+ * part of a stream of such events from a single job invocation the streaming
+ * flag will be set to true - when set layers that do not support streaming
+ * should either disable any related functionality or complain bitterly. They
+ * should never see such an event as the type checker will in the future catch
+ * such cases before they occur but for now it's something to watch for.
+ *
+ * @author Tom Oinn
+ */
+public class DispatchResultEvent extends
+ AbstractDispatchEvent<DispatchResultEvent> {
+ private Map<String, T2Reference> dataMap;
+ private boolean streaming;
+
+ /**
+ * Construct a new dispatch result event, specifying the data and whether
+ * the result is part of a stream of multiple results events from a single
+ * invocation
+ *
+ * @param owner
+ * @param index
+ * @param context
+ * @param data
+ * @param streaming
+ */
+ public DispatchResultEvent(String owner, int[] index,
+ InvocationContext context, Map<String, T2Reference> data,
+ boolean streaming) {
+ super(owner, index, context);
+ this.dataMap = data;
+ this.streaming = streaming;
+ }
+
+ /**
+ * If this result is part of a stream, that is to say multiple result events
+ * from a single job event, then return true otherwise return false.
+ *
+ * @return whether this is part of a streamed result set
+ */
+ public boolean isStreamingEvent() {
+ return this.streaming;
+ }
+
+ /**
+ * The result contains a map of named EntityIdentifier instances
+ * corresponding to the result data.
+ *
+ * @return the result data for this event
+ */
+ public Map<String, T2Reference> getData() {
+ return this.dataMap;
+ }
+
+ @Override
+ public DispatchResultEvent popOwningProcess()
+ throws ProcessIdentifierException {
+ return new DispatchResultEvent(popOwner(), index, context, dataMap,
+ streaming);
+ }
+
+ @Override
+ public DispatchResultEvent pushOwningProcess(String localProcessName)
+ throws ProcessIdentifierException {
+ return new DispatchResultEvent(pushOwner(localProcessName), index,
+ context, dataMap, streaming);
+ }
+
+ /**
+ * @return Always a {@link DispatchMessageType#RESULT}.
+ */
+ @Override
+ public DispatchMessageType getMessageType() {
+ return RESULT;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/package.html
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/package.html b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/package.html
new file mode 100644
index 0000000..d4dc0d4
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/dispatch/package.html
@@ -0,0 +1,19 @@
+<body>
+Definition and support classes for the Dispatch Stack. Each processor in
+a workflow contains a stack of dispatch layers with each layer being
+responsible for a particular aspect of the invocation. At a high level
+the stack consumes a queue of events from the iteration system along
+with an initial set of service proxy objects and is repsonsible for
+taking jobs from the queue and matching them to appropriate invocation
+targets.
+<p>Taverna 1 has in effect a single hardcoded dispatch stack for
+each processor with little control over it aside from a few basic
+properties. To replicate the same behaviour within Taverna 2 there are
+dispatch layers for parallelism, retry, failover and invocation. As the
+dispatch layer is an extension point we or others can provide other
+aspects such as recursive invocation and dynamic (runtime) binding from
+abstract service proxies to concrete instances. The last is possible
+because the service list is passed through the stack along with the
+queue or individual job events and can be rewritten or filtered by
+dispatch layer implementations.
+</body>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/AbstractIterationStrategyNode.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/AbstractIterationStrategyNode.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/AbstractIterationStrategyNode.java
new file mode 100644
index 0000000..279c585
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/AbstractIterationStrategyNode.java
@@ -0,0 +1,224 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.MutableTreeNode;
+import javax.swing.tree.TreeNode;
+
+import org.apache.taverna.invocation.Completion;
+import org.apache.taverna.workflowmodel.WorkflowStructureException;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * Abstract superclass for implementations of IterationStrategyNode, adds logic
+ * to connect nodes together and convenience methods to push jobs and completion
+ * events up to the parent node.
+ *
+ * @author Tom Oinn
+ * @author Stian Soiland-Reyes
+ */
+@SuppressWarnings("serial")
+public abstract class AbstractIterationStrategyNode extends
+ DefaultMutableTreeNode implements IterationStrategyNode {
+ private List<IterationStrategyNode> children = new ArrayList<>();
+ private IterationStrategyNode parent = null;
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public final synchronized Enumeration<IterationStrategyNode> children() {
+ return new Vector<>(children).elements(); // TODO arraylist?
+ }
+
+ /**
+ * Clear the child list and parent of this node
+ */
+ @Override
+ public final synchronized void clear() {
+ for (IterationStrategyNode child : children)
+ child.setParent(null);
+ children.clear();
+ this.parent = null;
+ }
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public final synchronized IterationStrategyNode getChildAt(int position) {
+ return children.get(position);
+ }
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public final int getChildCount() {
+ return children.size();
+ }
+
+ /**
+ * Implements IterationStrategyNode
+ */
+ @Override
+ public final synchronized List<IterationStrategyNode> getChildren() {
+ return new ArrayList<>(children);
+ }
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public final synchronized int getIndex(TreeNode node) {
+ return children.indexOf(node);
+ }
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public final IterationStrategyNode getParent() {
+ return parent;
+ }
+
+ @Override
+ public synchronized void insert(MutableTreeNode child) {
+ insert(child, getChildCount());
+ }
+
+ @Override
+ public synchronized void insert(MutableTreeNode child, int index) {
+ if (!getAllowsChildren())
+ throw new IllegalStateException("Node does not allow children");
+ if (!(child instanceof IterationStrategyNode))
+ throw new IllegalArgumentException(
+ "Child not an instance of IterationStrategyNode: " + child);
+ if (child == this)
+ throw new IllegalArgumentException("Can't be it's own parent");
+
+ // Check if it is already there (in case we'll just move it)
+ int alreadyExistsIndex = children.indexOf(child);
+
+ children.add(index, (IterationStrategyNode) child);
+
+ if (alreadyExistsIndex > -1) {
+ // Remove it from the old position
+ if (index < alreadyExistsIndex
+ && alreadyExistsIndex + 1 < children.size())
+ alreadyExistsIndex++;
+ children.remove(alreadyExistsIndex);
+ }
+ if (child.getParent() != this)
+ child.setParent(this);
+ }
+
+ /**
+ * Implement TreeNode
+ */
+ @Override
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ @Override
+ public void remove(int index) {
+ if (!getAllowsChildren())
+ throw new IllegalStateException("Node does not allow children");
+ children.remove(index);
+ }
+
+ @Override
+ public synchronized void remove(MutableTreeNode node) {
+ if (!getAllowsChildren())
+ throw new IllegalStateException("Node does not allow children");
+ children.remove(node);
+ if (node.getParent() == this)
+ node.setParent(null);
+ }
+
+ @Override
+ public void removeFromParent() {
+ if (parent != null) {
+ IterationStrategyNode oldParent = parent;
+ parent = null;
+ oldParent.remove(this);
+ }
+ }
+
+ /**
+ * Implements IterationStrategyNode
+ */
+ @Override
+ public final synchronized void setParent(MutableTreeNode newParent) {
+ if (newParent != null && !(newParent instanceof IterationStrategyNode))
+ throw new IllegalArgumentException(
+ "Parent not a IterationStrategyNode instance: " + newParent);
+ if (newParent != null && !newParent.getAllowsChildren())
+ throw new IllegalStateException(
+ "New parent does not allow children");
+ if (newParent == this)
+ throw new IllegalArgumentException("Can't be it's own parent");
+ removeFromParent();
+ parent = (IterationStrategyNode) newParent;
+ if (parent != null && !parent.getChildren().contains(this))
+ parent.insert(this);
+ }
+
+ @Override
+ public void setUserObject(Object object) {
+ throw new UnsupportedOperationException("Can't set user object");
+ }
+
+ /**
+ * Push the specified completion event to the parent node
+ */
+ protected final void pushCompletion(Completion completion) {
+ if (parent != null)
+ parent.receiveCompletion(parent.getIndex(this), completion);
+ }
+
+ /**
+ * Push the specified job up to the parent node in the iteration strategy.
+ */
+ protected final void pushJob(Job job) {
+ if (parent != null) {
+ int index = parent.getIndex(this);
+ if (index < 0)
+ throw new WorkflowStructureException(
+ "Parent doesn't have this node in its child list!");
+ parent.receiveJob(parent.getIndex(this), job);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CompletionHandlingAbstractIterationStrategyNode.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CompletionHandlingAbstractIterationStrategyNode.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CompletionHandlingAbstractIterationStrategyNode.java
new file mode 100644
index 0000000..c06888e
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CompletionHandlingAbstractIterationStrategyNode.java
@@ -0,0 +1,135 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import static java.util.Collections.synchronizedMap;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.taverna.invocation.Completion;
+import org.apache.taverna.invocation.InvocationContext;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * A superclass for all iteration strategy nodes which are required to propagate
+ * final completion events formed from multiple inputs. This is all the 'real'
+ * iteration strategy nodes (but not the internal ones within the iteration
+ * strategy object itself or the named input port nodes). All events are passed
+ * to delegates in subclasses after which the completion state is checked, the
+ * logic is as follows :
+ * <p>
+ * If the event received is final, that is to say it has an index of zero, and
+ * final events have been received on all other inputs and at least one final
+ * completion has been received then emit a final completion, otherwise do
+ * nothing.
+ * <p>
+ * This means that subclasses should not emit final completion events themselves
+ * - these will be handled by this superclass and emiting them in the subclass
+ * will lead to duplicatation.
+ *
+ * @author Tom Oinn
+ * @author David Withers
+ */
+@SuppressWarnings("serial")
+public abstract class CompletionHandlingAbstractIterationStrategyNode extends
+ AbstractIterationStrategyNode {
+ /**
+ * Container class for the state of completion for a given process
+ * identifier
+ *
+ * @author Tom Oinn
+ */
+ protected final class CompletionState {
+ protected CompletionState(int indexLength) {
+ inputComplete = new boolean[indexLength];
+ for (int i = 0; i < indexLength; i++)
+ inputComplete[i] = false;
+ }
+
+ protected boolean[] inputComplete;
+ protected boolean receivedCompletion = false;
+
+ /**
+ * Return true iff all inputs have completed
+ */
+ protected boolean isComplete() {
+ for (boolean inputCompletion : inputComplete)
+ if (!inputCompletion)
+ return false;
+ return true;
+ }
+ }
+
+ private Map<String, CompletionState> ownerToCompletion = synchronizedMap(new HashMap<String, CompletionState>());
+
+ @Override
+ public final void receiveCompletion(int inputIndex, Completion completion) {
+ innerReceiveCompletion(inputIndex, completion);
+ if (completion.getIndex().length == 0)
+ pingCompletionState(inputIndex, completion.getOwningProcess(),
+ true, completion.getContext());
+ }
+
+ @Override
+ public final void receiveJob(int inputIndex, Job newJob) {
+ innerReceiveJob(inputIndex, newJob);
+ if (newJob.getIndex().length == 0)
+ pingCompletionState(inputIndex, newJob.getOwningProcess(), false,
+ newJob.getContext());
+ }
+
+ /**
+ * Called after a final completion event has been emited for a given owning
+ * process, should be used by subclasses to do any tidying required,
+ * removing state etc.
+ *
+ * @param owningProcess
+ */
+ protected abstract void cleanUp(String owningProcess);
+
+ private void pingCompletionState(int inputIndex, String owningProcess,
+ boolean isCompletion, InvocationContext context) {
+ CompletionState cs = getCompletionState(owningProcess);
+ cs.inputComplete[inputIndex] = true;
+ if (isCompletion)
+ cs.receivedCompletion = true;
+ if (cs.isComplete()) {
+ cleanUp(owningProcess);
+ ownerToCompletion.remove(owningProcess);
+ if (cs.receivedCompletion)
+ pushCompletion(new Completion(owningProcess, new int[0],
+ context));
+ }
+ }
+
+ protected CompletionState getCompletionState(String owningProcess) {
+ if (ownerToCompletion.containsKey(owningProcess))
+ return ownerToCompletion.get(owningProcess);
+ CompletionState cs = new CompletionState(getChildCount());
+ ownerToCompletion.put(owningProcess, cs);
+ return cs;
+ }
+
+ protected abstract void innerReceiveCompletion(int inputIndex,
+ Completion completion);
+
+ protected abstract void innerReceiveJob(int inputIndex, Job newJob);
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CrossProduct.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CrossProduct.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CrossProduct.java
new file mode 100644
index 0000000..947c7d6
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/CrossProduct.java
@@ -0,0 +1,163 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import static java.util.Collections.synchronizedMap;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.taverna.invocation.Completion;
+import org.apache.taverna.reference.T2Reference;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * A cross product node combines its inputs in an 'all against all' manner. When
+ * a new job is received on index 'n' a set of jobs is emited corresponding to
+ * the combination of the new job with all other jobs on input indices other
+ * than 'n'.
+ *
+ * @author Tom Oinn
+ * @author David Withers
+ */
+@SuppressWarnings("serial")
+public class CrossProduct extends
+ CompletionHandlingAbstractIterationStrategyNode {
+ private Map<String, List<Set<Job>>> ownerToCache = synchronizedMap(new HashMap<String, List<Set<Job>>>());
+
+ /**
+ * Receive a job, emit jobs corresponding to the orthogonal join of the new
+ * job with all jobs in all other input lists.
+ */
+ @Override
+ public synchronized void innerReceiveJob(int inputIndex, Job newJob) {
+ if (getChildCount() == 1) {
+ /*
+ * there's only one input and there's nothing to do here so push the
+ * job through
+ */
+ pushJob(newJob);
+ return;
+ }
+ if (!ownerToCache.containsKey(newJob.getOwningProcess())) {
+ List<Set<Job>> perInputCache = new ArrayList<>();
+ for (int i = 0; i < getChildCount(); i++)
+ perInputCache.add(new HashSet<Job>());
+ ownerToCache.put(newJob.getOwningProcess(), perInputCache);
+ }
+ // Store the new job
+ List<Set<Job>> perInputCache = ownerToCache.get(newJob
+ .getOwningProcess());
+ perInputCache.get(inputIndex).add(newJob);
+ /*
+ * Find all combinations of the new job with all permutations of jobs in
+ * the other caches. We could make this a lot easier by restricting it
+ * to a single pair of inputs, this might be a more sane way to go in
+ * the future...
+ */
+ Set<Job> workingSet = perInputCache.get(0);
+ if (inputIndex == 0) {
+ workingSet = new HashSet<>();
+ workingSet.add(newJob);
+ }
+ for (int i = 1; i < getChildCount(); i++) {
+ Set<Job> thisSet = perInputCache.get(i);
+ if (i == inputIndex) {
+ /*
+ * This is the cache for the new job, so we rewrite the set to a
+ * single element one containing only the newly submitted job
+ */
+ thisSet = new HashSet<>();
+ thisSet.add(newJob);
+ }
+ workingSet = merge(workingSet, thisSet);
+ }
+ for (Job outputJob : workingSet)
+ pushJob(outputJob);
+ if (canClearCache(inputIndex, newJob.getOwningProcess()))
+ /*
+ * If we've seen completions for all the other indexes we don't need
+ * to cache jobs for this index
+ */
+ perInputCache.get(inputIndex).clear();
+ }
+
+ private Set<Job> merge(Set<Job> set1, Set<Job> set2) {
+ Set<Job> newSet = new HashSet<>();
+ for (Job job1 : set1)
+ for (Job job2 : set2) {
+ int[] newIndex = new int[job1.getIndex().length
+ + job2.getIndex().length];
+ int j = 0;
+ for (int i = 0; i < job1.getIndex().length; i++)
+ newIndex[j++] = job1.getIndex()[i];
+ for (int i = 0; i < job2.getIndex().length; i++)
+ newIndex[j++] = job2.getIndex()[i];
+ Map<String, T2Reference> newDataMap = new HashMap<>();
+ newDataMap.putAll(job1.getData());
+ newDataMap.putAll(job2.getData());
+ newSet.add(new Job(job1.getOwningProcess(), newIndex,
+ newDataMap, job1.getContext()));
+ }
+ return newSet;
+ }
+
+ @Override
+ public void innerReceiveCompletion(int inputIndex, Completion completion) {
+ // Do nothing, let the superclass handle final completion events
+ }
+
+ @Override
+ protected final void cleanUp(String owningProcess) {
+ ownerToCache.remove(owningProcess);
+ }
+
+ /**
+ * Returns true iff completions have been received for all other inputs.
+ *
+ * @param inputIndex
+ * @param owningProcess
+ * @return true iff completions have been received for all other inputs
+ */
+ private boolean canClearCache(int inputIndex, String owningProcess) {
+ boolean[] completionState = getCompletionState(owningProcess).inputComplete;
+ for (int i = 0; i < completionState.length; i++)
+ if (i != inputIndex && !completionState[i])
+ return false;
+ return true;
+ }
+
+ @Override
+ public int getIterationDepth(Map<String, Integer> inputDepths)
+ throws IterationTypeMismatchException {
+ if (isLeaf())
+ // No children!
+ throw new IterationTypeMismatchException(
+ "Cross product with no children");
+ int temp = 0;
+ for (IterationStrategyNode child : getChildren())
+ temp += child.getIterationDepth(inputDepths);
+ return temp;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/DotProduct.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/DotProduct.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/DotProduct.java
new file mode 100644
index 0000000..084e2db
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/DotProduct.java
@@ -0,0 +1,122 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import static java.util.Collections.synchronizedMap;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.taverna.invocation.Completion;
+import org.apache.taverna.invocation.TreeCache;
+import org.apache.taverna.reference.T2Reference;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * The dot product matches jobs by index array, when a job is received a job is
+ * emited if and only if the index array of the new job is matched exactly by
+ * index arrays of one job in each other input index.
+ *
+ * @author Tom Oinn
+ */
+@SuppressWarnings("serial")
+public class DotProduct extends CompletionHandlingAbstractIterationStrategyNode {
+ Map<String, TreeCache[]> ownerToCache = synchronizedMap(new HashMap<String, TreeCache[]>());
+
+ @Override
+ public synchronized void innerReceiveJob(int inputIndex, Job newJob) {
+ if (getChildCount() == 1) {
+ /*
+ * if there's only one input there's nothing to do here so push the
+ * job through
+ */
+ pushJob(newJob);
+ return;
+ }
+ String owningProcess = newJob.getOwningProcess();
+ if (!ownerToCache.containsKey(owningProcess)) {
+ TreeCache[] caches = new TreeCache[getChildCount()];
+ for (int i = 0; i < getChildCount(); i++)
+ caches[i] = new TreeCache();
+ ownerToCache.put(owningProcess, caches);
+ }
+ /*
+ * Firstly store the new job in the cache, this isn't optimal but is
+ * safe for now - we can make this more efficient by doing the
+ * comparison first and only storing the job if required
+ */
+ TreeCache[] caches = ownerToCache.get(owningProcess);
+ caches[inputIndex].insertJob(newJob);
+ int[] indexArray = newJob.getIndex();
+ boolean foundMatch = true;
+ Map<String, T2Reference> newDataMap = new HashMap<>();
+ for (TreeCache cache : caches)
+ if (cache.containsLocation(indexArray))
+ newDataMap.putAll(cache.get(indexArray).getData());
+ else
+ foundMatch = false;
+ if (foundMatch) {
+ Job j = new Job(owningProcess, indexArray, newDataMap, newJob
+ .getContext());
+ /*
+ * Remove all copies of the job with this index from the cache,
+ * we'll never use it again and it pays to be tidy
+ */
+ for (TreeCache cache : caches)
+ cache.cut(indexArray);
+ pushJob(j);
+ }
+ }
+
+ /**
+ * Delegate to the superclass to propogate completion events if and only if
+ * the completion event is a final one. We can potentially implement finer
+ * grained logic here in the future.
+ */
+ @Override
+ public void innerReceiveCompletion(int inputIndex,
+ Completion completion) {
+ /*
+ * Do nothing, let the superclass handle final completion events, ignore
+ * others for now (although in theory we should be able to do better
+ * than this really)
+ */
+ }
+
+ @Override
+ protected void cleanUp(String owningProcess) {
+ ownerToCache.remove(owningProcess);
+ }
+
+ @Override
+ public int getIterationDepth(Map<String, Integer> inputDepths)
+ throws IterationTypeMismatchException {
+ // Check that all input depths are the same
+ if (isLeaf())
+ // No children!
+ throw new IterationTypeMismatchException("Dot product with no children");
+ int depth = getChildAt(0).getIterationDepth(inputDepths);
+ for (IterationStrategyNode childNode : getChildren())
+ if (childNode.getIterationDepth(inputDepths) != depth)
+ throw new IterationTypeMismatchException(
+ "Mismatched input types for dot product node");
+ return depth;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategy.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategy.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategy.java
new file mode 100644
index 0000000..f0f0b07
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategy.java
@@ -0,0 +1,53 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import java.util.Map;
+
+import org.apache.taverna.workflowmodel.WorkflowItem;
+
+public interface IterationStrategy extends WorkflowItem {
+ /**
+ * The iteration strategy results in a set of job objects with a particular
+ * job index. This method returns the length of that index array when the
+ * specified input types are used. Input types are defined in terms of name
+ * and integer pairs where the name is the name of a NamedInputPortNode in
+ * the iteration strategy and the integer is the depth of the input data
+ * collection (i.e. item depth + index array length for that item which
+ * should be a constant).
+ *
+ * @param inputDepths
+ * map of port names to input collection depth
+ * @return the length of the index array which will be generated for each
+ * resultant job object.
+ */
+ int getIterationDepth(Map<String, Integer> inputDepths)
+ throws IterationTypeMismatchException;
+
+ /**
+ * Return a map of port name -> desired cardinality for this iteration
+ * strategy
+ */
+ Map<String, Integer> getDesiredCardinalities();
+
+ TerminalNode getTerminalNode();
+
+ void normalize();
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyNode.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyNode.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyNode.java
new file mode 100644
index 0000000..4dc786e
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyNode.java
@@ -0,0 +1,120 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.tree.MutableTreeNode;
+
+import org.apache.taverna.invocation.Completion;
+import org.apache.taverna.workflowmodel.WorkflowItem;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * Interface for nodes within an iteration strategy layer
+ *
+ * @author Tom Oinn
+ * @author Stian Soiland-Reyes
+ */
+public interface IterationStrategyNode extends MutableTreeNode, WorkflowItem {
+ /**
+ * Specialised return type of {@link TreeNode#children()}
+ */
+ @Override
+ Enumeration<IterationStrategyNode> children();
+
+ /**
+ * Remove all children nodes and set the parent to <code>null</code>.
+ */
+ void clear();
+
+ /**
+ * Specialised return type of {@link TreeNode#getChildAt(int)}
+ */
+ @Override
+ IterationStrategyNode getChildAt(int childIndex);
+
+ /**
+ * Return a copy of the list of children nodes, or an empty list if
+ * {@link #getAllowsChildren()} is <code>false</code>.
+ *
+ * @return List of children nodes.
+ */
+ List<IterationStrategyNode> getChildren();
+
+ /**
+ * In the context of an enclosing iteration strategy each node should be
+ * able to return the iteration depth, i.e. the length of the index array,
+ * for items it will emit. In all cases other than leaf nodes this is
+ * defined in terms of the depth of child nodes. The input cardinalities for
+ * named ports are pushed through each node so that the terminal nodes
+ * corresponding to input port collators can evaluate this expression -
+ * pushing it through the entire evaluation means we don't have to keep
+ * state anywhere in the leaf nodes (standard dependency injection)
+ * <p>
+ * Nodes can choose to throw the IterationTypeMismatchException if their
+ * inputs aren't compatible with the operational semantics of the node such
+ * as in the case of a dot product node with inputs with different depths.
+ *
+ * @param inputDepths
+ * @return
+ * @throws IterationTypeMismatchException
+ */
+ int getIterationDepth(Map<String, Integer> inputDepths)
+ throws IterationTypeMismatchException;
+
+ /**
+ * Specialised return type of {@link TreeNode#getParent()}
+ */
+ @Override
+ IterationStrategyNode getParent();
+
+ /**
+ * Insert a new child node. The new child will be added in the end of the
+ * list, so this would be equivalent to insert(child, getChildCount()).
+ *
+ * @param child
+ * Child node to add
+ */
+ void insert(MutableTreeNode child);
+
+ /**
+ * Nodes can also receive completion events, the simplest being one
+ * declaring that no further input is expected on the given input, or
+ * partial completion events which are interpreted as 'no event with an
+ * index array prefixed by the specified completion index array will be
+ * received on the specified index'
+ */
+ void receiveCompletion(int inputIndex, Completion completion);
+
+ /**
+ * The nodes within the iteration strategy, a tree structure, are event
+ * based. When a new fragment of a job from upstream in the tree (towards
+ * leaves) arrives it is handled by this method. Implementations will
+ * probably have to handle state management, i.e. what jobs have we already
+ * seen, and emit appropriate jobs to downstream nodes.
+ *
+ * @param inputIndex
+ * @param newJob
+ */
+ void receiveJob(int inputIndex, Job newJob);
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyStack.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyStack.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyStack.java
new file mode 100644
index 0000000..e2305a4
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationStrategyStack.java
@@ -0,0 +1,64 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.taverna.workflowmodel.WorkflowItem;
+
+/**
+ * Stack of iteration strategy containers. The stacking behaviour allows for
+ * staged implicit iteration where intermediate strategies are used to drill
+ * into the collection structure to a certain depth with a final one used to
+ * render job objects containing data at the correct depth for the process. This
+ * was achieved in Taverna 1 through the combination of nested workflows and
+ * 'forcing' processors which could echo and therefore force input types of the
+ * workflow to a particular cardinality.
+ *
+ * @author Tom Oinn
+ */
+public interface IterationStrategyStack extends WorkflowItem {
+ /**
+ * The iteration strategy stack consists of an ordered list of iteration
+ * strategies.
+ *
+ * @return An unmodifiable copy of the list containing the iteration
+ * strategy objects in order, with the strategy at position 0 in the
+ * list being the one to which data is fed first.
+ */
+ List<? extends IterationStrategy> getStrategies();
+
+ /**
+ * Calculate the depth of the iteration strategy stack as a whole given a
+ * set of named inputs and their cardinalities. This depth is the length of
+ * the index array which will be added to any output data, so the resultant
+ * output of each port in the owning processor is the depth of that port as
+ * defined by the activity plus this value.
+ *
+ * @param inputDepths
+ * @return
+ * @throws IterationTypeMismatchException
+ * @throws MissingIterationInputException
+ */
+ int getIterationDepth(Map<String, Integer> inputDepths)
+ throws IterationTypeMismatchException,
+ MissingIterationInputException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationTypeMismatchException.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationTypeMismatchException.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationTypeMismatchException.java
new file mode 100644
index 0000000..7f17f3f
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/IterationTypeMismatchException.java
@@ -0,0 +1,48 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+/**
+ * Thrown during the typecheck phase when an iteration strategy is configured
+ * such that at runtime it would fail. This is generally because a dot product
+ * node has been specified where the children of that node will have different
+ * cardinalities (in this case the dot product isn't defined)
+ *
+ * @author Tom Oinn
+ */
+public class IterationTypeMismatchException extends Exception {
+ private static final long serialVersionUID = -3034020607723767223L;
+
+ public IterationTypeMismatchException() {
+ super();
+ }
+
+ public IterationTypeMismatchException(String arg0) {
+ super(arg0);
+ }
+
+ public IterationTypeMismatchException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public IterationTypeMismatchException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/MissingIterationInputException.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/MissingIterationInputException.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/MissingIterationInputException.java
new file mode 100644
index 0000000..0c9833e
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/MissingIterationInputException.java
@@ -0,0 +1,49 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+/**
+ * Thrown when an attempt is made to evaluate the type of the iteration strategy
+ * but one or more input ports aren't defined in the input array of types.
+ * Shouldn't normally happen as this will be handled by the type checker
+ * detecting that there aren't enough inputs to check but we indicate it for
+ * extra robustness.
+ *
+ * @author Tom Oinn
+ */
+public class MissingIterationInputException extends Exception {
+ private static final long serialVersionUID = -1615949178096496592L;
+
+ public MissingIterationInputException() {
+ super();
+ }
+
+ public MissingIterationInputException(String arg0) {
+ super(arg0);
+ }
+
+ public MissingIterationInputException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public MissingIterationInputException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/NamedInputPortNode.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/NamedInputPortNode.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/NamedInputPortNode.java
new file mode 100644
index 0000000..91c2f20
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/NamedInputPortNode.java
@@ -0,0 +1,115 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import java.util.Map;
+
+import org.apache.taverna.invocation.Completion;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * Acts as the input to a stage within the iteration strategy, passes all jobs
+ * straight through. NamedInputPortNode objects are, as the name suggests,
+ * named. These names correspond to the names of abstract input ports on the
+ * Processor object to which the iteration strategy belongs.
+ *
+ * @author Tom Oinn
+ */
+@SuppressWarnings("serial")
+public class NamedInputPortNode extends AbstractIterationStrategyNode {
+ private String portName;
+ private int desiredCardinality;
+
+ public NamedInputPortNode(String name, int cardinality) {
+ super();
+ this.portName = name;
+ this.desiredCardinality = cardinality;
+ }
+
+ /**
+ * If this node receives a job it will always be pushed without modification
+ * up to the parent
+ */
+ @Override
+ public void receiveJob(int inputIndex, Job newJob) {
+ pushJob(newJob);
+ }
+
+ /**
+ * Completion events are passed straight through the same as jobs
+ */
+ @Override
+ public void receiveCompletion(int inputIndex, Completion completion) {
+ pushCompletion(completion);
+ }
+
+ /**
+ * Each node maps to a single named input port within the processor
+ */
+ public String getPortName() {
+ return this.portName;
+ }
+
+ /**
+ * Each node defines the level of collection depth for that input port
+ */
+ public int getCardinality() {
+ return this.desiredCardinality;
+ }
+
+ /**
+ * These nodes correspond to inputs to the iteration strategy and are always
+ * leaf nodes as a result.
+ *
+ * @override
+ */
+ @Override
+ public boolean isLeaf() {
+ return true;
+ }
+
+ /**
+ * These nodes can never have children
+ *
+ * @override
+ */
+ @Override
+ public boolean getAllowsChildren() {
+ return false;
+ }
+
+ /**
+ * Iteration depth is the difference between the supplied input depth and
+ * the desired one. If the desired depth is greater then wrapping will
+ * happen and the iteration depth will be zero (rather than a negative!)
+ */
+ @Override
+ public int getIterationDepth(Map<String, Integer> inputDepths) {
+ int myInputDepth = inputDepths.get(portName);
+ int depthMismatch = myInputDepth - desiredCardinality;
+ return (depthMismatch > 0 ? depthMismatch : 0);
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " " + getPortName() + "("
+ + getCardinality() + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/PrefixDotProduct.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/PrefixDotProduct.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/PrefixDotProduct.java
new file mode 100644
index 0000000..cbf45e0
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/PrefixDotProduct.java
@@ -0,0 +1,110 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.taverna.invocation.TreeCache;
+import org.apache.taverna.reference.T2Reference;
+import org.apache.taverna.workflowmodel.processor.activity.Job;
+
+/**
+ * Matches jobs where the index array of the job on index 0 is the prefix of the
+ * index array of the job on index 1. This node can only ever have exactly two
+ * child nodes!
+ *
+ * @author Tom Oinn
+ */
+@SuppressWarnings("serial")
+public class PrefixDotProduct extends DotProduct {
+ @Override
+ protected synchronized final void cleanUp(String owningProcess) {
+ ownerToCache.remove(owningProcess);
+ }
+
+ @Override
+ public void innerReceiveJob(int inputIndex, Job newJob) {
+ String owningProcess = newJob.getOwningProcess();
+ TreeCache[] caches;
+ synchronized (ownerToCache) {
+ caches = ownerToCache.get(owningProcess);
+ // Create the caches if not already initialized
+ if (caches == null) {
+ caches = new TreeCache[getChildCount()];
+ for (int i = 0; i < getChildCount(); i++)
+ caches[i] = new TreeCache();
+ ownerToCache.put(owningProcess, caches);
+ }
+ }
+
+ // Store the job
+ caches[inputIndex].insertJob(newJob);
+
+ /*
+ * If this job came in on index 0 we have to find all jobs in the cache
+ * for index 1 which have the index array as a prefix. Fortunately this
+ * is quite easy due to the tree structure of the cache, we can just ask
+ * for all nodes in the cache with that index.
+ */
+ if (inputIndex == 0) {
+ int[] prefixIndexArray = newJob.getIndex();
+ List<Job> matchingJobs;
+ synchronized (caches[1]) {
+ // Match all jobs and remove them so other calls can't produce
+ // duplicates
+ matchingJobs = caches[1].jobsWithPrefix(prefixIndexArray);
+ caches[1].cut(prefixIndexArray);
+ }
+ for (Job job : matchingJobs) {
+ Map<String, T2Reference> newDataMap = new HashMap<>();
+ newDataMap.putAll(newJob.getData());
+ newDataMap.putAll(job.getData());
+ Job mergedJob = new Job(owningProcess, job.getIndex(),
+ newDataMap, newJob.getContext());
+ pushJob(mergedJob);
+ }
+ }
+
+ /*
+ * If the job came in on index 1 we have to find the job on index 0 that
+ * matches the first 'n' indices, where 'n' is determined by the depth
+ * of jobs on the cache for index 0.
+ */
+ else if (inputIndex == 1) {
+ // Only act if we've received jobs on the cache at index 0
+ if (caches[0].getIndexLength() > 0) {
+ int[] prefix = new int[caches[0].getIndexLength()];
+ for (int i = 0; i < prefix.length; i++)
+ prefix[i] = newJob.getIndex()[i];
+ Job j = caches[0].get(prefix);
+ if (j != null) {
+ Map<String, T2Reference> newDataMap = new HashMap<>();
+ newDataMap.putAll(j.getData());
+ newDataMap.putAll(newJob.getData());
+ Job mergedJob = new Job(owningProcess, newJob.getIndex(),
+ newDataMap, newJob.getContext());
+ pushJob(mergedJob);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/TerminalNode.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/TerminalNode.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/TerminalNode.java
new file mode 100644
index 0000000..504296e
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/TerminalNode.java
@@ -0,0 +1,38 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.processor.iteration;
+
+import javax.swing.tree.MutableTreeNode;
+
+/**
+ * The terminal node is the root of the iteration strategy tree, it is
+ * responsible for forwarding all events up to the iteration strategy itself
+ * which can then propogate them to the strategy stack.
+ */
+@SuppressWarnings("serial")
+public abstract class TerminalNode extends AbstractIterationStrategyNode {
+ @Override
+ public synchronized void insert(MutableTreeNode child, int index) {
+ if (getChildCount() > 0 && getChildAt(0) != child)
+ throw new IllegalStateException(
+ "The terminal node can have maximum one child");
+ super.insert(child, index);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/package.html
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/package.html b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/package.html
new file mode 100644
index 0000000..65f2a61
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/processor/iteration/package.html
@@ -0,0 +1,4 @@
+<body>
+Object model and enactment logic for the iteration strategy component of
+a Processor
+</body>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/DeserializationException.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/DeserializationException.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/DeserializationException.java
new file mode 100644
index 0000000..5563566
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/DeserializationException.java
@@ -0,0 +1,32 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.serialization;
+
+public class DeserializationException extends Exception {
+ public DeserializationException(String msg) {
+ super(msg);
+ }
+
+ public DeserializationException(String msg, Exception cause) {
+ super(msg, cause);
+ }
+
+ private static final long serialVersionUID = -5905705659863088259L;
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/SerializationException.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/SerializationException.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/SerializationException.java
new file mode 100644
index 0000000..6339305
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/serialization/SerializationException.java
@@ -0,0 +1,32 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.serialization;
+
+public class SerializationException extends Exception {
+ public SerializationException(String msg, Exception cause) {
+ super(msg, cause);
+ }
+
+ public SerializationException(String msg) {
+ super(msg);
+ }
+
+ private static final long serialVersionUID = -218787623524401819L;
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/AnnotationTools.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/AnnotationTools.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/AnnotationTools.java
new file mode 100644
index 0000000..2b044c0
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/AnnotationTools.java
@@ -0,0 +1,170 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.utils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.taverna.annotation.Annotated;
+import org.apache.taverna.annotation.AnnotationAssertion;
+import org.apache.taverna.annotation.AnnotationBeanSPI;
+import org.apache.taverna.annotation.AnnotationChain;
+import org.apache.taverna.annotation.AppliesTo;
+import org.apache.taverna.annotation.annotationbeans.AbstractTextualValueAssertion;
+import org.apache.taverna.workflowmodel.Edit;
+import org.apache.taverna.workflowmodel.EditException;
+import org.apache.taverna.workflowmodel.Edits;
+
+import org.apache.log4j.Logger;
+
+public class AnnotationTools {
+ private static Logger logger = Logger.getLogger(AnnotationTools.class);
+ // private Iterable<Class<?>> annotationBeanRegistry;
+
+ public static Edit<?> addAnnotation(Annotated<?> annotated,
+ AnnotationBeanSPI a, Edits edits) {
+ return edits.getAddAnnotationChainEdit(annotated, a);
+ }
+
+ public static AnnotationBeanSPI getAnnotation(Annotated<?> annotated,
+ Class<?> annotationClass) {
+ AnnotationBeanSPI result = null;
+ Date latestDate = null;
+ for (AnnotationChain chain : annotated.getAnnotations())
+ for (AnnotationAssertion<?> assertion : chain.getAssertions()) {
+ AnnotationBeanSPI detail = assertion.getDetail();
+ if (annotationClass.isInstance(detail)) {
+ Date assertionDate = assertion.getCreationDate();
+ if ((latestDate == null)
+ || latestDate.before(assertionDate)) {
+ result = detail;
+ latestDate = assertionDate;
+ }
+ }
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> List<Class<? extends T>> getAnnotationBeanClasses(
+ List<AnnotationBeanSPI> annotations, Class<T> superClass) {
+ List<Class<? extends T>> results = new ArrayList<>();
+ for (AnnotationBeanSPI annotation : annotations) {
+ Class<? extends AnnotationBeanSPI> annotationBeanClass = annotation
+ .getClass();
+ if (superClass.isAssignableFrom(annotationBeanClass))
+ results.add((Class<? extends T>) annotationBeanClass);
+ }
+ return results;
+ }
+
+ public List<Class<?>> getAnnotatingClasses(
+ List<AnnotationBeanSPI> annotations, Annotated<?> annotated) {
+ List<Class<?>> result = new ArrayList<>();
+ for (Class<? extends AbstractTextualValueAssertion> c : getAnnotationBeanClasses(
+ annotations, AbstractTextualValueAssertion.class)) {
+ AppliesTo appliesToAnnotation = (AppliesTo) c
+ .getAnnotation(AppliesTo.class);
+ if (appliesToAnnotation == null)
+ continue;
+ for (Class<?> target : appliesToAnnotation.targetObjectType())
+ if (target.isInstance(annotated))
+ result.add(c);
+ }
+ return result;
+ }
+
+ public static Edit<?> setAnnotationString(Annotated<?> annotated,
+ Class<?> c, String value, Edits edits) {
+ AbstractTextualValueAssertion a = null;
+ try {
+ logger.info("Setting " + c.getCanonicalName() + " to " + value);
+ a = (AbstractTextualValueAssertion) c.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ logger.error(e);
+ throw new RuntimeException(e);
+ }
+ a.setText(value);
+ return addAnnotation(annotated, a, edits);
+ }
+
+ public static String getAnnotationString(Annotated<?> annotated,
+ Class<?> annotationClass, String missingValue) {
+ AbstractTextualValueAssertion a = (AbstractTextualValueAssertion) getAnnotation(
+ annotated, annotationClass);
+ if (a == null)
+ return missingValue;
+ return a.getText();
+ }
+
+ /**
+ * Remove out of date annotations unless many of that class are allowed, or
+ * it is explicitly not pruned
+ */
+ @SuppressWarnings("rawtypes")
+ public static void pruneAnnotations(Annotated<?> annotated, Edits edits) {
+ Map<Class<? extends AnnotationBeanSPI>, AnnotationAssertion> remainder = new HashMap<>();
+ Set<AnnotationChain> newChains = new HashSet<AnnotationChain>();
+ for (AnnotationChain chain : annotated.getAnnotations()) {
+ AnnotationChain newChain = edits.createAnnotationChain();
+ for (AnnotationAssertion assertion : chain.getAssertions()) {
+ AnnotationBeanSPI annotation = assertion.getDetail();
+ Class<? extends AnnotationBeanSPI> annotationClass = annotation
+ .getClass();
+ AppliesTo appliesToAnnotation = (AppliesTo) annotationClass
+ .getAnnotation(AppliesTo.class);
+ if ((appliesToAnnotation == null) || appliesToAnnotation.many()
+ || !appliesToAnnotation.pruned())
+ try {
+ edits.getAddAnnotationAssertionEdit(newChain, assertion)
+ .doEdit();
+ } catch (EditException e) {
+ logger.error("Error while pruning annotations", e);
+ }
+ else if (remainder.containsKey(annotationClass)) {
+ AnnotationAssertion currentAssertion = remainder
+ .get(annotationClass);
+ if (assertion.getCreationDate().compareTo(
+ currentAssertion.getCreationDate()) > 0)
+ remainder.put(annotationClass, assertion);
+ } else
+ remainder.put(annotationClass, assertion);
+ }
+ if (!newChain.getAssertions().isEmpty())
+ newChains.add(newChain);
+ }
+ for (AnnotationAssertion assertion : remainder.values()) {
+ AnnotationChain newChain = edits.createAnnotationChain();
+ try {
+ edits.getAddAnnotationAssertionEdit(newChain, assertion)
+ .doEdit();
+ } catch (EditException e) {
+ logger.error("Error while pruning annotations", e);
+ }
+ newChains.add(newChain);
+ }
+ annotated.setAnnotations(newChains);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/NamedWorkflowEntityComparator.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/NamedWorkflowEntityComparator.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/NamedWorkflowEntityComparator.java
new file mode 100644
index 0000000..df45360
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/NamedWorkflowEntityComparator.java
@@ -0,0 +1,38 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.utils;
+
+import java.util.Comparator;
+
+import org.apache.taverna.workflowmodel.NamedWorkflowEntity;
+
+/**
+ * Compare two named workflow entities (such as a Processor) by their local
+ * name.
+ *
+ * @author Stian Soiland-Reyes
+ */
+public class NamedWorkflowEntityComparator implements
+ Comparator<NamedWorkflowEntity> {
+ @Override
+ public int compare(NamedWorkflowEntity o1, NamedWorkflowEntity o2) {
+ return o1.getLocalName().compareToIgnoreCase(o2.getLocalName());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/5f1ddb71/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/PortComparator.java
----------------------------------------------------------------------
diff --git a/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/PortComparator.java b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/PortComparator.java
new file mode 100644
index 0000000..f3a85fd
--- /dev/null
+++ b/taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/PortComparator.java
@@ -0,0 +1,36 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.workflowmodel.utils;
+
+import java.util.Comparator;
+
+import org.apache.taverna.workflowmodel.Port;
+
+/**
+ * Compare two workflow ports by their name.
+ *
+ * @author Stian Soiland-Reyes
+ */
+public class PortComparator implements Comparator<Port> {
+ @Override
+ public int compare(Port o1, Port o2) {
+ return o1.getName().compareToIgnoreCase(o2.getName());
+ }
+}