Beispiel #1
0
void
cmx_participantFindTopicAction(
    v_public p,
    c_voidp args)
{
    cmx_walkEntityArg arg;
    c_iter topics;
    v_entity topic;
    c_bool proceed;
    c_char* xmlEntity;

    arg = cmx_walkEntityArg(args);
    topics = v_resolveTopics(v_objectKernel(p), cmx_walkParticipantArg(arg)->topicName);
    topic = v_entity(c_iterTakeFirst(topics));

    while(topic != NULL){
        proceed = cmx_entityNewFromWalk(v_public(topic), &arg->entityArg);

        if(proceed == TRUE){
            xmlEntity = arg->entityArg.result;
            arg->list = c_iterInsert(arg->list, xmlEntity);
            arg->length += strlen(xmlEntity);
        }
        c_free(topic);
        topic = v_entity(c_iterTakeFirst(topics));
    }
    c_iterFree(topics);
}
Beispiel #2
0
void
jni_getTopicKeyExpression(
    v_entity entity,
    c_voidp args)
{
    v_kernel vk;
    c_iter vtopics;
    c_array keyList;
    c_char* keyExpr;
    c_long nrOfKeys, totalSize, i;
    c_string fieldName, actualFieldName;
    struct jni_topicArg *arg;
    
    arg = (struct jni_topicArg *)args;
    vk = v_objectKernel(entity);
    
    if(vk != NULL){
        vtopics = v_resolveTopics(vk, arg->topicName);
            
        if(c_iterLength(vtopics) == 0){
            c_iterFree(vtopics);
        }
        else{
            keyList = v_topicMessageKeyList(c_iterTakeFirst(vtopics));
            c_iterFree(vtopics);                
            nrOfKeys = c_arraySize(keyList);

            if (nrOfKeys>0) {
                totalSize = 0;
                
                for (i=0;i<nrOfKeys;i++) {
                    fieldName = c_fieldName(keyList[i]);
                    totalSize += (strlen(fieldName)+1-9/*skip 'userdata.'*/);
                }
                keyExpr = (c_char *)os_malloc((size_t)(totalSize+1));
                keyExpr[0] = 0;
                
                for (i=0;i<nrOfKeys;i++) {
                    fieldName = c_fieldName(keyList[i]);
                    actualFieldName = c_skipUntil(fieldName, ".");
                    actualFieldName++; /*skip '.' */
                    os_strcat(keyExpr,actualFieldName);
                    
                    if (i<(nrOfKeys-1)) { 
                        os_strcat(keyExpr,","); 
                    }
                }
                arg->keyExpr = keyExpr;
            } else{
                /*No keys, do nothing.*/
            }
            arg->result = U_RESULT_OK;
        }
    }
}
Beispiel #3
0
v_index
v__indexNew(
    v_dataReader reader,
    q_expr _from,
    c_iter indexList,
    v_indexNewAction action,
    c_voidp arg)
{
    v_kernel kernel;
    v_index index;
    v_topic topic;
    c_type instanceType;
    c_iter list;
    c_char *keyExpr;
    c_array keyList;
    c_ulong nrOfTopics;

    assert(C_TYPECHECK(reader,v_dataReader));
    kernel = v_objectKernel(reader);

    if (q_isId(_from)) {
        list = v_resolveTopics(kernel,q_getId(_from));
        nrOfTopics = c_iterLength(list);
        if (nrOfTopics == 0) {
            OS_REPORT(OS_ERROR,
                        "v__indexNew", V_RESULT_ILL_PARAM,
                        "Unknown topic %s",
                        q_getId(_from));
            c_iterFree(list);
            return NULL;
        }
        if (nrOfTopics > 1) {
            OS_REPORT(OS_ERROR,
                        "v__indexNew", V_RESULT_ILL_PARAM,
                        "Multiple topic definitions of: %s",
                        q_getId(_from));
            topic = v_topic(c_iterTakeFirst(list));
            while (topic != NULL) {
                c_free(topic);
                topic = v_topic(c_iterTakeFirst(list));
            }
            c_iterFree(list);
            return NULL;
        }
        topic = c_iterTakeFirst(list);
        c_iterFree(list);
        index = v_index(c_iterReadAction(indexList, indexCompare, topic));
        if (index == NULL) {
            /* If the userKey is enabled then the instance type key field type
             * will be determined from the user key expression and topic.
             * Otherwise when no user key is specified the default Topic key
             * type will be used.
             */
            if (v_reader(reader)->qos->userKey.v.enable) {
                keyExpr = v_reader(reader)->qos->userKey.v.expression;
            } else {
                keyExpr = NULL;
            }
            instanceType = createInstanceType(topic,keyExpr,&keyList);
            if (instanceType) {
                index = v_index(v_objectNew(kernel,K_INDEX));
                v_indexInit(index, instanceType, keyList, v_reader(reader));
            }
            c_free(keyList);
            c_free(instanceType);

            if (index != NULL) {
                if (action != NULL && !action(index, topic, arg)) {
                    OS_REPORT(OS_ERROR,
                        "v_indexNew", V_RESULT_INTERNAL_ERROR,
                        "v_indexNewAction failed!");
                    c_free(index);
                    index = NULL;
                } else {
                    (void)c_iterAppend(indexList, index);
                }
            }
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "v_indexNew failed",V_RESULT_ILL_PARAM,
                  "illegal from clause specified");
        assert(FALSE);
        index = NULL;
    }
    return index;
}
Beispiel #4
0
u_group
u_groupNew(
    u_participant participant,
    const c_char *partitionName,
    const c_char *topicName,
    v_duration timeout)
{
    u_result r;
    v_participant kparticipant;
    v_kernel kernel;
    v_topic ktopic;
    v_partition kpartition;
    v_group kgroup;
    c_iter topics;
    os_time delay;
    u_group group = NULL;

    if ((partitionName != NULL) && (topicName != NULL)) {
        if (participant != NULL) {
            r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant));
            if (r == U_RESULT_OK){
                assert(kparticipant);
                kernel = v_objectKernel(kparticipant);
                topics = v_resolveTopics(kernel,topicName);
                if (c_iterLength(topics) == 0) {
                    c_iterFree(topics);
                    delay.tv_sec = timeout.seconds;
                    delay.tv_nsec = timeout.nanoseconds;
                    os_nanoSleep(delay);
                    topics = v_resolveTopics(v_objectKernel(kparticipant),
                                             topicName);
                }
                if (c_iterLength(topics) > 1) {
                    OS_REPORT_1(OS_WARNING, "u_groupNew", 0,
                                "Internal error: "
                                "Multiple topics found with name = <%s>.",
                                topicName);
                }

                ktopic = c_iterTakeFirst(topics);

                /* If ktopic == NULL, the topic definition is unknown.
                 * This is not critical since it may become known in the near future.
                 * In that case the caller is responsible for retrying to create this group,
                 * and log something if, eventually, the group still cannot be created.
                 */
                if (ktopic != NULL) {
                    kpartition = v_partitionNew(kernel, partitionName, NULL);
                    if (kpartition != NULL) {
                        kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic);
                        if (kgroup != NULL) {
                            group = u_groupCreate(kgroup, participant);
                            if (group == NULL) {
                                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                            "Create proxy failed. "
                                            "For Partition <%s> and Topic <%s>.",
                                            partitionName, topicName);
                            }
                            c_free(kgroup);
                        } else {
                            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                        "Create kernel entity failed. "
                                        "For Partition <%s> and Topic <%s>.",
                                        partitionName, topicName);
                        }
                        c_free(kpartition);
                    } else {
                        OS_REPORT_2(OS_ERROR,"u_groupNew", 0,
                                    "Failed to create partition. "
                                    "For Partition <%s> and Topic <%s>.",
                                    partitionName, topicName);
                    }
                    c_free(ktopic);
                }
                ktopic = c_iterTakeFirst(topics);
                while (ktopic != NULL) {
                    c_free(ktopic);
                    ktopic = c_iterTakeFirst(topics);
                }
                c_iterFree(topics);
                r = u_entityRelease(u_entity(participant));
            } else {
                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                            "Claim kernel participant failed."
                            "For Partition <%s> and Topic <%s>.",
                            partitionName, topicName);
            }
        } else {
            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                        "No participant specified. "
                        "For Partition <%s> and Topic <%s>.",
                        partitionName, topicName);
        }
    } else {
        OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                    "Illegal parameter."
                    "partitionName = <0x%x>, topicName = <0x%x>.",
                    partitionName, topicName);
    }
    return group;
}
Beispiel #5
0
u_group
u_groupNew(
    u_participant participant,
    const c_char *partitionName,
    const c_char *topicName,
    v_duration timeout)
{
    u_result r;
    v_participant kparticipant;
    v_kernel kernel;
    v_topic ktopic;
    v_partition kpartition;
    v_group kgroup;
    c_iter topics;
    os_time delay;
    u_group group = NULL;

    if ((partitionName != NULL) && (topicName != NULL)) {
        if (participant != NULL) {
            r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant));
            if (r == U_RESULT_OK){
                assert(kparticipant);
                kernel = v_objectKernel(kparticipant);
                topics = v_resolveTopics(kernel,topicName);
                if (c_iterLength(topics) == 0) {
                    c_iterFree(topics);
                    delay.tv_sec = timeout.seconds;
                    delay.tv_nsec = timeout.nanoseconds;
                    os_nanoSleep(delay);
                    topics = v_resolveTopics(v_objectKernel(kparticipant),
                                             topicName);
                }
                if (c_iterLength(topics) > 1) {
                    OS_REPORT_1(OS_WARNING, "u_groupNew", 0,
                                "Internal error: "
                                "Multiple topics found with name = <%s>.",
                                topicName);
                }
                ktopic = c_iterTakeFirst(topics);
                if (ktopic != NULL) {
                    kpartition = v_partitionNew(kernel, partitionName, NULL);
                    if (kpartition != NULL) {
                        kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic);
                        if (kgroup != NULL) {
                            group = u_groupCreate(kgroup, participant);
                            if (group == NULL) {
                                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                            "Create proxy failed. "
                                            "For Partition <%s> and Topic <%s>.",
                                            partitionName, topicName);
                            }
                            c_free(kgroup);
                        } else {
                            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                        "Create kernel entity failed. "
                                        "For Partition <%s> and Topic <%s>.",
                                        partitionName, topicName);
                        }
                        c_free(kpartition);
                    } else {
                        OS_REPORT_2(OS_ERROR,"u_groupNew", 0,
                                    "Failed to create partition. "
                                    "For Partition <%s> and Topic <%s>.",
                                    partitionName, topicName);
                    }
                    c_free(ktopic);
                }else {
                    OS_REPORT_2(OS_ERROR,"u_groupNew", 0,
                                    "Topic not (yet) known. "
                                    "For Partition <%s> and Topic <%s>.",
                                    partitionName, topicName);
                }
                ktopic = c_iterTakeFirst(topics);
                while (ktopic != NULL) {
                    c_free(ktopic);
                    ktopic = c_iterTakeFirst(topics);
                }
                c_iterFree(topics);
                r = u_entityRelease(u_entity(participant));
            } else {
                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                            "Claim kernel participant failed."
                            "For Partition <%s> and Topic <%s>.",
                            partitionName, topicName);
            }
        } else {
            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                        "No participant specified. "
                        "For Partition <%s> and Topic <%s>.",
                        partitionName, topicName);
        }
    } else {
        OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                    "Illegal parameter."
                    "partitionName = <0x%x>, topicName = <0x%x>.",
                    partitionName, topicName);
    }
    return group;
}