Calls executor to dispatch the flow, update db to assign the executor and in-memory state of
executableFlow.
967269
private void dispatch(final ExecutionReference reference, final ExecutableFlow exflow,
      final Executor choosenExecutor) throws ExecutorManagerException {
    exflow.setUpdateTime(System.currentTimeMillis());

    this.executorLoader.assignExecutor(choosenExecutor.getId(),
        exflow.getExecutionId());
    try {
      this.apiGateway.callWithExecutable(exflow, choosenExecutor,
          ConnectorParams.EXECUTE_ACTION);
    } catch (final ExecutorManagerException ex) {
      logger.error("Rolling back executor assignment for execution id:"
          + exflow.getExecutionId(), ex);
      this.executorLoader.unassignExecutor(exflow.getExecutionId());
      throw new ExecutorManagerException(ex);
    }
    reference.setExecutor(choosenExecutor);

    // move from flow to running flows
    this.runningExecutions.get().put(exflow.getExecutionId(), new Pair<>(reference, exflow));
    synchronized (this.runningExecutions.get()) {
      // Wake up RunningExecutionsUpdaterThread from wait() so that it will immediately check status
      // from executor(s). Normally flows will run at least some time and can't be cleaned up
      // immediately, so there will be another wait round (or many, actually), but for unit tests
      // this is significant to let them run quickly.
      this.runningExecutions.get().notifyAll();
    }
    synchronized (this) {
      // wake up all internal waiting threads, too
      this.notifyAll();
    }

    logger.info(String.format(
        "Successfully dispatched exec %d with error count %d",
        exflow.getExecutionId(), reference.getNumErrors()));
  }
309766
void setup(final ExecutableFlow flow) throws ExecutorManagerException {
    final ProjectFileHandler projectFileHandler = null;
    File tempDir = null;
    try {
      final ProjectDirectoryMetadata project = new ProjectDirectoryMetadata(
          flow.getProjectId(),
          flow.getVersion());

      final long flowPrepStartTime = System.currentTimeMillis();


      tempDir = downloadProjectIfNotExists(project, flow.getExecutionId());


      // With synchronization, only one thread is allowed to proceed to avoid complicated race
      // conditions which could arise when multiple threads are downloading/deleting/hard-linking
      // the same project. But it doesn't prevent multiple executor processes interfering with each
      // other triggering race conditions. So it's important to operationally make sure that only
      // one executor process is setting up flow execution against the shared project directory.
      long criticalSectionStartTime = -1;
      File execDir = null;

      synchronized (this) {
        criticalSectionStartTime = System.currentTimeMillis();
        if (!project.getInstalledDir().exists() && tempDir != null) {
          // If new project is downloaded and project dir cache clean-up feature is enabled, then
          // perform clean-up if size of all project dirs exceeds the cache size.
          if (this.projectCacheCleaner.isPresent()) {
            this.projectCacheCleaner.get()
                .deleteProjectDirsIfNecessary(project.getDirSizeInByte());
          }
          // Rename temp dir to a proper project directory name.
          Files.move(tempDir.toPath(), project.getInstalledDir().toPath());
        }

        final long start = System.currentTimeMillis();
        execDir = setupExecutionDir(project.getInstalledDir(), flow);
        final long end = System.currentTimeMillis();
        log.info("Setting up execution dir {} took {} sec(s)", execDir, (end - start) / 1000);
      }

      final long flowPrepCompletionTime = System.currentTimeMillis();
      log.info("Flow preparation completed in {} sec(s), out ot which {} sec(s) was spent inside "
              + "critical section. [execid: {}, path: {}]",
          (flowPrepCompletionTime - flowPrepStartTime) / 1000,
          (flowPrepCompletionTime - criticalSectionStartTime) / 1000,
          flow.getExecutionId(), execDir.getPath());
    } catch (final Exception ex) {
      FileIOUtils.deleteDirectorySilently(tempDir);
      log.error("Error in preparing flow execution {}", flow.getExecutionId(), ex);
      throw new ExecutorManagerException(ex);
    } finally {
      if (projectFileHandler != null) {
        projectFileHandler.deleteLocalFile();
      }
    }
  }
