Пример #1
0
void truncateAndFlush(CatContext *context, unsigned long long timestampMs) {
    CatMessageTree *pRootMsg = context->tree;
    CATStaticStack *pStack = context->transactionStack;
    CatMessage *message = pRootMsg->root;

    if (!isCatTransaction(message)) {
        return;
    }
    sds id = pRootMsg->messageId;

    if (id == NULL) {
        id = getNextMessageId();
        pRootMsg->messageId = id;
    }
    sds rootId = pRootMsg->rootMessageId;
    sds childId = getNextMessageId();

    CatTransaction *source = (CatTransaction *) message;

    CatTransaction *target = copyCatTransaction(source);
    target->setStatus(target, CAT_SUCCESS);

    migrateMessage(pStack, source, target, 1);

    int i;
    i = getCATStaticQueueSize(pStack) - 1;
    for (; i >= 0; --i) {
        CatTransaction *t = (CatTransaction *) getCATStaticQueueByIndex(pStack, i);
        CatTransactionInner *tInner = getInnerTrans(t);
        tInner->message.timestampMs = timestampMs;
        tInner->durationStart = GetTime64() * 1000 * 1000;
    }
    CatEvent *next = createCatEvent("RemoteCall", "Next");

    next->addData(next, childId);
    next->setStatus(next, CAT_SUCCESS);
    target->addChild(target, next);

    // tree is the parent, and m_tree is the child.
    CatMessageTree *pCp = copyCatMessageTree(pRootMsg);

    pCp->root = (CatMessage *) target;

    pRootMsg->messageId = childId;

    if (pRootMsg->parentMessageId != NULL) {
        catsdsfree(pRootMsg->parentMessageId);
    }

    pRootMsg->parentMessageId = id;
    pRootMsg->rootMessageId = (rootId != NULL ? rootId : catsdsdup(id));

    context->elementSize = getCATStaticStackSize(pStack);
    context->lastTruncateTransDurationUs =
            context->lastTruncateTransDurationUs + getCatTransactionDurationUs(target);

    catMessageManagerFlush(pCp);
}
 void CMessageBrokerController::prepareMessage(Json::Value& root)
 {
    root["jsonrpc"] = "2.0";
    root["id"] = getNextMessageId();
 }