Takes in a collection of executions belonging to the same process instance. Orders the executions in a list, first elements are the leaf, last element is the root elements.
320934
public static List<ExecutionEntity> orderFromRootToLeaf(Collection<ExecutionEntity> executions) {
    List<ExecutionEntity> orderedList = new ArrayList<ExecutionEntity>(executions.size());

    // Root elements
    HashSet<String> previousIds = new HashSet<String>();
    for (ExecutionEntity execution : executions) {
      if (execution.getParentId() == null) {
        orderedList.add(execution);
        previousIds.add(execution.getId());
      }
    }

    // Non-root elements
    while (orderedList.size() < executions.size()) {
      for (ExecutionEntity execution : executions) {
        if (!previousIds.contains(execution.getId()) && previousIds.contains(execution.getParentId())) {
          orderedList.add(execution);
          previousIds.add(execution.getId());
        }
      }
    }

    return orderedList;
  }
482452
def execute(self, elem_list):
        
        if self.condition.is_true(elem_list):
            return self.action.act(elem_list)
        else:
            return elem_list
641815
private List<Integer> getRunningFlowsHelper(final int projectId, final String flowId,
      final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) {
    final List<Integer> executionIds = new ArrayList<>();
    for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) {
      if (ref.getSecond().getFlowId().equals(flowId)
          && ref.getSecond().getProjectId() == projectId) {
        executionIds.add(ref.getFirst().getExecId());
      }
    }
    return executionIds;
  }
618885
@SuppressWarnings("unchecked")
	protected void executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
		OutputFormat<IN> format = this.formatWrapper.getUserCodeObject();
		TypeInformation<IN> inputType = getInput().getOperatorInfo().getOutputType();

		if (this.localOrdering != null) {
			int[] sortColumns = this.localOrdering.getFieldPositions();
			boolean[] sortOrderings = this.localOrdering.getFieldSortDirections();

			final TypeComparator<IN> sortComparator;
			if (inputType instanceof CompositeType) {
				sortComparator = ((CompositeType<IN>) inputType).createComparator(sortColumns, sortOrderings, 0, executionConfig);
			} else if (inputType instanceof AtomicType) {
				sortComparator = ((AtomicType<IN>) inputType).createComparator(sortOrderings[0], executionConfig);
			} else {
				throw new UnsupportedOperationException("Local output sorting does not support type "+inputType+" yet.");
			}

			Collections.sort(inputData, new Comparator<IN>() {
				@Override
				public int compare(IN o1, IN o2) {
					return sortComparator.compare(o1, o2);
				}
			});
		}

		if(format instanceof InitializeOnMaster) {
			((InitializeOnMaster)format).initializeGlobal(1);
		}
		format.configure(this.parameters);

		if(format instanceof RichOutputFormat){
			((RichOutputFormat<?>) format).setRuntimeContext(ctx);
		}
		format.open(0, 1);
		for (IN element : inputData) {
			format.writeRecord(element);
		}
		
		format.close();
		
		if(format instanceof FinalizeOnMaster) {
			((FinalizeOnMaster)format).finalizeGlobal(1);
		}
	}
181139
def traverse_postorder(self, leaves=True, internal=True):
        '''
        '''
        s1 = deque(); s2 = deque(); s1.append(self)
        while len(s1) != 0:
            n = s1.pop(); s2.append(n); s1.extend(n.children)
        while len(s2) != 0:
            n = s2.pop()
            if (leaves and n.is_leaf()) or (internal and not n.is_leaf()):
                yield n
1178956
static public void filterBlockedElements(List<Context> executionContexts) {
    for (Context context : executionContexts) {
      Model model = new Model(context.getModel());
      List<Edge> edges = model.getEdges();
      List<Vertex> vertices = model.getVertices();

      ListIterator<Edge> e_it = edges.listIterator();
      while (e_it.hasNext()) {
        Edge edge = e_it.next();
        if (edge.hasProperty("blocked") &&
            (boolean) edge.getProperty("blocked")) {
          e_it.remove();
        }
      }
      ListIterator<Vertex> v_it = vertices.listIterator();
      while (v_it.hasNext()) {
        Vertex vertex = v_it.next();
        if (vertex.hasProperty("blocked") &&
            (boolean) vertex.getProperty("blocked")) {
          e_it = edges.listIterator();
          while (e_it.hasNext()) {
            Edge e = e_it.next();
            if (e.getSourceVertex() == vertex) {
              e_it.remove();
            } else if (e.getTargetVertex() == vertex) {
              e_it.remove();
            }
          }
          v_it.remove();
        }
      }
      context.setModel(model.build());
    }
  }