196260
def LeaseFlowForProcessing(self,
                             client_id,
                             flow_id,
                             processing_time,
                             cursor=None):
    """"""
    query = ("SELECT " + self.FLOW_DB_FIELDS +
             "FROM flows WHERE client_id=%s AND flow_id=%s")
    cursor.execute(
        query,
        [db_utils.ClientIDToInt(client_id),
         db_utils.FlowIDToInt(flow_id)])
    response = cursor.fetchall()
    if not response:
      raise db.UnknownFlowError(client_id, flow_id)

    row, = response
    rdf_flow = self._FlowObjectFromRow(row)

    now = rdfvalue.RDFDatetime.Now()
    if rdf_flow.processing_on and rdf_flow.processing_deadline > now:
      raise ValueError("Flow %s on client %s is already being processed." %
                       (client_id, flow_id))

    if (rdf_flow.parent_hunt_id is not None and
        # TODO(user): remove the check for a legacy hunt prefix as soon as
        # AFF4 is gone.
        not rdf_flow.parent_hunt_id.startswith("H:")):

      query = "SELECT hunt_state FROM hunts WHERE hunt_id=%s"
      args = [db_utils.HuntIDToInt(rdf_flow.parent_hunt_id)]
      rows_found = cursor.execute(query, args)
      if rows_found == 1:
        hunt_state, = cursor.fetchone()
        if (hunt_state is not None and
            not rdf_hunt_objects.IsHuntSuitableForFlowProcessing(hunt_state)):
          raise db.ParentHuntIsNotRunningError(client_id, flow_id,
                                               rdf_flow.parent_hunt_id,
                                               hunt_state)

    update_query = ("UPDATE flows SET "
                    "processing_on=%s, "
                    "processing_since=FROM_UNIXTIME(%s), "
                    "processing_deadline=FROM_UNIXTIME(%s) "
                    "WHERE client_id=%s and flow_id=%s")
    processing_deadline = now + processing_time
    process_id_string = utils.ProcessIdString()

    args = [
        process_id_string,
        mysql_utils.RDFDatetimeToTimestamp(now),
        mysql_utils.RDFDatetimeToTimestamp(processing_deadline),
        db_utils.ClientIDToInt(client_id),
        db_utils.FlowIDToInt(flow_id)
    ]
    cursor.execute(update_query, args)

    # This needs to happen after we are sure that the write has succeeded.
    rdf_flow.processing_on = process_id_string
    rdf_flow.processing_since = now
    rdf_flow.processing_deadline = processing_deadline
    return rdf_flow
463643
Map<Integer, Pair<ExecutionReference, ExecutableFlow>> fetchUnfinishedFlows()
      throws ExecutorManagerException {
    try {
      return this.dbOperator.query(FetchActiveExecutableFlows.FETCH_UNFINISHED_EXECUTABLE_FLOWS,
          new FetchActiveExecutableFlows());
    } catch (final SQLException e) {
      throw new ExecutorManagerException("Error fetching unfinished flows", e);
    }
  }
1373820
private void startExecutingUpdates() throws ClosedException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "startExecutingUpdates");

    // swap the enqueuedUnits and executingUnits.
    ArrayList temp = executingUnits;
    executingUnits = enqueuedUnits;
    enqueuedUnits = temp;
    enqueuedUnits.clear();
    // enqueuedUnits is now ready to accept AsyncUpdates in enqueueWork()

    executing = true;
    try
    {
      LocalTransaction tran = tranManager.createLocalTransaction(false);
      ExecutionThread thread = new ExecutionThread(executingUnits, tran);
      mp.startNewSystemThread(thread);
    }
    catch (InterruptedException e)
    {
      // this object cannot recover from this exception since we don't know how much work the ExecutionThread
      // has done. should not occur!
      FFDCFilter.processException(
        e,
        "com.ibm.ws.sib.processor.impl.store.AsyncUpdateThread.startExecutingUpdates",
        "1:222:1.28",
        this);
      SibTr.exception(tc, e);

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.exit(tc, "startExecutingUpdates", e);

      closed = true;
      throw new ClosedException(e.getMessage());
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "startExecutingUpdates");

  }
