Finalize to add the client to the list of observer.

        :type transaction: Transaction
        :param transaction: the transaction that owns the response
        :return: the transaction unmodified
506014
def send_response(self, transaction):
        
        host, port = transaction.request.source
        key_token = hash(str(host) + str(port) + str(transaction.request.token))
        if key_token in self._relations:
            if transaction.response.code == defines.Codes.CONTENT.number:
                if transaction.resource is not None and transaction.resource.observable:

                    transaction.response.observe = transaction.resource.observe_count
                    self._relations[key_token].allowed = True
                    self._relations[key_token].transaction = transaction
                    self._relations[key_token].timestamp = time.time()
                else:
                    del self._relations[key_token]
            elif transaction.response.code >= defines.Codes.ERROR_LOWER_BOUND:
                del self._relations[key_token]
        return transaction
1313889
def apply_transaction(self,
                          transaction: BaseTransaction
                          ) -> Tuple[BaseBlock, Receipt, BaseComputation]:
        
        vm = self.get_vm(self.header)
        base_block = vm.block

        receipt, computation = vm.apply_transaction(base_block.header, transaction)
        header_with_receipt = vm.add_receipt_to_header(base_block.header, receipt)

        # since we are building the block locally, we have to persist all the incremental state
        vm.state.persist()
        new_header = header_with_receipt.copy(state_root=vm.state.state_root)

        transactions = base_block.transactions + (transaction, )
        receipts = base_block.get_receipts(self.chaindb) + (receipt, )

        new_block = vm.set_block_transactions(base_block, new_header, transactions, receipts)

        self.header = new_block.header

        return new_block, receipt, computation
101775
public void afterCompletion(int status) {
		switch (status) {
			case Status.STATUS_COMMITTED:
				txContext.run();
				break;
			default:				
		}
		TransactionContextThreadLocal.setTransactionContext(null);
	}
1344488
def rollback_transaction(self):
        
        self._assert_open()
        if not self._transaction:
            raise TransactionError("No transaction to rollback")
        cx = self._connection
        if cx:
            metadata = {}
            try:
                cx.rollback(on_success=metadata.update)
            finally:
                self._disconnect(sync=True)
                self._transaction = None
367394
def finalize
      @transactions.sort! { |a, b| a.date <=> b.date }
      balance = Value.new(0)
      @balances = @transactions.map do |act_txn|
        balance += act_txn.value
        {
          date: act_txn.date,
          value: balance,
        }
      end
    end
1076026
def create_request(payment_transaction)
      request = super payment_transaction

      payment_transaction.payment.status  = payment_status
      payment_transaction.processor_type  = PaymentTransaction::PROCESSOR_QUERY
      payment_transaction.processor_name  = @api_method
      payment_transaction.status          = PaymentTransaction::STATUS_PROCESSING

      request
    end
414981
def commit_transaction(self):
        
        self._assert_open()
        if not self._transaction:
            raise TransactionError("No transaction to commit")
        metadata = {}
        try:
            self._connection.commit(on_success=metadata.update)
        finally:
            self._disconnect(sync=True)
            self._transaction = None
        bookmark = metadata.get("bookmark")
        self._bookmarks_in = tuple([bookmark])
        self._bookmark_out = bookmark
        return bookmark
175051
def start_transaction(self, read_concern=None, write_concern=None,
                          read_preference=None):
        
        self._check_ended()

        if self._in_transaction:
            raise InvalidOperation("Transaction already in progress")

        read_concern = self._inherit_option("read_concern", read_concern)
        write_concern = self._inherit_option("write_concern", write_concern)
        read_preference = self._inherit_option(
            "read_preference", read_preference)

        self._transaction.opts = TransactionOptions(
            read_concern, write_concern, read_preference)
        self._transaction.reset()
        self._transaction.state = _TxnState.STARTING
        self._start_retryable_write()
        return _TransactionContext(self)
729806
def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
        
        return self.get_transaction_class()(*args, **kwargs)
495004
protected void eventPostCommitRemove(SIMPMessage msg, TransactionCommon transaction)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "eventPostCommitRemove", new Object[] { msg, transaction });

        // NB: ideally this would go in afterCompletion but we
        // dont have the transaction reference to register for the callback
        synchronized (orderLock)
        {

            // Remove the transaction from the transactionSet if applicable
            // Use the orderLock to synch with attachConsumer
            if (transactionSet != null)
            {
                transactionSet.remove(transaction.getPersistentTranId());
                if (transactionSet.isEmpty())
                {
                    transactionSet = null;
                    // Get the consumer and resume it
                    consumerPoints.get(0).
                                    getConsumerPoint().
                                    resumeConsumer(DispatchableConsumerPoint.SUSPEND_FLAG_INITIAL_INDOUBTS);
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "eventPostCommitRemove");
    }
886593
public final void commitExternal(final PersistentTransaction transaction)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        {
            SibTr.entry(this, tc, "commitExternal", transaction);
            SibTr.exit(this, tc, "commitExternal");
        }
    }
