d_groupInfo d_groupInfoNew ( const d_storeMMFKernel kernel, const d_topicInfo topic, const d_group dgroup) { d_groupInfo group; c_base base; c_char* partition; c_type instanceType, groupInfoType; c_char *keyExpr; if(kernel && topic && dgroup){ base = c_getBase(kernel); groupInfoType = c_resolve(base,"durabilityModule2::d_groupInfo"); group = d_groupInfo(c_new(groupInfoType)); c_free(groupInfoType); if (group) { group->kernel = kernel; /* Unmanaged pointer */ group->topic = c_keep(topic); partition = d_groupGetPartition(dgroup); group->partition = c_stringNew(base, partition); os_free(partition); group->quality = d_groupGetQuality(dgroup); group->completeness = d_groupGetCompleteness(dgroup); instanceType = d_topicInfoGetInstanceType(topic); keyExpr = d_topicInfoGetInstanceKeyExpr(topic); group->instances = c_tableNew(instanceType, keyExpr); c_free(keyExpr); c_free(instanceType); } else { OS_REPORT(OS_ERROR, "d_groupInfoNew",0, "Failed to allocate d_groupInfo."); assert(FALSE); group = NULL; } } else { OS_REPORT(OS_ERROR, "d_groupInfoNew",0, "Illegal constructor parameter."); group = NULL; } return group; }
static c_bool checkCompleteness( d_group group, c_voidp args) { c_bool result; OS_UNUSED_ARG(args); assert(!args); if(d_groupGetCompleteness(group) == D_GROUP_COMPLETE){ result = TRUE; } else { result = FALSE; } return result; }
static void d_waitForCompletenessDCPSTopic( d_groupCreationQueue queue) { d_group dcpstopicGroup; d_completeness completeness; d_admin admin; os_time sleepTime; d_durability durability; sleepTime.tv_sec = 1; sleepTime.tv_nsec = 0; admin = queue->admin; durability = d_adminGetDurability(admin); d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_CREATION, "Waiting for group '%s.%s' to be created.\n", V_BUILTIN_PARTITION, V_TOPICINFO_NAME); do{ dcpstopicGroup = d_adminGetLocalGroup(admin, V_BUILTIN_PARTITION, V_TOPICINFO_NAME, D_DURABILITY_TRANSIENT); if((dcpstopicGroup == NULL) && (queue->terminate == FALSE)){ os_nanoSleep(sleepTime); } } while((dcpstopicGroup == NULL) && (queue->terminate == FALSE)); if(queue->terminate == FALSE){ d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_CREATION, "Group '%s.%s' is available. Waiting for completeness...\n", V_BUILTIN_PARTITION, V_TOPICINFO_NAME); } do{ if(dcpstopicGroup){ completeness = d_groupGetCompleteness(dcpstopicGroup); if((completeness != D_GROUP_COMPLETE) && (queue->terminate == FALSE)){ os_nanoSleep(sleepTime); } } else { completeness = D_GROUP_KNOWLEDGE_UNDEFINED; } } while((completeness != D_GROUP_COMPLETE) && (queue->terminate == FALSE)); if(queue->terminate == FALSE){ d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_CREATION, "Group '%s.%s' is complete now.\n", V_BUILTIN_PARTITION, V_TOPICINFO_NAME); } else { d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_GROUP_CREATION, "Not waiting for group '%s.%s', because termination is in progress.\n", V_BUILTIN_PARTITION, V_TOPICINFO_NAME); } return; }
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; }