Get a primed and readytogo flow coordinator.
5137
def get_flow(self, name, options=None):
        
        config = self.project_config.get_flow(name)
        callbacks = self.callback_class()
        coordinator = FlowCoordinator(
            self.project_config,
            config,
            name=name,
            options=options,
            skip=None,
            callbacks=callbacks,
        )
        return coordinator
958512
def prepare_queues(queues, lock):
    """"""
    for queue in queues:
        queue._pebble_lock = lock
        with queue.mutex:
            queue._pebble_old_method = queue._put
            queue._put = MethodType(new_method, queue)
29914
def ProcessFlow(self, flow_processing_request):
    """"""

    client_id = flow_processing_request.client_id
    flow_id = flow_processing_request.flow_id

    data_store.REL_DB.AckFlowProcessingRequests([flow_processing_request])

    try:
      rdf_flow = data_store.REL_DB.LeaseFlowForProcessing(
          client_id, flow_id, processing_time=rdfvalue.Duration("6h"))
    except db.ParentHuntIsNotRunningError:
      flow_base.TerminateFlow(client_id, flow_id, "Parent hunt stopped.")
      return

    logging.info("Processing Flow %s/%s (%s).", client_id, flow_id,
                 rdf_flow.flow_class_name)

    flow_cls = registry.FlowRegistry.FlowClassByName(rdf_flow.flow_class_name)
    flow_obj = flow_cls(rdf_flow)

    if not flow_obj.IsRunning():
      raise ValueError(
          "Received a request to process flow %s on client %s that is not "
          "running." % (flow_id, client_id))

    processed = flow_obj.ProcessAllReadyRequests()
    if processed == 0:
      raise ValueError(
          "Unable to process any requests for flow %s on client %s." %
          (flow_id, client_id))

    while not self._ReleaseProcessedFlow(flow_obj):
      processed = flow_obj.ProcessAllReadyRequests()
      if processed == 0:
        raise ValueError(
            "%s/%s: ReleaseProcessedFlow returned false but no "
            "request could be processed (next req: %d)." %
            (client_id, flow_id, flow_obj.rdf_flow.next_request_to_process))
468898
private void setup(final Handler<AsyncResult<Void>> doneHandler) {
    // Retrieve the component context from the coordinator (the current cluster).
    // If the context has changed due to a network configuration change, the
    // internal context and input/output connections will be automatically updated.
    log.debug(String.format("%s - Starting cluster coordination", DefaultComponent.this));
    coordinator.start(new Handler<AsyncResult<Void>>() {
      @Override
      public void handle(AsyncResult<Void> result) {
        if (result.failed()) {
          new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
        } else {
          // We have to make sure the input and output collectors are started
          // simultaneously in order to support circular connections. If both
          // input and output aren't started at the same time then circular
          // connections will never open.
          final CountingCompletionHandler<Void> ioHandler = new CountingCompletionHandler<Void>(2);
          ioHandler.setHandler(new Handler<AsyncResult<Void>>() {
            @Override
            public void handle(AsyncResult<Void> result) {
              if (result.failed()) {
                new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
              } else {
                // Tell the coordinator we're ready for the network to start.
                coordinator.resume();
              }
            }
          });

          output.open(new Handler<AsyncResult<Void>>() {
            @Override
            public void handle(AsyncResult<Void> result) {
              if (result.failed()) {
                log.error(String.format("%s - Failed to open component outputs", DefaultComponent.this), result.cause());
                ioHandler.fail(result.cause());
              } else {
                ioHandler.succeed();
              }
            }
          });

          input.open(new Handler<AsyncResult<Void>>() {
            @Override
            public void handle(AsyncResult<Void> result) {
              if (result.failed()) {
                log.error(String.format("%s - Failed to open component inputs", DefaultComponent.this), result.cause());
                ioHandler.fail(result.cause());
              } else {
                ioHandler.succeed();
              }
            }
          });
        }
      }
    });

    // The resume handler will be called by the coordinator once the
    // network's manager has indicated that all the components in the
    // network have finished setting up their connections.
    coordinator.resumeHandler(new Handler<Void>() {
      @Override
      @SuppressWarnings("unchecked")
      public void handle(Void _) {
        if (!started) {
          started = true;
          log.debug(String.format("%s - Started", DefaultComponent.this, context.component().name(), context.number()));
          List<ComponentHook> hooks = context.component().hooks();
          for (ComponentHook hook : hooks) {
            hook.handleStart(DefaultComponent.this);
          }
          new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler);
        }
      }
    });
  }