1141970
protected int createInstances(DelegateExecution execution) {
    int nrOfInstances = resolveNrOfInstances(execution);
    if (nrOfInstances < 0) {
      throw new ActivitiIllegalArgumentException("Invalid number of instances: must be non-negative integer value" + ", but was " + nrOfInstances);
    }

    execution.setMultiInstanceRoot(true);

    setLoopVariable(execution, NUMBER_OF_INSTANCES, nrOfInstances);
    setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, 0);
    setLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES, nrOfInstances);

    List<DelegateExecution> concurrentExecutions = new ArrayList<DelegateExecution>();
    for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
      DelegateExecution concurrentExecution = Context.getCommandContext().getExecutionEntityManager()
          .createChildExecution((ExecutionEntity) execution);
      concurrentExecution.setCurrentFlowElement(activity);
      concurrentExecution.setActive(true);
      concurrentExecution.setScope(false);

      concurrentExecutions.add(concurrentExecution);
      logLoopDetails(concurrentExecution, "initialized", loopCounter, 0, nrOfInstances, nrOfInstances);
    }

    // Before the activities are executed, all executions MUST be created up front
    // Do not try to merge this loop with the previous one, as it will lead
    // to bugs, due to possible child execution pruning.
    for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
      DelegateExecution concurrentExecution = concurrentExecutions.get(loopCounter);
      // executions can be inactive, if instances are all automatics
      // (no-waitstate) and completionCondition has been met in the meantime
      if (concurrentExecution.isActive() && !concurrentExecution.isEnded() && concurrentExecution.getParent().isActive() && !concurrentExecution.getParent().isEnded()) {
        setLoopVariable(concurrentExecution, getCollectionElementIndexVariable(), loopCounter);
        executeOriginalBehavior(concurrentExecution, loopCounter);
      }
    }

    // See ACT-1586: ExecutionQuery returns wrong results when using multi
    // instance on a receive task The parent execution must be set to false, so it wouldn't show up in
    // the execution query when using .activityId(something). Do not we cannot nullify the
    // activityId (that would have been a better solution), as it would break boundary event behavior.
    if (!concurrentExecutions.isEmpty()) {
      ExecutionEntity executionEntity = (ExecutionEntity) execution;
      executionEntity.setActive(false);
    }

    return nrOfInstances;
  }
1066926
protected ProcessAdapter execute(ProcessAdapter processAdapter, ProcessContext processContext) {
    return newProcessExecutor().execute(processAdapter.getDirectory(), processAdapter.getCommandLine());
  }
1206055
def order_executed(self, orderDict):
        '''  '''
        for orderId, order in orderDict.items():
            if order.security in self.__trakers.keys():
                self.__trakers[order.security].orderExecuted(orderId)
1057849
@Override
	protected List<OUT> executeOnCollections(List<IN1> input1, List<IN2> input2, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
		// --------------------------------------------------------------------
		// Setup
		// --------------------------------------------------------------------
		TypeInformation<IN1> inputType1 = getOperatorInfo().getFirstInputType();
		TypeInformation<IN2> inputType2 = getOperatorInfo().getSecondInputType();

		int[] inputKeys1 = getKeyColumns(0);
		int[] inputKeys2 = getKeyColumns(1);

		boolean[] inputSortDirections1 = new boolean[inputKeys1.length];
		boolean[] inputSortDirections2 = new boolean[inputKeys2.length];

		Arrays.fill(inputSortDirections1, true);
		Arrays.fill(inputSortDirections2, true);

		final TypeSerializer<IN1> inputSerializer1 = inputType1.createSerializer(executionConfig);
		final TypeSerializer<IN2> inputSerializer2 = inputType2.createSerializer(executionConfig);

		final TypeComparator<IN1> inputComparator1 = getTypeComparator(executionConfig, inputType1, inputKeys1, inputSortDirections1);
		final TypeComparator<IN2> inputComparator2 = getTypeComparator(executionConfig, inputType2, inputKeys2, inputSortDirections2);

		SimpleListIterable<IN1> iterator1 = new SimpleListIterable<IN1>(input1, inputComparator1, inputSerializer1);
		SimpleListIterable<IN2> iterator2 = new SimpleListIterable<IN2>(input2, inputComparator2, inputSerializer2);

		// --------------------------------------------------------------------
		// Run UDF
		// --------------------------------------------------------------------
		CoGroupFunction<IN1, IN2, OUT> function = userFunction.getUserCodeObject();

		FunctionUtils.setFunctionRuntimeContext(function, ctx);
		FunctionUtils.openFunction(function, parameters);

		List<OUT> result = new ArrayList<OUT>();
		Collector<OUT> resultCollector = new CopyingListCollector<OUT>(result, getOperatorInfo().getOutputType().createSerializer(executionConfig));

		function.coGroup(iterator1, iterator2, resultCollector);

		FunctionUtils.closeFunction(function);

		return result;
	}
