Exemplo n.º 1
0
def invocation_operate(
    operation_id, group, method, subscription, timeout, initial_metadata,
    payload, completion, ticket_sink, termination_action, pool):
  """Constructs objects necessary for front-side operation management.

  Args:
    operation_id: An object identifying the operation.
    group: The group identifier of the operation.
    method: The method identifier of the operation.
    subscription: A base.Subscription describing the customer's interest in the
      results of the operation.
    timeout: A length of time in seconds to allow for the operation.
    initial_metadata: An initial metadata value to be sent to the other side of
      the operation. May be None if the initial metadata will be passed later or
      if there will be no initial metadata passed at all.
    payload: The first payload value to be transmitted to the other side. May be
      None if there is no such value or if the customer chose not to pass it at
      operation invocation.
    completion: A base.Completion value indicating the end of values passed to
      the other side of the operation.
    ticket_sink: A callable that accepts links.Tickets and delivers them to the
      other side of the operation.
    termination_action: A callable that accepts the outcome of the operation as
      a base.Outcome value to be called on operation completion.
    pool: A thread pool with which to do the work of the operation.

  Returns:
    An _interfaces.Operation for the operation.
  """
  lock = threading.Lock()
  with lock:
    termination_manager = _termination.invocation_termination_manager(
        termination_action, pool)
    transmission_manager = _transmission.TransmissionManager(
        operation_id, ticket_sink, lock, pool, termination_manager)
    expiration_manager = _expiration.invocation_expiration_manager(
        timeout, lock, termination_manager, transmission_manager)
    operation_context = _context.OperationContext(
        lock, termination_manager, transmission_manager, expiration_manager)
    emission_manager = _emission.EmissionManager(
        lock, termination_manager, transmission_manager, expiration_manager)
    ingestion_manager = _ingestion.invocation_ingestion_manager(
        subscription, lock, pool, termination_manager, transmission_manager,
        expiration_manager)
    reception_manager = _reception.ReceptionManager(
        termination_manager, transmission_manager, expiration_manager,
        ingestion_manager)

    termination_manager.set_expiration_manager(expiration_manager)
    transmission_manager.set_expiration_manager(expiration_manager)
    emission_manager.set_ingestion_manager(ingestion_manager)

    transmission_manager.kick_off(
        group, method, timeout, initial_metadata, payload, completion, None)

  return _EasyOperation(
      lock, termination_manager, transmission_manager, expiration_manager,
      operation_context, emission_manager, reception_manager)
Exemplo n.º 2
0
def service_operate(servicer_package, ticket, ticket_sink, termination_action,
                    pool):
    """Constructs an Operation for service of an operation.

  Args:
    servicer_package: A _utilities.ServicerPackage to be used servicing the
      operation.
    ticket: The first links.Ticket received for the operation.
    ticket_sink: A callable that accepts links.Tickets and delivers them to the
      other side of the operation.
    termination_action: A callable that accepts the outcome of the operation as
      a base.Outcome value to be called on operation completion.
    pool: A thread pool with which to do the work of the operation.

  Returns:
    An _interfaces.Operation for the operation.
  """
    lock = threading.Lock()
    with lock:
        termination_manager = _termination.service_termination_manager(
            termination_action, pool)
        transmission_manager = _transmission.TransmissionManager(
            ticket.operation_id, ticket_sink, lock, pool, termination_manager)
        expiration_manager = _expiration.service_expiration_manager(
            ticket.timeout, servicer_package.default_timeout,
            servicer_package.maximum_timeout, lock, termination_manager,
            transmission_manager)
        protocol_manager = _protocol.service_protocol_manager(
            lock, pool, termination_manager, transmission_manager,
            expiration_manager)
        operation_context = _context.OperationContext(lock,
                                                      termination_manager,
                                                      transmission_manager,
                                                      expiration_manager)
        emission_manager = _emission.EmissionManager(lock, termination_manager,
                                                     transmission_manager,
                                                     expiration_manager)
        ingestion_manager = _ingestion.service_ingestion_manager(
            servicer_package.servicer, operation_context, emission_manager,
            lock, pool, termination_manager, transmission_manager,
            expiration_manager, protocol_manager)
        reception_manager = _reception.ReceptionManager(
            termination_manager, transmission_manager, expiration_manager,
            protocol_manager, ingestion_manager)

        termination_manager.set_expiration_manager(expiration_manager)
        transmission_manager.set_expiration_manager(expiration_manager)
        emission_manager.set_ingestion_manager(ingestion_manager)

        reception_manager.receive_ticket(ticket)

    return _EasyOperation(lock, termination_manager, transmission_manager,
                          expiration_manager, operation_context,
                          emission_manager, reception_manager)