521519
def set_executor(self, executor: futures.Executor):
        
        self.loop.set_default_executor(executor)
        self._func_executor = executor
        return True
872861
public void execute() throws DataflowAnalysisException {
        boolean change;
        boolean debugWas = DEBUG;
        if (DEBUG) {
            reportAnalysis("Executing");
        }

        int timestamp = 0;
        boolean firstTime = true;
        do {
            change = false;
            boolean sawBackEdge = false;
            ++numIterations;
            if (numIterations > MAX_ITERS && !DEBUG) {
                DEBUG = true;
                reportAnalysis("Too many iterations");
                System.out.println(this.getClass().getName());
                if (this.getClass() == UnconditionalValueDerefDataflow.class || this.getClass() == LiveLocalStoreDataflow.class) {
                    try {
                        ClassContext cc = Global.getAnalysisCache().getClassAnalysis(ClassContext.class,
                                DescriptorFactory.createClassDescriptorFromDottedClassName(cfg.getMethodGen().getClassName()));
                        System.out.println("Forwards cfg");
                        CFGPrinter printer = new CFGPrinter(cfg);
                        printer.setIsForwards(true);
                        printer.print(System.out);
                        System.out.println("Backwards cfg");
                        printer = new CFGPrinter(cfg);
                        printer.setIsForwards(false);
                        printer.print(System.out);
                        cc.dumpSimpleDataflowInformation(cfg.getMethodGen().getMethod());
                    } catch (CheckedAnalysisException e) {
                        e.printStackTrace(System.out);
                    }
                }
            }

            if (DEBUG) {
                System.out.println("----------------------------------------------------------------------");
                System.out.println(this.getClass().getName() + " iteration: " + numIterations + ", timestamp: " + timestamp);
                MethodGen mg = cfg.getMethodGen();
                System.out.println(mg.getClassName() + "." + mg.getName() + mg.getSignature());
                System.out.println("----------------------------------------------------------------------");

            }

            if (numIterations >= MAX_ITERS + 9) {
                throw new DataflowAnalysisException("Too many iterations (" + numIterations + ") in dataflow when analyzing "
                        + getFullyQualifiedMethodName());
            }

            analysis.startIteration();

            if (DEBUG && firstTime && blockOrder instanceof ReverseDFSOrder) {
                ReverseDFSOrder rBlockOrder = (ReverseDFSOrder) blockOrder;
                System.out.println("Entry point is: " + logicalEntryBlock());
                System.out.println("Basic block order: ");
                Iterator<BasicBlock> i = blockOrder.blockIterator();
                while (i.hasNext()) {

                    BasicBlock block = i.next();
                    debug(block, "rBlockOrder " + rBlockOrder.rdfs.getDiscoveryTime(block) + "\n");
                }
            }
            Iterator<BasicBlock> i = blockOrder.blockIterator();
            if (numIterations > 3 && numIterations % 2 == 0 && blockOrder instanceof ReverseDFSOrder) {
                if (DEBUG) {
                    System.out.println("Trying program order");
                }
                TreeSet<BasicBlock> bb = new TreeSet<>(new BackwardProgramOrder());
                Iterator<BasicBlock> j = blockOrder.blockIterator();
                while (j.hasNext()) {
                    BasicBlock block = j.next();
                    bb.add(block);
                }
                if (DEBUG) {
                    for (BasicBlock block : bb) {
                        debug(block, "\n");
                    }
                }
                i = bb.iterator();
            }
            if (DEBUG) {
                dumpDataflow(analysis);
            }

            // For each block in CFG...

            while (i.hasNext()) {

                BasicBlock block = i.next();

                // Get start fact for block.
                Fact start = analysis.getStartFact(block);
                assert start != null;

                boolean needToRecompute = false;
                // Get result facts for block,
                Fact result = analysis.getResultFact(block);
                assert result != null;

                int originalResultTimestamp = analysis.getLastUpdateTimestamp(result);

                // Meet all of the logical predecessor results into this block's
                // start.
                // Special case: if the block is the logical entry, then it gets
                // the special "entry fact".
                if (block == logicalEntryBlock()) {
                    analysis.makeFactTop(start);
                    analysis.initEntryFact(start);
                    if (DEBUG) {
                        debug(block, "Init entry fact ==> " + analysis.factToString(start) + "\n");
                    }
                    needToRecompute = true;
                } else {
                    int lastCalculated = analysis.getLastUpdateTimestamp(start);
                    Iterator<Edge> predEdgeIter = logicalPredecessorEdgeIterator(block);

                    int predCount = 0;
                    int rawPredCount = 0;
                    while (predEdgeIter.hasNext()) {
                        Edge edge = predEdgeIter.next();
                        rawPredCount++;
                        if (needToRecompute) {
                            // don't need to check to see if we need to recompute.
                            if (firstTime && !sawBackEdge) {
                                // may need to se sawBackEdge
                            } else {
                                continue;
                            }

                        }
                        BasicBlock logicalPred = isForwards ? edge.getSource() : edge.getTarget();

                        int direction = blockOrder.compare(block, logicalPred);

                        if (DEBUG) {
                            debug(block, "direction " + direction + " for " + blockId(logicalPred) + "\n");
                        }
                        if (direction < 0) {
                            sawBackEdge = true;
                        }

                        // Get the predecessor result fact
                        Fact predFact = analysis.getResultFact(logicalPred);
                        int predLastUpdated = analysis.getLastUpdateTimestamp(predFact);
                        if (!analysis.isTop(predFact)) {
                            predCount++;
                            if (predLastUpdated >= lastCalculated) {

                                needToRecompute = true;
                                if (DEBUG) {
                                    debug(block, "\n Need to recompute. My timestamp = " + lastCalculated + ", pred timestamp = "
                                            + predLastUpdated + ",\n   pred fact = " + predFact + "\n");
                                }
                                // break;
                            }
                        }
                    }
                    if (predCount == 0) {
                        needToRecompute = true;
                    }

                    if (!needToRecompute) {
                        continue;
                    }

                    analysis.makeFactTop(start);
                    predEdgeIter = logicalPredecessorEdgeIterator(block);
                    while (predEdgeIter.hasNext()) {
                        Edge edge = predEdgeIter.next();
                        BasicBlock logicalPred = isForwards ? edge.getSource() : edge.getTarget();

                        // Get the predecessor result fact
                        Fact predFact = analysis.getResultFact(logicalPred);

                        // Apply the edge transfer function.
                        Fact edgeFact = analysis.createFact();
                        analysis.copy(predFact, edgeFact);
                        analysis.edgeTransfer(edge, edgeFact);

                        if (DEBUG && !analysis.same(edgeFact, predFact)) {
                            debug(block, logicalPred, edge, "Edge transfer " + analysis.factToString(predFact) + " ==> "
                                    + analysis.factToString(edgeFact));
                        }

                        // Merge the predecessor fact (possibly transformed
                        // by the edge transfer function)
                        // into the block's start fact.
                        if (DEBUG) {
                            if (analysis.isTop(start)) {
                                debug(block, logicalPred, edge, "\n  First pred is " + analysis.factToString(edgeFact)
                                        + "\n   last updated at " + analysis.getLastUpdateTimestamp(predFact) + "\n");
                            } else {
                                debug(block, logicalPred, edge, "\n  Meet " + analysis.factToString(start) + "\n   with "
                                        + analysis.factToString(edgeFact)

                                        + "\n   pred last updated at " + analysis.getLastUpdateTimestamp(predFact) + "\n");
                            }
                        }

                        if (analysis instanceof UnconditionalValueDerefAnalysis) {
                            ((UnconditionalValueDerefAnalysis) analysis).meetInto((UnconditionalValueDerefSet) edgeFact,
                                    edge, (UnconditionalValueDerefSet) start, rawPredCount == 1);
                        } else {
                            analysis.meetInto(edgeFact, edge, start);
                        }
                        analysis.setLastUpdateTimestamp(start, timestamp);

                        int pos = -1;
                        if (block.getFirstInstruction() != null) {
                            pos = block.getFirstInstruction().getPosition();
                        }
                        if (DEBUG) {
                            System.out.println(" [" + pos + "]==> " + analysis.factToString(start) + " @ " + timestamp
                                    + " \n");
                        }
                    }
                }
                if (DEBUG) {
                    debug(block, "start fact is " + analysis.factToString(start) + "\n");
                }

                // making a copy of result facts (so we can detect if it
                // changed).
                boolean resultWasTop = analysis.isTop(result);
                Fact origResult = null;
                if (!resultWasTop) {
                    origResult = analysis.createFact();
                    analysis.copy(result, origResult);
                }

                //                if (true || analysis.isTop(start)) {
                // Apply the transfer function.

                analysis.transfer(block, null, start, result);
                //                } else {
                //                    analysis.copy(start, result);
                //                }

                if (DEBUG && SystemProperties.getBoolean("dataflow.blockdebug")) {
                    debug(block, "Dumping flow values for block:\n");
                    Iterator<InstructionHandle> ii = block.instructionIterator();
                    while (ii.hasNext()) {
                        InstructionHandle handle = ii.next();
                        Fact tmpResult = analysis.createFact();
                        analysis.transfer(block, handle, start, tmpResult);
                        System.out.println("\t" + handle + " " + analysis.factToString(tmpResult));
                    }
                }

                // See if the result changed.
                if (DEBUG) {
                    debug(block, "orig result is " + (origResult == null ? "TOP" : analysis.factToString(origResult)) + "\n");
                }
                boolean thisResultChanged = false;
                if (resultWasTop) {
                    thisResultChanged = !analysis.isTop(result);
                } else {
                    thisResultChanged = !analysis.same(result, origResult);
                }
                if (thisResultChanged) {
                    timestamp++;
                    if (DEBUG) {
                        debug(block, "result changed at timestamp " + timestamp + "\n");
                    }
                    if (DEBUG && !needToRecompute) {
                        System.out.println("I thought I didn't need to recompute");
                    }
                    change = true;
                    analysis.setLastUpdateTimestamp(result, timestamp);
                } else {
                    analysis.setLastUpdateTimestamp(result, originalResultTimestamp);
                }

                if (DEBUG) {
                    debug(block,
                            "result is " + analysis.factToString(result) + " @ timestamp "
                                    + analysis.getLastUpdateTimestamp(result) + "\n");
                }
            }

            analysis.finishIteration();
            if (!sawBackEdge) {
                break;
            }

        } while (change);

        if (DEBUG) {
            System.out.println("-- Quiescence achieved-------------------------------------------------");
            System.out.println(this.getClass().getName() + " iteration: " + numIterations + ", timestamp: " + timestamp);
            MethodGen mg = cfg.getMethodGen();
            System.out.println(mg.getClassName() + "." + mg.getName() + mg.getSignature());
            new RuntimeException("Quiescence achieved----------------------------------------------------------------")
            .printStackTrace(System.out);

        }
        DEBUG = debugWas;
    }