805085
def get_requested_form(self, request):
        """"""
        flow_name = self.get_flow_name()
        flow_key = '%s_flow' % self.flow_type
        flow_enabled = self.enabled
        form_data = None

        if (flow_enabled and
            request.method == 'POST' and
            request.POST.get(flow_key, False) and
            request.POST[flow_key] == flow_name):

            form_data = request.POST

        form = self.init_form(
            form_data,
            widget_attrs=self.flow_args.get('widget_attrs', None),
            template=self.get_template_name(self.flow_args.get('template', None))
        )

        # Attach flow identifying field to differentiate among several possible forms.
        form.fields[flow_key] = forms.CharField(required=True, initial=flow_name, widget=forms.HiddenInput)
        form.flow_enabled = flow_enabled
        form.flow_disabled_text = self.disabled_text
        return form
683344
def Flow(self, flow_id):
    """"""

    return flow.FlowRef(
        client_id=self.client_id, flow_id=flow_id, context=self._context)
846933
def get():
  """"""
  configs = {c.name(): c
             for c in lib.RunConfig.all_subclasses() if c.priority()}

  if not configs:
    raise sc_process.SC2LaunchError("No valid run_configs found.")

  if FLAGS.sc2_run_config is None:  # Find the highest priority as default.
    return max(configs.values(), key=lambda c: c.priority())()

  try:
    return configs[FLAGS.sc2_run_config]()
  except KeyError:
    raise sc_process.SC2LaunchError(
        "Invalid run_config. Valid configs are: %s" % (
            ", ".join(sorted(configs.keys()))))
78223
def get_waiting_components(self):
        # type: () -> List[Tuple[str, str, Set[str]]]
        
        with self.__instances_lock:
            result = []
            for name, (context, _) in self.__waiting_handlers.items():
                # Compute missing handlers
                missing = set(context.factory_context.get_handlers_ids())
                missing.difference_update(self._handlers.keys())

                result.append((name, context.factory_context.name, missing))

            result.sort()
            return result
719355
def free_processed_queue(self):
        '''  '''
        with self._lock:
            if len(self._processed_coordinators) > 0:
                for _coordinator in self._processed_coordinators:
                    _coordinator.free_resources()
                self._processed_coordinators = []
280784
def get_preparer(mixed: Union[SQLCompiler, Engine,
                              Dialect]) -> IdentifierPreparer:
    
    dialect = get_dialect(mixed)
    # noinspection PyUnresolvedReferences
    return dialect.preparer(dialect)
651864
def get_attention(config: AttentionConfig, max_seq_len: int, prefix: str = C.ATTENTION_PREFIX) -> 'Attention':
    

    att_cls = Attention.get_attention_cls(config.type)
    params = config.__dict__.copy()
    params.pop('_frozen')
    params['max_seq_len'] = max_seq_len
    params['prefix'] = prefix
    return _instantiate(att_cls, params)
916868
def _ScheduleVariableHunt(hunt_obj):
  """"""
  if hunt_obj.client_rate != 0:
    raise VariableHuntCanNotHaveClientRateError(hunt_obj.hunt_id,
                                                hunt_obj.client_rate)

  seen_clients = set()
  for flow_group in hunt_obj.args.variable.flow_groups:
    for client_id in flow_group.client_ids:
      if client_id in seen_clients:
        raise CanStartAtMostOneFlowPerClientError(hunt_obj.hunt_id, client_id)
      seen_clients.add(client_id)

  now = rdfvalue.RDFDatetime.Now()
  for flow_group in hunt_obj.args.variable.flow_groups:
    flow_cls = registry.FlowRegistry.FlowClassByName(flow_group.flow_name)
    flow_args = flow_group.flow_args if flow_group.HasField(
        "flow_args") else None

    for client_id in flow_group.client_ids:
      flow.StartFlow(
          client_id=client_id,
          creator=hunt_obj.creator,
          cpu_limit=hunt_obj.per_client_cpu_limit,
          network_bytes_limit=hunt_obj.per_client_network_bytes_limit,
          flow_cls=flow_cls,
          flow_args=flow_args,
          # Setting start_at explicitly ensures that flow.StartFlow won't
          # process flow's Start state right away. Only the flow request
          # will be scheduled.
          start_at=now,
          parent_hunt_id=hunt_obj.hunt_id)