471842
def actions( self ):
        
        output = []
        for i in range(self.uiActionTREE.topLevelItemCount()):
            output.append(self.uiActionTREE.topLevelItem(i).action())
        return output
1208274
private ListIterator<List<Emit<E>>> elements(SchemaTable schemaTable, SchemaTableTree rootSchemaTableTree) {
        this.sqlgGraph.tx().readWrite();
        if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().getBatchManager().isStreaming()) {
            throw new IllegalStateException("streaming is in progress, first flush or commit before querying.");
        }
        this.replacedStepTree.maybeAddLabelToLeafNodes();
        rootSchemaTableTree.setParentIdsAndIndexes(this.schemaTableParentIds.get(schemaTable));
        Set<SchemaTableTree> rootSchemaTableTrees = new HashSet<>();
        rootSchemaTableTrees.add(rootSchemaTableTree);
        return new SqlgCompiledResultListIterator<>(new SqlgCompiledResultIterator<>(this.sqlgGraph, rootSchemaTableTrees, true));
    }
861535
@SuppressWarnings("unchecked")
	@Override
	protected List<OUT> executeOnCollections(List<IN1> inputData1, List<IN2> inputData2, RuntimeContext runtimeContext,
			ExecutionConfig executionConfig) throws Exception {
		FlatJoinFunction<IN1, IN2, OUT> function = userFunction.getUserCodeObject();

		FunctionUtils.setFunctionRuntimeContext(function, runtimeContext);
		FunctionUtils.openFunction(function, this.parameters);

		TypeInformation<IN1> leftInformation = getOperatorInfo().getFirstInputType();
		TypeInformation<IN2> rightInformation = getOperatorInfo().getSecondInputType();
		TypeInformation<OUT> outInformation = getOperatorInfo().getOutputType();

		TypeSerializer<IN1> leftSerializer = leftInformation.createSerializer(executionConfig);
		TypeSerializer<IN2> rightSerializer = rightInformation.createSerializer(executionConfig);

		TypeComparator<IN1> leftComparator;
		TypeComparator<IN2> rightComparator;

		if (leftInformation instanceof AtomicType) {
			leftComparator = ((AtomicType<IN1>) leftInformation).createComparator(true, executionConfig);
		} else if (leftInformation instanceof CompositeType) {
			int[] keyPositions = getKeyColumns(0);
			boolean[] orders = new boolean[keyPositions.length];
			Arrays.fill(orders, true);

			leftComparator = ((CompositeType<IN1>) leftInformation).createComparator(keyPositions, orders, 0, executionConfig);
		} else {
			throw new RuntimeException("Type information for left input of type " + leftInformation.getClass()
					.getCanonicalName() + " is not supported. Could not generate a comparator.");
		}

		if (rightInformation instanceof AtomicType) {
			rightComparator = ((AtomicType<IN2>) rightInformation).createComparator(true, executionConfig);
		} else if (rightInformation instanceof CompositeType) {
			int[] keyPositions = getKeyColumns(1);
			boolean[] orders = new boolean[keyPositions.length];
			Arrays.fill(orders, true);

			rightComparator = ((CompositeType<IN2>) rightInformation).createComparator(keyPositions, orders, 0, executionConfig);
		} else {
			throw new RuntimeException("Type information for right input of type " + rightInformation.getClass()
					.getCanonicalName() + " is not supported. Could not generate a comparator.");
		}

		TypePairComparator<IN1, IN2> pairComparator = new GenericPairComparator<IN1, IN2>(leftComparator, rightComparator);

		List<OUT> result = new ArrayList<OUT>();
		Collector<OUT> collector = new CopyingListCollector<OUT>(result, outInformation.createSerializer(executionConfig));

		Map<Integer, List<IN2>> probeTable = new HashMap<Integer, List<IN2>>();

		//Build hash table
		for (IN2 element : inputData2) {
			List<IN2> list = probeTable.get(rightComparator.hash(element));
			if (list == null) {
				list = new ArrayList<IN2>();
				probeTable.put(rightComparator.hash(element), list);
			}

			list.add(element);
		}

		//Probing
		for (IN1 left : inputData1) {
			List<IN2> matchingHashes = probeTable.get(leftComparator.hash(left));

			if (matchingHashes != null) {
				pairComparator.setReference(left);
				for (IN2 right : matchingHashes) {
					if (pairComparator.equalToReference(right)) {
						function.join(leftSerializer.copy(left), rightSerializer.copy(right), collector);
					}
				}
			}
		}

		FunctionUtils.closeFunction(function);

		return result;
	}