1282608
def settle(self, reserveTransactionId, transactionAmount=None):
        
        params = {}
        params['ReserveTransactionId'] = reserveTransactionId
        if(transactionAmount != None):
            params['TransactionAmount'] = transactionAmount
        
        response = self.make_request("Settle", params)
        body = response.read()
        if(response.status == 200):
            rs = ResultSet()
            h = handler.XmlHandler(rs, self)
            xml.sax.parseString(body, h)
            return rs
        else:
            raise FPSResponseError(response.status, response.reason, body)
1353251
def _handle_response(self, transaction):
        
        code = transaction.response.code
        utils.check_code(code)
        """
        VALID response:
        change the current cache value by switching the option set with the one provided
        also resets the timestamp
        if the request etag is different from the response, send the cached response
        """
        if code == Codes.VALID.number:
            logger.debug("received VALID")
            self.cache.validate(transaction.request, transaction.response)
            if transaction.request.etag != transaction.response.etag:
                element = self.cache.search_response(transaction.request)
                transaction.response = element.cached_response
            return transaction

        """
        CHANGED, CREATED or DELETED response:
        mark the requested resource as not fresh
        """
        if code == Codes.CHANGED.number or code == Codes.CREATED.number or code == Codes.DELETED.number:
            target = self.cache.search_related(transaction.request)
            if target is not None:
                for element in target:
                    self.cache.mark(element)
            return transaction

        """
        any other response code can be cached normally
        """
        self.cache.cache_add(transaction.request, transaction.response)
        return transaction
1113671
def begin(self):
        
        if hasattr(self._locals, 'transaction_exists') and self._locals.transaction_exists:
            raise TransactionError("Nested transactions are not allowed.")
        if self.state != _STATE_NOT_STARTED:
            raise TransactionError("Transaction has already been started.")
        self._locals.transaction_exists = True
        self.start_time = time.time()
        self.thread_id = thread_id()
        try:
            request = transaction_create_codec.encode_request(timeout=int(self.timeout * 1000), durability=self.durability,
                                                              transaction_type=self.transaction_type,
                                                              thread_id=self.thread_id)
            response = self.client.invoker.invoke_on_connection(request, self.connection).result()
            self.id = transaction_create_codec.decode_response(response)["response"]
            self.state = _STATE_ACTIVE
        except:
            self._locals.transaction_exists = False
            raise
33122
def send_response(self, transaction):
        
        host, port = transaction.request.source
        key_token = hash(str(host) + str(port) + str(transaction.request.token))
        if (key_token in self._block2_receive and transaction.response.payload is not None) or \
                (transaction.response.payload is not None and len(transaction.response.payload) > defines.MAX_PAYLOAD):
            if key_token in self._block2_receive:

                byte = self._block2_receive[key_token].byte
                size = self._block2_receive[key_token].size
                num = self._block2_receive[key_token].num

            else:
                byte = 0
                num = 0
                size = defines.MAX_PAYLOAD
                m = 1

                self._block2_receive[key_token] = BlockItem(byte, num, m, size)

            if len(transaction.response.payload) > (byte + size):
                m = 1
            else:
                m = 0
            transaction.response.payload = transaction.response.payload[byte:byte + size]
            del transaction.response.block2
            transaction.response.block2 = (num, m, size)

            self._block2_receive[key_token].byte += size
            self._block2_receive[key_token].num += 1
            if m == 0:
                del self._block2_receive[key_token]

        return transaction
45445
public void commit(DBTransaction transaction) {
        try {
            applyUpdates(transaction);
        } catch (Exception e) {
            m_logger.error("Updates failed", e);
            throw e;
        } finally {
            transaction.clear();
        }
    }
878904
def get_transaction_result(
            self,
            transaction: BaseOrSpoofTransaction,
            at_header: BlockHeader) -> bytes:
        
        with self.get_vm(at_header).state_in_temp_block() as state:
            computation = state.costless_execute_transaction(transaction)

        computation.raise_if_error()
        return computation.output