675575
def run(self):
        
        for task in self.get_next_tasks(None):
            self.executor.add_task(task, None)
        while not self.executor.is_done():
            done_task_and_result = self.executor.wait_for_tasks()
            for task, task_result in done_task_and_result:
                self._add_sub_tasks_to_executor(task, task_result)
632795
@MainThread
    private void handleTasksExecution() {
        if (isExecuting || executionQueue.isEmpty()) {
            return; // Nothing to dispatch
        }

        try {
            isExecuting = true;
            handleTasksExecutionWrapped();
        } finally {
            isExecuting = false;
        }
    }
762916
static void execute(Tenant tenant, Runnable runnable) {
        startTenantFlow();
        try {
            getThreadLocalInstance().setTenant(tenant);
            runnable.run();
        } finally {
            endTenantFlow();
        }
    }
898044
public void update() {
		if (done) {
			return;
		}
		
		int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
		
		while (processed > 0) {
			unqueued.clear();
			
			AL10.alSourceUnqueueBuffers(source, unqueued);
	        if (stream(unqueued.get(0))) {
	        	AL10.alSourceQueueBuffers(source, unqueued);
	        } else {
	        	remainingBufferCount--;
	        	if (remainingBufferCount == 0) {
	        		done = true;
	        	}
	        }
	        processed--;
		}
		
		int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
	    
	    if (state != AL10.AL_PLAYING) {
	    	AL10.alSourcePlay(source);
	    }
	}