270916
@Override
	protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
		GroupReduceFunction<IN, OUT> function = this.userFunction.getUserCodeObject();

		UnaryOperatorInformation<IN, OUT> operatorInfo = getOperatorInfo();
		TypeInformation<IN> inputType = operatorInfo.getInputType();

		int[] keyColumns = getKeyColumns(0);
		int[] sortColumns = keyColumns;
		boolean[] sortOrderings = new boolean[sortColumns.length];

		if (groupOrder != null) {
			sortColumns = ArrayUtils.addAll(sortColumns, groupOrder.getFieldPositions());
			sortOrderings = ArrayUtils.addAll(sortOrderings, groupOrder.getFieldSortDirections());
		}

		if(sortColumns.length == 0) { // => all reduce. No comparator
			checkArgument(sortOrderings.length == 0);
		} else {
			final TypeComparator<IN> sortComparator = getTypeComparator(inputType, sortColumns, sortOrderings, executionConfig);
			Collections.sort(inputData, new Comparator<IN>() {
				@Override
				public int compare(IN o1, IN o2) {
					return sortComparator.compare(o1, o2);
				}
			});
		}

		FunctionUtils.setFunctionRuntimeContext(function, ctx);
		FunctionUtils.openFunction(function, this.parameters);
		
		ArrayList<OUT> result = new ArrayList<OUT>();

		if (inputData.size() > 0) {
			final TypeSerializer<IN> inputSerializer = inputType.createSerializer(executionConfig);
			if (keyColumns.length == 0) {
				TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);
				List<IN> inputDataCopy = new ArrayList<IN>(inputData.size());
				for (IN in : inputData) {
					inputDataCopy.add(inputSerializer.copy(in));
				}
				CopyingListCollector<OUT> collector = new CopyingListCollector<OUT>(result, outSerializer);

				function.reduce(inputDataCopy, collector);
			} else {
				boolean[] keyOrderings = new boolean[keyColumns.length];
				final TypeComparator<IN> comparator = getTypeComparator(inputType, keyColumns, keyOrderings, executionConfig);

				ListKeyGroupedIterator<IN> keyedIterator = new ListKeyGroupedIterator<IN>(inputData, inputSerializer, comparator);

				TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);
				CopyingListCollector<OUT> collector = new CopyingListCollector<OUT>(result, outSerializer);

				while (keyedIterator.nextKey()) {
					function.reduce(keyedIterator.getValues(), collector);
				}
			}
		}

		FunctionUtils.closeFunction(function);
		return result;
	}
1124317
public Gather<T> order(Ordering<T> ordering) {
		Collection<T> sorted = ordering.sortedCopy(list());
		elements = Optional.fromNullable(sorted);
		return this;
	}
1181069
void init(KProcess process) {
		process.markings = new Object[this.elements.size()];
		for (KElement element : this.elements) {
			element.init(process);
		}
	}
57766
def execute(self):
        

        with self._lock_c:
            self.count = 0
            self.numtasks = 0
            self.taskset = []
            self.results = {}
            self.totaltime = time.time()
            # Start all tasks
            for task in self.taskseq:
                self.taskset.append(task)
                self.numtasks += 1
                task.init_and_start(self)

        num_tasks = self.getNumTasks()
        # Wait on each task to clean up results
        while num_tasks > 0:

            self.check_state()

            for i in range(num_tasks):
                try:
                    try:
                        task = self.getTask(i)
                    except IndexError:
                        # A task got deleted from the set.  Jump back out
                        # to outer loop and repoll the number of tasks
                        break

                    #self.logger.debug("waiting on %s" % task)
                    res = task.wait(timeout=self.idletime)

                    #self.logger.debug("finished: %s" % task)
                    self.child_done(res, task)

                except TaskTimeout:
                    continue

                except Exception as e:
                    #self.logger.warning("Subtask propagated exception: %s" % str(e))
                    self.child_done(e, task)
                    continue

            # wait a bit and try again
            #self.ev_quit.wait(self.idletime)

            # re-get number of tasks, in case some were added or deleted
            num_tasks = self.getNumTasks()

        # Scan results for errors (exceptions) and raise the first one we find
        for key in self.results.keys():
            value = self.results[key]
            if isinstance(value, Exception):
                (count, task) = key
                self.logger.error("Child task %s terminated with exception: %s" % (
                    task.tag, str(value)))
                raise value

        # Return value of last child to complete
        return value