354554
def _ReadAndLockNextRequestsToProcess(self, flow_keys, cursor):
    """"""

    query = """
      SELECT client_id, flow_id, next_request_to_process
      FROM flows
      WHERE {conditions}
      FOR UPDATE
    """
    condition_template = "(client_id = %s AND flow_id = %s)"
    conditions = [condition_template] * len(flow_keys)
    query = query.format(conditions=" OR ".join(conditions))
    args = []
    for client_id, flow_id in flow_keys:
      args.append(db_utils.ClientIDToInt(client_id))
      args.append(db_utils.FlowIDToInt(flow_id))

    cursor.execute(query, args)
    next_requests = {}
    for client_id_int, flow_id_int, next_request in cursor.fetchall():
      flow_key = (db_utils.IntToClientID(client_id_int),
                  db_utils.IntToFlowID(flow_id_int))
      next_requests[flow_key] = next_request
    return next_requests
1063013
def Handle(self, args, token=None):
    """"""

    if data_store.RelationalDBEnabled():
      flow_iterator = iteritems(registry.FlowRegistry.FLOW_REGISTRY)
    else:
      flow_iterator = iteritems(registry.AFF4FlowRegistry.FLOW_REGISTRY)

    result = []
    for name, cls in sorted(flow_iterator):

      # Flows without a category do not show up in the GUI.
      if not getattr(cls, "category", None):
        continue

      # Only show flows that the user is allowed to start.
      try:
        if self.access_check_fn:
          self.access_check_fn(token.username, name)
      except access_control.UnauthorizedAccess:
        continue

      result.append(ApiFlowDescriptor().InitFromFlowClass(cls, token=token))

    return ApiListFlowDescriptorsResult(items=result)
136882
public static <T> FlowableTransformer<T,T> doOnCompleteCountFx(Consumer<Integer> onComplete) {
        return obs -> obs.compose(doOnCompleteCount(i -> runOnFx(i,onComplete)));
    }
638036
def dispatch_object_source(client, account_info, bid, bucket_info):
    

    if (account_info.get('inventory') and
        bucket_info['keycount'] >
            account_info['inventory'].get('bucket-size-threshold',
                                          DEFAULT_INVENTORY_BUCKET_SIZE_THRESHOLD)):
        inventory_info = get_bucket_inventory(
            client,
            bucket_info['name'],
            account_info['inventory'].get('id-selector', '*'))
        if inventory_info is not None:
            return invoke(
                process_bucket_inventory, bid,
                inventory_info['bucket'], inventory_info['prefix'])

    if bucket_info['keycount'] > PARTITION_BUCKET_SIZE_THRESHOLD:
        invoke(process_bucket_partitions, bid)
    else:
        invoke(process_bucket_iterator, bid)
620245
Coordinator getCoordinator()
    {
        coordinator = new Coordinator();
        try
        {
            for (String pu : clientMap.keySet())
            {
                PersistenceUnitMetadata puMetadata = KunderaMetadataManager.getPersistenceUnitMetadata(kunderaMetadata,
                        pu);

                String txResource = puMetadata.getProperty(PersistenceProperties.KUNDERA_TRANSACTION_RESOURCE);

                if (txResource != null)
                {
                    TransactionResource resource = (TransactionResource) Class.forName(txResource).newInstance();
                    coordinator.addResource(resource, pu);
                    Client client = clientMap.get(pu);

                    if (!(client instanceof TransactionBinder))
                    {
                        throw new KunderaTransactionException(
                                "Client : "
                                        + client.getClass()
                                        + " must implement TransactionBinder interface, if {kundera.transaction.resource.class} property provided!");
                    }
                    else
                    {
                        ((TransactionBinder) client).bind(resource);
                    }
                }
                else
                {
                    coordinator.addResource(new DefaultTransactionResource(clientMap.get(pu)), pu);
                }
            }
        }
        catch (Exception e)
        {
            log.error("Error while initializing Transaction Resource:", e);
            throw new KunderaTransactionException(e);

        }

        return coordinator;
    }