613954
public static void update( CommandExecutionContext executionContext, Instance createdInstance ) {

		if( executionContext != null ) {
			createdInstance.data.put( executionContext.getNewVmMarkerKey(), executionContext.getNewVmMarkerValue());
			executionContext.getGlobalVmNumber().incrementAndGet();
			executionContext.getAppVmNumber().incrementAndGet();
		}
	}
194808
private Map<Optional<Executor>, List<ExecutableFlow>> getFlowToExecutorMap() {
    final HashMap<Optional<Executor>, List<ExecutableFlow>> exFlowMap =
        new HashMap<>();

    for (final Pair<ExecutionReference, ExecutableFlow> runningFlow : this.runningExecutions.get()
        .values()) {
      final ExecutionReference ref = runningFlow.getFirst();
      final ExecutableFlow flow = runningFlow.getSecond();
      final Optional<Executor> executor = ref.getExecutor();

      // We can set the next check time to prevent the checking of certain
      // flows.
      if (ref.getNextCheckTime() >= DateTime.now().getMillis()) {
        continue;
      }

      List<ExecutableFlow> flows = exFlowMap.get(executor);
      if (flows == null) {
        flows = new ArrayList<>();
        exFlowMap.put(executor, flows);
      }

      flows.add(flow);
    }

    return exFlowMap;
  }
