d_readerRequest d_readerRequestNew( d_admin admin, v_handle source, c_char* filter, c_char** filterParams, c_long filterParamsCount, struct v_resourcePolicy resourceLimits, c_time minSourceTimestamp, c_time maxSourceTimestamp) { d_readerRequest request; c_long i; v_handleResult handleResult; v_reader vreader, *vreaderPtr; c_iter partitions; v_partition partition; v_topic topic; d_group dgroup; c_char *topicName; d_quality quality; request = d_readerRequest(os_malloc(C_SIZEOF(d_readerRequest))); if(request){ d_lockInit(d_lock(request), D_READER_REQUEST, d_readerRequestDeinit); request->admin = admin; request->readerHandle.index = source.index; request->readerHandle.serial = source.serial; request->readerHandle.server = source.server; request->requests = d_tableNew(d_chainCompare, d_chainFree); if(filter){ request->filter = os_strdup(filter); } else { request->filter = NULL; } request->resourceLimits = resourceLimits; request->minSourceTimestamp = minSourceTimestamp; request->maxSourceTimestamp = maxSourceTimestamp; request->filterParamsCount = filterParamsCount; if(filterParamsCount > 0){ request->filterParams = (c_char**)(os_malloc( filterParamsCount*sizeof(c_char*))); for(i=0; i<filterParamsCount; i++){ request->filterParams[i] = os_strdup(filterParams[i]); } } else { request->filterParams = NULL; } request->groups = d_tableNew(d_groupCompare, d_groupFree); handleResult = v_handleClaim(source, (v_object*)(vreaderPtr = &vreader)); if(handleResult == V_HANDLE_OK){ if(v_object(vreader)->kind == K_DATAREADER){ topic = v_dataReaderGetTopic(v_dataReader(vreader)); topicName = v_entity(topic)->name; partitions = ospl_c_select(v_subscriber(vreader->subscriber)->partitions->partitions, 0); partition = v_partition(c_iterTakeFirst(partitions)); while(partition){ quality.seconds = 0; quality.nanoseconds = 0; dgroup = d_groupNew( v_entity(partition)->name, topicName, topic->qos->durability.kind, D_GROUP_KNOWLEDGE_UNDEFINED, quality); d_tableInsert(request->groups, dgroup); c_free(partition); partition = v_partition(c_iterTakeFirst(partitions)); } c_free(topic); } else { d_readerRequestFree(request); request = NULL; } v_handleRelease(source); } else { d_readerRequestFree(request); request = NULL; } } return request; }
d_storeResult d_groupInfoInject( d_groupInfo _this, const d_store store, u_participant participant, d_group* group) { d_storeResult result; u_group ugroup; u_partition upartition; v_partitionQos partitionQos; v_duration timeout; c_string name; if(_this && store && participant){ result = d_topicInfoInject(_this->topic, store, participant); if(result == D_STORE_RESULT_OK){ partitionQos = u_partitionQosNew(NULL); if(partitionQos) { d_storeReport(store, D_LEVEL_FINE, "PartitionQoS created.\n"); upartition = u_partitionNew(participant, _this->partition, partitionQos); if(upartition) { name = d_topicInfoGetName(_this->topic); d_storeReport(store, D_LEVEL_FINE, "Partition %s created.\n", _this->partition); timeout.seconds = 0; timeout.nanoseconds = 0; ugroup = u_groupNew(participant, _this->partition, name, timeout); if(ugroup) { d_storeReport(store, D_LEVEL_INFO, "Group %s.%s created.\n", _this->partition, name); *group = d_groupNew(_this->partition, name, D_DURABILITY_PERSISTENT, _this->completeness, _this->quality); u_entityAction(u_entity(ugroup), setKernelGroup, *group); u_entityFree(u_entity(ugroup)); result = D_STORE_RESULT_OK; } else { result = D_STORE_RESULT_OUT_OF_RESOURCES; d_storeReport(store, D_LEVEL_SEVERE, "Group %s.%s could NOT be created.\n", _this->partition, name); OS_REPORT_2(OS_ERROR, "d_groupInfoInject", (os_int32)result, "Group %s.%s could NOT be created.\n", _this->partition, name); } c_free(name); u_partitionFree(upartition); } else { result = D_STORE_RESULT_OUT_OF_RESOURCES; d_storeReport(store, D_LEVEL_SEVERE, "Partition %s could NOT be created.\n", _this->partition); OS_REPORT_1(OS_ERROR, "d_groupInfoInject", (os_int32)result, "Partition %s could NOT be created.\n", _this->partition); } u_partitionQosFree(partitionQos); } else { result = D_STORE_RESULT_OUT_OF_RESOURCES; d_storeReport(store, D_LEVEL_SEVERE, "PartitionQos could NOT be created.\n"); OS_REPORT(OS_ERROR, "d_groupInfoInject", (os_int32)result, "PartitionQos could NOT be created.\n"); } } } else { result = D_STORE_RESULT_ILL_PARAM; } return result; }
void d_groupRemoteListenerAction( d_listener listener, d_message message) { d_newGroup remote; d_configuration config; d_durability durability; d_admin admin; d_group group, group2; d_fellow fellow; c_bool createLocally, added; v_duration duration; u_group ugroup; d_networkAddress addr; c_bool result; d_subscriber subscriber; d_sampleChainListener sampleChainListener; d_completeness localCompleteness; assert(d_listenerIsValid(d_listener(listener), D_GROUP_REMOTE_LISTENER)); remote = d_newGroup(message); admin = d_listenerGetAdmin(listener); durability = d_adminGetDurability(admin); config = d_durabilityGetConfiguration(durability); addr = d_networkAddressNew(message->senderAddress.systemId, message->senderAddress.localId, message->senderAddress.lifecycleId); fellow = d_adminGetFellow(admin, addr); if(remote->partition && remote->topic){ d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_GROUP_REMOTE_LISTENER, "Received remote group '%s.%s'.\n", remote->partition, remote->topic); } if(fellow){ if(d_fellowGetCommunicationState(fellow) == D_COMMUNICATION_STATE_APPROVED){ if(!(remote->partition) && !(remote->topic)){ d_fellowSetExpectedGroupCount(fellow, remote->alignerCount); } else { group = d_adminGetLocalGroup(admin, remote->partition, remote->topic, remote->durabilityKind); if(!group){ d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_REMOTE_LISTENER, "Received remote group %s.%s which is locally unknown.\n", remote->partition, remote->topic); /* Group unknown locally, check if it is in the alignee namespace. */ createLocally = d_adminGroupInAligneeNS( admin, remote->partition, remote->topic, remote->durabilityKind); if(createLocally == TRUE){ group = d_groupNew(remote->partition, remote->topic, remote->durabilityKind, remote->completeness, remote->quality); added = d_fellowAddGroup(fellow, group); d_fellowSetExpectedGroupCount(fellow, remote->alignerCount); if(added == FALSE){ d_groupFree(group); group = d_fellowGetGroup(fellow, remote->partition, remote->topic, remote->durabilityKind); if(group){ d_groupUpdate(group, remote->completeness, remote->quality); d_groupFree(group); } } /* Group unknown locally, check if it should be aligned * initially. */ createLocally = d_adminGroupInInitialAligneeNS( admin, remote->partition, remote->topic, remote->durabilityKind); if(createLocally == TRUE){ d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group %s.%s in initial alignee namespace.\n", remote->partition, remote->topic); duration.seconds = 0; duration.nanoseconds = 10000000; ugroup = u_groupNew( u_participant(d_durabilityGetService(durability)), remote->partition, remote->topic, duration); if(ugroup){ d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group %s.%s with quality %d created locally.\n", remote->partition, remote->topic, remote->quality.seconds); u_entityFree(u_entity(ugroup)); } else { d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group %s.%s with quality %d could NOT be created locally.\n", remote->partition, remote->topic, remote->quality.seconds); /** * TODO: quality must not be taken over * from remote. */ group2 = d_groupNew(remote->partition, remote->topic, remote->durabilityKind, D_GROUP_INCOMPLETE, remote->quality); result = d_groupCreationQueueAdd( d_groupRemoteListener(listener)->groupCreationQueue, group2); if(result == FALSE){ d_printTimedEvent(durability, D_LEVEL_FINER, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group %s.%s already in creation queue. Skipping this one.\n", remote->partition, remote->topic); d_groupFree(group2); } } } else { d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group %s.%s in alignee namespace, but not initial.\n", remote->partition, remote->topic); } } else { d_printTimedEvent(durability, D_LEVEL_INFO, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group '%s.%s' is not in alignee namespace.\n", remote->partition, remote->topic); } } else { localCompleteness = d_groupGetCompleteness(group); group = d_fellowGetGroup(fellow, remote->partition, remote->topic, remote->durabilityKind); if(group){ d_groupUpdate(group, remote->completeness, remote->quality); d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_GROUP_REMOTE_LISTENER, "Updating remote group '%s.%s' completeness: '%d'.\n", remote->partition, remote->topic, remote->completeness); d_groupFree(group); } else if(localCompleteness != D_GROUP_COMPLETE){ group = d_groupNew(remote->partition, remote->topic, remote->durabilityKind, remote->completeness, remote->quality); added = d_fellowAddGroup(fellow, group); if(added == FALSE){ d_groupFree(group); group = d_fellowGetGroup(fellow, remote->partition, remote->topic, remote->durabilityKind); if(group){ d_groupUpdate(group, remote->completeness, remote->quality); d_groupFree(group); } } else { d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group '%s.%s' with completeness: '%d' registered for fellow.\n", remote->partition, remote->topic, remote->completeness); } } /* A complete group might be interesting in case there are * still unfullfilled chain requests. */ if(remote->completeness == D_GROUP_COMPLETE){ d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_GROUP_REMOTE_LISTENER, "Remote group '%s.%s' complete, check for unfullfilled chains.\n", remote->partition, remote->topic); subscriber = d_adminGetSubscriber(admin); sampleChainListener = d_subscriberGetSampleChainListener(subscriber); group = d_groupNew(remote->partition, remote->topic, remote->durabilityKind, remote->completeness, remote->quality); d_sampleChainListenerTryFulfillChains(sampleChainListener, group); d_groupFree(group); } } } } else { d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_GROUP_REMOTE_LISTENER, "Fellow not approved, so ignore the message.\n"); } d_fellowFree(fellow); } else { d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_GROUP_REMOTE_LISTENER, "Fellow unknown so far, so ignore the message.\n"); } d_networkAddressFree(addr); return; }