1233368
public void handleInstanceExecutor() {
    for (InstanceExecutor executor : taskIdToInstanceExecutor.values()) {
      boolean isLocalSpout = spoutSets.contains(executor.getComponentName());
      int taskId = executor.getTaskId();

      int items = executor.getStreamOutQueue().size();
      for (int i = 0; i < items; i++) {
        Message msg = executor.getStreamOutQueue().poll();

        if (msg instanceof HeronTuples.HeronTupleSet) {
          HeronTuples.HeronTupleSet tupleSet = (HeronTuples.HeronTupleSet) msg;

          if (tupleSet.hasData()) {
            HeronTuples.HeronDataTupleSet d = tupleSet.getData();
            TopologyAPI.StreamId streamId = d.getStream();
            for (HeronTuples.HeronDataTuple tuple : d.getTuplesList()) {
              List<Integer> outTasks = this.topologyManager.getListToSend(streamId, tuple);

              outTasks.addAll(tuple.getDestTaskIdsList());

              if (outTasks.isEmpty()) {
                LOG.severe("Nobody to send the tuple to");
              }

              copyDataOutBound(taskId, isLocalSpout, streamId, tuple, outTasks);
            }
          }

          if (tupleSet.hasControl()) {
            HeronTuples.HeronControlTupleSet c = tupleSet.getControl();
            for (HeronTuples.AckTuple ack : c.getAcksList()) {
              copyControlOutBound(tupleSet.getSrcTaskId(), ack, true);
            }

            for (HeronTuples.AckTuple fail : c.getFailsList()) {
              copyControlOutBound(tupleSet.getSrcTaskId(), fail, false);
            }
          }
        }
      }
    }
  }
129065
def execute_update(self, update, safe=False):
		''' 
		'''

		# safe = self.safe
		# if update.safe is not None:
		#     safe = remove.safe

		assert len(update.update_data) > 0
		self.queue.append(UpdateOp(self.transaction_id, self, update.query.type, safe, update))
		if self.autoflush:
			return self.flush()
366818
def update_db():
    
    logger = get_logger(PROCESS_SCHEDULER)
    managed_process_dao = ManagedProcessDao(logger)
    managed_process_dao.clear()

    for process_name, process_entry in context.process_context.items():
        if not isinstance(process_entry, ManagedProcessEntry):
            continue

        managed_process_dao.update(process_entry)
        logger.info('Updated DB with process entry {0} from the context.'.format(process_entry.key))
1157015
def start(self):
        
        if not self.started:
            self.started = True
            self.executor = ThreadPoolExecutor(max_workers=32)
            self.poller = self.executor.submit(self.poll_events)
        else:
            raise IllegalStateError("Dispatcher is already started.")