Beispiel #1
0
static void*
d_waitsetEventHandler(
    void* userData)
{
    d_subscriber subscriber;
    d_durability durability;
    d_admin admin;
    c_iter events;
    d_waitsetEntity we;
    c_time time;
    d_waitsetHelper helper;
    u_waitset userWaitset;
    u_waitsetEvent event;
    u_result ur;

    helper           = d_waitsetHelper(userData);
    we               = helper->entity;
    subscriber       = d_waitsetGetSubscriber(helper->waitset);
    admin            = d_subscriberGetAdmin(subscriber);
    durability       = d_adminGetDurability(admin);
    time.seconds     = 1;
    time.nanoseconds = 0;
    userWaitset      = helper->userWaitset;
    ur               = U_RESULT_OK;

    while((helper->terminate == FALSE) && (ur == U_RESULT_OK)) {
        events = NULL;
        if(helper->waitset->timedWait == TRUE){
            ur = u_waitsetTimedWaitEvents(userWaitset, time,&events);
        } else {
            ur = u_waitsetWaitEvents(userWaitset,&events);
        }
        if(events  && (ur == U_RESULT_OK)){/* events may be null if waitset was deleted*/
            event = u_waitsetEvent(c_iterTakeFirst(events));

            while(event){
                /* Only dispatch event when durability is not terminating */
                if (d_durabilityGetState(durability) != D_STATE_TERMINATING){
                    we->action(we->dispatcher, event, we->usrData);
                }
                u_waitsetEventFree(event);
                event = u_waitsetEvent(c_iterTakeFirst(events));
            }
            c_iterFree(events);
        }
    }
    if(ur != U_RESULT_OK){
        d_printTimedEvent(durability, D_LEVEL_SEVERE,
            we->name,
            "Waitset no longer available (result: %d). Fatal error, terminating now...\n",
            ur);
        OS_REPORT_1(OS_ERROR, D_CONTEXT_DURABILITY, 0,
            "Waitset no longer available (result: %d). Fatal error, terminating now...\n",
            ur);
        d_durabilityTerminate(durability);
    }
    return NULL;
}
Beispiel #2
0
static void
nsInitialQualityWalk(
    d_nameSpace ns,
    void* userData)
{
    d_durability    durability;
    d_admin         admin;
    d_subscriber    subscriber;
    d_quality       quality;
    d_storeResult   result;
    c_ulong         i;

    subscriber = d_subscriber(((struct initialQualityWalkData*)userData)->subscriber);
    admin = subscriber->admin;
    durability = d_adminGetDurability(admin);
    i = ((struct initialQualityWalkData*)userData)->i;

     if( (d_nameSpaceGetDurabilityKind(ns) == D_DURABILITY_PERSISTENT) ||
         (d_nameSpaceGetDurabilityKind(ns) == D_DURABILITY_ALL))
     {
         result = d_storeGetQuality(subscriber->persistentStore, ns, &quality);

         if(result == D_STORE_RESULT_OK){
             d_nameSpaceSetInitialQuality(ns, quality);
             d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN,
              "Initial quality for nameSpace %d is %d.%u.\n",
              i, quality.seconds, quality.nanoseconds);
         } else {
              d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN,
              "Unable to get quality from persistent store for nameSpace %d.\n",
              i);
         }
     } else {
         d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN,
              "nameSpace %d does not hold persistent data.\n", i);
     }
     ((struct initialQualityWalkData*)userData)->i++;
}
Beispiel #3
0
void
d_reportLocalGroup(
    d_durability d,
    const char *threadName,
    v_group group)
{
    const c_char* durability;
    v_topicQos qos;

    if(group){
        qos = v_topicQosRef(group->topic);
        switch(qos->durability.kind){
            case V_DURABILITY_VOLATILE:
                durability = "VOLATILE";
                break;
            case V_DURABILITY_TRANSIENT_LOCAL:
                durability = "TRANSIENT LOCAL";
                break;
            case V_DURABILITY_TRANSIENT:
                durability = "TRANSIENT";
                break;
            case V_DURABILITY_PERSISTENT:
                durability = "PERSISTENT";
                break;
            default:
                durability = "<<UNKNOWN>>";
                assert(FALSE);
                break;
        }
    } else {
        durability = "<<UNKNOWN>>";
        assert(FALSE);
    }
    d_printTimedEvent(d, D_LEVEL_FINE,
                      threadName, "Group found: %s.%s (%s)\n",
                      v_partitionName(v_groupPartition(group)),
                      v_topicName(v_groupTopic(group)),
                      durability);
}
void
d_nameSpacesRequestListenerAction(
    d_listener listener,
    d_message message)
{
    d_durability durability;
    d_admin admin;
    d_fellow fellow;
    d_publisher publisher;
    c_ulong i, count;
    d_nameSpaces ns;
    d_networkAddress addr;
    d_nameSpacesRequest request;
    c_bool added;
    c_iter nameSpaces;

    assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_REQ_LISTENER));

    admin      = d_listenerGetAdmin(listener);
    durability = d_adminGetDurability(admin);
    addr       = d_networkAddressNew(message->senderAddress.systemId,
                                     message->senderAddress.localId,
                                     message->senderAddress.lifecycleId);
    fellow     = d_adminGetFellow(admin, addr);
    publisher  = d_adminGetPublisher(admin);

    d_printTimedEvent(durability, D_LEVEL_FINE,
            D_THREAD_NAMESPACES_REQUEST_LISTENER,
            "Received nameSpacesRequest from fellow %d.\n",
            message->senderAddress.systemId);

    /* Update nameSpaces list for listener */
    nameSpaces = updateNameSpaces(d_nameSpacesRequestListener(listener));

    if(!fellow){
        fellow = d_fellowNew(addr, message->senderState);
        d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());
        added = d_adminAddFellow(admin, fellow);

        if(added == FALSE){
            d_fellowFree(fellow);
            fellow = d_adminGetFellow(admin, addr);
            assert(fellow);
        } else {
            fellow = d_adminGetFellow(admin, addr);
            d_printTimedEvent(durability, D_LEVEL_FINE,
                D_THREAD_NAMESPACES_REQUEST_LISTENER,
                "Fellow %d unknown, added to administration and requesting nameSpaces.\n",
                message->senderAddress.systemId);
            request = d_nameSpacesRequestNew(admin);
            d_messageSetAddressee(d_message(request), addr);
            d_publisherNameSpacesRequestWrite(publisher, request, addr);
            d_nameSpacesRequestFree(request);
        }
    }
    d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());

    count = c_iterLength(nameSpaces);

    for(i=0; i<count; i++){
        ns = d_nameSpaces(c_iterObject(nameSpaces, i));
        d_messageInit(d_message(ns), admin);
        d_messageSetAddressee(d_message(ns), addr);
        d_publisherNameSpacesWrite(publisher, ns, addr);
    }
    cleanNameSpaces (nameSpaces);
    d_fellowFree(fellow);
    d_networkAddressFree(addr);

    return;
}
Beispiel #5
0
c_bool
d_publisherDeleteDataWrite(
    d_publisher publisher,
    d_deleteData message,
    d_networkAddress addressee)
{
    c_bool result;
    u_result ur;
    int resendCount;
    c_bool terminate;
    d_durability durability;

    OS_UNUSED_ARG(addressee);
    result = FALSE;
    assert(d_objectIsValid(d_object(publisher), D_PUBLISHER) == TRUE);

    if(publisher){
        if(publisher->enabled == TRUE){
            terminate = FALSE;
            resendCount = 0;
            durability = d_adminGetDurability(publisher->admin);
            d_publisherInitMessage(publisher, d_message(message));
            d_message(message)->sequenceNumber = publisher->deleteDataNumber++;

            while((!result) && (!terminate)){
                ur = u_writerWrite(publisher->deleteDataWriter,
                                   message, v_timeGet(), U_INSTANCEHANDLE_NIL);

                if(ur == U_RESULT_OK){
                    result = TRUE;
                } else if(ur == U_RESULT_TIMEOUT) {
                    terminate = d_durabilityMustTerminate(durability);
                    resendCount++;

                    if(terminate){
                        d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Failed to resend d_deleteData message, because durability is terminating.\n");
                        OS_REPORT(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                            "Failed to send d_deleteData message, because durability is terminating.");
                    } else if((resendCount == 1) || ((resendCount % 5) == 0)){
                        d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_UNSPECIFIED,
                            "Already tried to resend d_deleteData message '%d' times.\n", resendCount);

                        if(resendCount != 1){
                            OS_REPORT_1(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                                    "Already tried to resend d_deleteData message '%d' times.",
                                    resendCount);
                        }
                    }
                } else {
                    d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Write of d_deleteData message FAILED with result %d.\n", ur);
                    OS_REPORT_1(OS_ERROR, D_CONTEXT_DURABILITY, 0,
                            "Write of d_deleteData message FAILED with result %d.", ur);
                    d_durabilityTerminate(durability, TRUE);
                    terminate = d_durabilityMustTerminate(durability);
                }
            }
        }
    }
    return result;
}
Beispiel #6
0
c_bool
d_publisherStatusWrite(
    d_publisher publisher,
    d_status message,
    d_networkAddress addressee)
{
    c_bool result;
    u_result ur;
    int resendCount;
    c_bool terminate;
    d_durability durability;

    OS_UNUSED_ARG(addressee);
    result = FALSE;
    assert(d_objectIsValid(d_object(publisher), D_PUBLISHER) == TRUE);

    if(publisher){
        if(publisher->enabled == TRUE){
            terminate = FALSE;
            resendCount = 0;
            durability = d_adminGetDurability(publisher->admin);
            d_publisherInitMessage(publisher, d_message(message));
            d_message(message)->sequenceNumber = publisher->statusNumber++;

            while((!result) && (!terminate)){
                ur = u_writerWrite(publisher->statusWriter,
                                   message,
                                   v_timeGet(),
                                   U_INSTANCEHANDLE_NIL);

                if(ur == U_RESULT_OK){
                    result = TRUE;
                } else if(ur == U_RESULT_TIMEOUT) {
                    terminate = d_durabilityMustTerminate(durability);
                    if(!terminate && d_message(message)->senderState == D_STATE_TERMINATING){
                        /* ES 21 - okt - 2011:
                         * if durability is not yet terminating, but the message being written
                         * does indicate that termination of durability is imminent, then we have
                         * to prevent durability from constantly retrying in the case of a TIMEOUT
                         * of the datawriter. The standard timeout provided to the write will ensure
                         * the write is tried during the period of the timeout. But once that timeout is
                         * exceeded then it is fruitless to continue try to write the terminating message
                         * Without this specific code, durability will hang when terminating is caused
                         * by splice daemon terminating.
                         */
                        terminate = TRUE;
                    }
                    resendCount++;

                    if(terminate){
                        d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Failed to resend d_status message, because durability is terminating.\n");
                        OS_REPORT(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                            "Failed to send d_status message, because durability is terminating.");
                    }  else if((resendCount == 1) || ((resendCount % 5) == 0)){
                        d_printTimedEvent(durability, D_LEVEL_WARNING, D_THREAD_UNSPECIFIED,
                            "Already tried to resend d_status message '%d' times.\n", resendCount);

                        if(resendCount != 1){
                            OS_REPORT_1(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                                    "Already tried to resend d_status message '%d' times.",
                                    resendCount);
                        }
                    }
                } else {
                    d_printTimedEvent(durability, D_LEVEL_SEVERE, D_THREAD_UNSPECIFIED,
                            "Write of d_status message FAILED with result %d.\n", ur);
                    OS_REPORT_1(OS_ERROR, D_CONTEXT_DURABILITY, 0,
                            "Write of d_status message FAILED with result %d.", ur);
                    d_durabilityTerminate(durability, TRUE);
                    terminate = d_durabilityMustTerminate(durability);
                }
            }
        }
    }
    return result;
}
Beispiel #7
0
void
d_publisherDeinit(
    d_object object)
{
    d_publisher publisher;
    d_durability durability;

    assert(d_objectIsValid(object, D_PUBLISHER) == TRUE);

    if(object){
        publisher = d_publisher(object);
        durability = d_adminGetDurability(publisher->admin);

        if(publisher->statusWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying status writer\n");
            u_writerFree(publisher->statusWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "status writer destroyed\n");
            publisher->statusWriter = NULL;
        }
        if(publisher->newGroupWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying newGroup writer\n");
            u_writerFree(publisher->newGroupWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "newGroup writer destroyed\n");
            publisher->newGroupWriter = NULL;
        }
        if(publisher->groupsRequestWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying groupsRequest writer\n");
            u_writerFree(publisher->groupsRequestWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "groupsRequest writer destroyed\n");
            publisher->groupsRequestWriter = NULL;
        }
        if(publisher->statusRequestWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying statusRequest writer\n");
            u_writerFree(publisher->statusRequestWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "statusRequest writer destroyed\n");
            publisher->statusRequestWriter = NULL;
        }
        if(publisher->sampleChainWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying sampleChain writer\n");
            u_writerFree(publisher->sampleChainWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "sampleChain writer destroyed\n");
            publisher->sampleChainWriter = NULL;
        }
        if(publisher->nameSpacesWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying nameSpaces writer\n");
            u_writerFree(publisher->nameSpacesWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "nameSpaces writer destroyed\n");
            publisher->nameSpacesWriter = NULL;
        }
        if(publisher->nameSpacesRequestWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying nameSpacesRequest writer\n");
            u_writerFree(publisher->nameSpacesRequestWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "nameSpacesRequest writer destroyed\n");
            publisher->nameSpacesRequestWriter = NULL;
        }
        if(publisher->deleteDataWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying deleteData writer\n");
            u_writerFree(publisher->deleteDataWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "deleteData writer destroyed\n");
            publisher->deleteDataWriter = NULL;
        }
        if(publisher->sampleRequestWriter){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying sampleRequest writer\n");
            u_writerFree(publisher->sampleRequestWriter);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "sampleRequest writer destroyed\n");
            publisher->sampleRequestWriter = NULL;
        }
        if(publisher->publisher){
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "destroying user publisher\n");
            u_publisherFree(publisher->publisher);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "user publisher destroyed\n");
            publisher->publisher = NULL;
        }
    }
}
void
d_nameSpacesListenerAction(
    d_listener listener,
    d_message message)
{
    d_durability durability;
    d_admin admin;
    d_publisher publisher;
    d_fellow fellow;
    c_bool allowed;
    d_nameSpace nameSpace, localNameSpace, oldFellowNameSpace;
    c_ulong count;
    d_configuration config;
    d_nameSpacesRequest nsRequest;
    d_networkAddress sender;
    d_subscriber subscriber;
    d_sampleChainListener sampleChainListener;
    struct compatibilityHelper helper;
    d_adminStatisticsInfo info;
    c_bool added;
    os_time srcTime , curTime, difTime, maxDifTime;
    struct checkFellowMasterHelper fellowMasterHelper;
    d_name role;
    c_iter fellowNameSpaces;
    d_nameSpace ns;

    assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_LISTENER));

    admin               = d_listenerGetAdmin(listener);
    publisher           = d_adminGetPublisher(admin);
    durability          = d_adminGetDurability(admin);
    config              = d_durabilityGetConfiguration(durability);
    fellowNameSpaces    = NULL;

    d_printTimedEvent         (durability, D_LEVEL_FINE,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Received nameSpace from fellow %d (his master: %d, confirmed: %d, mergeState: %s, %d).\n",
                               message->senderAddress.systemId,
                               d_nameSpaces(message)->master.systemId,
                               d_nameSpaces(message)->masterConfirmed,
                               d_nameSpaces(message)->state.role,
                               d_nameSpaces(message)->state.value);

    sender = d_networkAddressNew(message->senderAddress.systemId,
                               message->senderAddress.localId,
                               message->senderAddress.lifecycleId);

    fellow = d_adminGetFellow(admin, sender);

    if(!fellow){
        d_printTimedEvent (durability, D_LEVEL_FINE,
                           D_THREAD_NAMESPACES_LISTENER,
                           "Fellow %d unknown, administrating it.\n",
                           message->senderAddress.systemId);
        fellow = d_fellowNew(sender, message->senderState);
        d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());
        added = d_adminAddFellow(admin, fellow);

        if(added == FALSE){
            d_fellowFree(fellow);
            fellow = d_adminGetFellow(admin, sender);
            assert(fellow);
        } else {
            fellow = d_adminGetFellow(admin, sender); /*Do this to allow fellowFree at the end*/
            nsRequest = d_nameSpacesRequestNew(admin);
            d_messageSetAddressee(d_message(nsRequest), sender);
            d_publisherNameSpacesRequestWrite(publisher, nsRequest, sender);
            d_nameSpacesRequestFree(nsRequest);
        }
    }
    d_fellowUpdateStatus(fellow, message->senderState, v_timeGet());

    nameSpace = d_nameSpaceFromNameSpaces(config, d_nameSpaces(message));

    if(d_fellowGetCommunicationState(fellow) == D_COMMUNICATION_STATE_APPROVED){

        /* Get old namespace of fellow */
        oldFellowNameSpace = d_nameSpaceCopy (d_fellowGetNameSpace (fellow, nameSpace));

        /* Update master of fellow nameSpace */
        added = d_fellowAddNameSpace(fellow, nameSpace);

        /* Create namespace with local policy (if a match exists) */
        localNameSpace = d_nameSpaceNew (config, d_nameSpaceGetName(nameSpace));

        /* If namespace is created, add to administration */
        if (localNameSpace) {
            /* Copy partitions to local nameSpace */
            d_nameSpaceCopyPartitions (localNameSpace, nameSpace);
            d_adminAddNameSpace (admin, localNameSpace);
            d_nameSpaceFree (localNameSpace);
        }

        /* If fellow is master for a namespace, report it to admin */
        fellowMasterHelper.admin = admin;
        fellowMasterHelper.fellow = d_fellowGetAddress(fellow);
        fellowMasterHelper.oldNameSpace = oldFellowNameSpace;
        checkFellowMasterWalk (nameSpace, &fellowMasterHelper);
        d_free (fellowMasterHelper.fellow);

        /* If the namespace was not added to the fellow (because it already existed there), free it */
        if(!added){
            d_nameSpaceFree(nameSpace);
        }

        d_nameSpaceFree (oldFellowNameSpace);

    } else {
        info = d_adminStatisticsInfoNew();
        d_fellowSetExpectedNameSpaces(fellow, d_nameSpaces(message)->total);
        d_fellowAddNameSpace(fellow, nameSpace);
        count = d_fellowNameSpaceCount(fellow);

        if(count == d_nameSpaces(message)->total){
            allowed = isFellowStateCompatible(durability, fellow);

            if(allowed == TRUE){
                config = d_durabilityGetConfiguration(durability);
                helper.fellow = fellow;
                helper.compatible = TRUE;

                d_adminNameSpaceWalk (admin, areFellowNameSpacesCompatible, &helper);

                if(helper.compatible == TRUE){

                    if(config->timeAlignment == TRUE){
                        curTime.tv_sec     = d_readerListener(listener)->lastInsertTime.seconds;
                        curTime.tv_nsec    = d_readerListener(listener)->lastInsertTime.nanoseconds;
                        srcTime.tv_sec     = d_readerListener(listener)->lastSourceTime.seconds;
                        srcTime.tv_nsec    = d_readerListener(listener)->lastSourceTime.nanoseconds;
                        maxDifTime.tv_sec  = 1; /*1s*/
                        maxDifTime.tv_nsec = 0;
                        difTime            = os_timeAbs(os_timeSub(curTime, srcTime));

                        if(os_timeCompare(difTime, maxDifTime) == OS_MORE){
                            d_printTimedEvent (durability, D_LEVEL_WARNING,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Estimated time difference including latency with " \
                               "fellow %d is %f seconds, which is larger then " \
                               "expected.\n",
                               message->senderAddress.systemId,
                               os_timeToReal(difTime));
                            OS_REPORT_2(OS_WARNING, D_CONTEXT, 0,
                                "Estimated time difference including latency " \
                                "with fellow '%d' is larger then expected " \
                                "(%f seconds). Durability alignment might not be " \
                                "reliable. Please align time between these nodes " \
                                "and restart.",
                                message->senderAddress.systemId,
                                os_timeToReal(difTime));
                        } else {
                            d_printTimedEvent (durability, D_LEVEL_FINER,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Estimated time difference including latency with " \
                               "fellow %d is %f seconds.\n",
                               message->senderAddress.systemId,
                               os_timeToReal(difTime));
                        }
                    }

                    /* Set role of fellow (take native role from namespace) */
                    role = d_nameSpaceGetRole(nameSpace);
                    d_fellowSetRole (fellow, role);
                    os_free (role);

                    d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_APPROVED);
                    info->fellowsApprovedDif += 1;
                    subscriber = d_adminGetSubscriber(admin);
                    sampleChainListener = d_subscriberGetSampleChainListener(subscriber);

                    if(sampleChainListener){
                        d_sampleChainListenerTryFulfillChains(sampleChainListener, NULL);
                    }

                    /* Check if the fellow is master for one or more namespaces and report this to admin */
                    fellowNameSpaces = c_iterNew(NULL);

                    /* Collect fellow namespaces */
                    d_fellowNameSpaceWalk (fellow, collectFellowNsWalk, fellowNameSpaces);

                    fellowMasterHelper.admin = admin;
                    fellowMasterHelper.fellow = d_fellowGetAddress(fellow);
                    fellowMasterHelper.oldNameSpace = NULL;
                    c_iterWalk (fellowNameSpaces, checkFellowMasterWalk, &fellowMasterHelper);

                    while ((ns = c_iterTakeFirst(fellowNameSpaces))) {
                        d_nameSpaceFree(ns);
                    }
                    c_iterFree(fellowNameSpaces);

                    d_free (fellowMasterHelper.fellow);

                } else {
                    info->fellowsIncompatibleDataModelDif += 1;

                    d_printTimedEvent (durability, D_LEVEL_WARNING,
                                   D_THREAD_NAMESPACES_LISTENER,
                                   "Communication with fellow %d NOT approved, because data model is not compatible\n",
                                   message->senderAddress.systemId);
                    d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_INCOMPATIBLE_DATA_MODEL);
                }
            } else {
                info->fellowsIncompatibleStateDif += 1;
                d_printTimedEvent (durability, D_LEVEL_WARNING,
                                   D_THREAD_NAMESPACES_LISTENER,
                                   "Communication with fellow %d NOT approved, because state is not compatible my state: %d, fellow state: %d\n",
                                   message->senderAddress.systemId,
                                   d_durabilityGetState(durability),
                                   message->senderState);
                d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_INCOMPATIBLE_STATE);
            }
        } else {
            d_printTimedEvent (durability, D_LEVEL_WARNING,
                               D_THREAD_NAMESPACES_LISTENER,
                               "Received %u of %u nameSpaces from fellow %u.\n",
                               count, d_nameSpaces(message)->total,
                               message->senderAddress.systemId);
        }
        d_adminUpdateStatistics(admin, info);
        d_adminStatisticsInfoFree(info);
    }
    d_fellowFree(fellow);
    d_networkAddressFree(sender);

    return;
}
static void*
d_groupCreationQueueRun(
    void* userData)
{
    d_groupCreationQueue queue;
    c_iter groupsToCreate, reinsert;
    d_group group, localGroup;
    d_durability durability;
    d_durabilityKind kind;
    u_participant uservice;
    c_char *partition, *topic;
    v_duration duration;
    u_group ugroup;
    c_long creationCountVolatile, creationCountTransient, creationCountPersistent;
    c_ulong maxBurst;
    os_time sleepTime, maxBurstSleepTime;
    c_bool update;

    sleepTime.tv_sec          = 1;
    sleepTime.tv_nsec         = 0;
    duration.seconds          = 0;
    duration.nanoseconds      = 5000000; /*5ms*/
    creationCountVolatile     = 0;
    creationCountTransient    = 0;
    creationCountPersistent   = 0;
    maxBurstSleepTime.tv_sec  = 0;
    maxBurstSleepTime.tv_nsec = 10000000; /*10ms*/

    queue                = d_groupCreationQueue(userData);
    groupsToCreate       = c_iterNew(NULL);
    reinsert             = c_iterNew(NULL);
    durability           = d_adminGetDurability(queue->admin);
    uservice             = u_participant(d_durabilityGetService(durability));

    d_waitForCompletenessDCPSTopic(queue);

    while(queue->terminate == FALSE) {
        d_lockLock(d_lock(queue));

        queue->groupsToCreateVolatile -= creationCountVolatile;
        assert(queue->groupsToCreateVolatile >= 0);
        queue->groupsToCreateTransient -= creationCountTransient;
        assert(queue->groupsToCreateTransient >= 0);
        queue->groupsToCreatePersistent -= creationCountPersistent;
        assert(queue->groupsToCreatePersistent >= 0);

        group = d_group(c_iterTakeFirst(queue->groups));

        while(group){
            groupsToCreate = c_iterInsert(groupsToCreate, group);
            group = d_group(c_iterTakeFirst(queue->groups));
        }
        assert((queue->groupsToCreateVolatile +
                queue->groupsToCreateTransient +
                queue->groupsToCreatePersistent) ==
               c_iterLength(groupsToCreate));

        durability = d_adminGetDurability(queue->admin);
        d_durabilityUpdateStatistics(durability, d_statisticsUpdateGroupsToCreate, queue);

        d_lockUnlock(d_lock(queue));

        creationCountVolatile   = 0;
        creationCountTransient  = 0;
        creationCountPersistent = 0;
        maxBurst                = 10;

        group = c_iterTakeFirst(groupsToCreate);

        while(group && (queue->terminate == FALSE)){
            partition  = d_groupGetPartition(group);
            topic      = d_groupGetTopic(group);
            kind       = d_groupGetKind(group);
            localGroup = d_adminGetLocalGroup(queue->admin, partition, topic, kind);
            update     = FALSE;

            if(localGroup) {
                d_printTimedEvent(durability,
                            D_LEVEL_FINE,
                            D_THREAD_GROUP_CREATION,
                            "Remote group %s.%s has already been created locally.\n",
                            partition, topic);
                update = TRUE;
            } else {
                ugroup = u_groupNew(uservice, partition, topic, duration);

                if(ugroup){
                    d_printTimedEvent(durability,
                                    D_LEVEL_FINE,
                                    D_THREAD_GROUP_CREATION,
                                    "Remote group %s.%s created locally.\n",
                                    partition, topic);
                    update = TRUE;
                    u_entityFree(u_entity(ugroup));
                    maxBurst--;

                    if(maxBurst == 0){
                        os_nanoSleep(maxBurstSleepTime);
                        maxBurst = 10;
                    }
                } else {
                    maxBurst++;
                    d_printTimedEvent(durability, D_LEVEL_FINE,
                                D_THREAD_GROUP_CREATION,
                                "Remote group %s.%s could not be created locally.\n",
                                partition, topic);

                    if(d_durabilityGetState(durability) == D_STATE_COMPLETE){
                        d_printTimedEvent(durability, D_LEVEL_FINE,
                                D_THREAD_GROUP_CREATION,
                                "I am complete so it will not be available anymore.\n");
                        update = TRUE;
                    } else if(d_adminGetFellowCount(queue->admin) == 0){
                        d_printTimedEvent(durability, D_LEVEL_WARNING,
                                D_THREAD_GROUP_CREATION,
                                "No fellows available to provide me with group information. " \
                                "Ignoring group.\n",
                                partition, topic);
                        update = TRUE;
                    } else {
                        reinsert = c_iterInsert(reinsert, group);
                    }
                }
            }
            if(update){
                switch(d_groupGetKind(group)){
                case D_DURABILITY_VOLATILE:
                    creationCountVolatile++;
                    break;
                case D_DURABILITY_TRANSIENT:
                case D_DURABILITY_TRANSIENT_LOCAL:
                    creationCountTransient++;
                    break;
                case D_DURABILITY_PERSISTENT:
                    creationCountPersistent++;
                    break;
                default:
                    assert(FALSE);
                    break;
                }
                d_groupFree(group);
            }
            os_free(partition);
            os_free(topic);
            group = c_iterTakeFirst(groupsToCreate);
        }
        group = d_group(c_iterTakeFirst(reinsert));

        while(group){
            groupsToCreate = c_iterInsert(groupsToCreate, group);
            group = d_group(c_iterTakeFirst(reinsert));
        }
        if(queue->terminate == FALSE){
            os_nanoSleep(sleepTime);
        }
    }

    group = d_group(c_iterTakeFirst(groupsToCreate));

    while(group) {
        d_groupFree(group);
        group = d_group(c_iterTakeFirst(groupsToCreate));
    }
    c_iterFree(groupsToCreate);
    c_iterFree(reinsert);

    d_lockLock(d_lock(queue));
    group = d_group(c_iterTakeFirst(queue->groups));

    while(group) {
        d_groupFree(group);
        group = d_group(c_iterTakeFirst(queue->groups));
    }
    d_lockUnlock(d_lock(queue));

    return NULL;
}
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;
}
Beispiel #11
0
static c_char*
getPersistentPartitionExpression(
    d_admin admin,
    d_durability durability)
{
    c_char *result, *expr;
    d_nameSpace ns;
    d_durabilityKind dkind;
    c_ulong length;
    c_long i, j;
    c_iter nameSpaces;

    result = NULL;

    assert (admin);

    /* Collect namespaces */
    nameSpaces = d_adminNameSpaceCollect(admin);

    if(admin){
        length = 0;
        j = 0;

        for(i=0; i<c_iterLength(nameSpaces); i++){
            ns    = d_nameSpace(c_iterObject(nameSpaces, i));
            dkind = d_nameSpaceGetDurabilityKind(ns);

            if((dkind == D_DURABILITY_PERSISTENT) || (dkind == D_DURABILITY_ALL)){
                expr = d_nameSpaceGetPartitions(ns);
                if(j==0){
                    length += strlen(expr);
                } else {
                    length += strlen(expr) + 1; /*for the comma*/
                }
                os_free(expr);
                j++;
            }
        }

        if(length > 0){
            result = (c_char*)(os_malloc(length + 1));
            result[0] = '\0';
            j = 0;

            for(i=0; i<c_iterLength(nameSpaces); i++){
                ns    = d_nameSpace(c_iterObject(nameSpaces, i));
                dkind = d_nameSpaceGetDurabilityKind(ns);

                if((dkind == D_DURABILITY_PERSISTENT) || (dkind == D_DURABILITY_ALL)){
                    expr = d_nameSpaceGetPartitions(ns);

                    if(j != 0){
                        os_strcat(result, ",");
                    }
                    os_strcat(result, expr);
                    os_free(expr);
                    j++;
                }
            }
        }

        d_adminNameSpaceCollectFree(admin, nameSpaces);
    }

    if(result){
        d_printTimedEvent(durability, D_LEVEL_FINE,
            D_THREAD_PERISTENT_DATA_LISTENER,
            "Persistent partition expression is: '%s'\n", result);
    } else {
        d_printTimedEvent(durability, D_LEVEL_FINE,
            D_THREAD_PERISTENT_DATA_LISTENER,
            "Persistent partition expression is empty.\n");
    }
    return result;
}
Beispiel #12
0
void
d_subscriberDeinit(
    d_object object)
{
    d_subscriber subscriber;
    d_durability durability;

    assert(d_objectIsValid(object, D_SUBSCRIBER) == TRUE);

    if(object){
        subscriber = d_subscriber(object);
        durability = d_adminGetDurability(subscriber->admin);

        if(subscriber->statusListener){
            d_statusListenerFree(subscriber->statusListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "statusListener freed\n");
            subscriber->statusListener = NULL;
        }
        if(subscriber->groupLocalListener){
            if(subscriber->sampleChainListener){
                d_sampleChainListenerStop(subscriber->sampleChainListener);
            }
            d_groupLocalListenerFree(subscriber->groupLocalListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "groupLocalListener freed\n");
            subscriber->groupLocalListener = NULL;
        }
        if(subscriber->groupRemoteListener){
            d_groupRemoteListenerFree(subscriber->groupRemoteListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "groupRemoteListener freed\n");
            subscriber->groupRemoteListener = NULL;
        }
        if(subscriber->groupsRequestListener){
            d_groupsRequestListenerFree(subscriber->groupsRequestListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "groupsRequestListener freed\n");
            subscriber->groupsRequestListener = NULL;
        }
       if(subscriber->sampleRequestListener){
            d_sampleRequestListenerFree(subscriber->sampleRequestListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "sampleRequestListener freed\n");
            subscriber->sampleRequestListener = NULL;
        }
        if(subscriber->sampleChainListener){
            d_sampleChainListenerFree(subscriber->sampleChainListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "sampleChainListener freed\n");
            subscriber->sampleChainListener = NULL;
        }
        if(subscriber->nameSpacesRequestListener){
            d_nameSpacesRequestListenerFree(subscriber->nameSpacesRequestListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "nameSpacesRequestListener freed\n");
            subscriber->nameSpacesRequestListener = NULL;
        }
        if(subscriber->nameSpacesListener){
            d_nameSpacesListenerFree(subscriber->nameSpacesListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "nameSpacesListener freed\n");
            subscriber->nameSpacesListener = NULL;
        }
        if(subscriber->deleteDataListener){
            d_deleteDataListenerFree(subscriber->deleteDataListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "deleteDataListener freed\n");
            subscriber->deleteDataListener = NULL;
        }
        if(subscriber->persistentDataListener){
            d_persistentDataListenerFree(subscriber->persistentDataListener);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "persistentDataListener freed\n");
            subscriber->persistentDataListener = NULL;
        }
        if(subscriber->persistentStore){
            d_storeClose(subscriber->persistentStore);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "persistent store closed\n");
            subscriber->persistentStore = NULL;
        }
        if(subscriber->waitset) {
            d_waitsetFree(subscriber->waitset);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "waitset freed\n");
            subscriber->waitset = NULL;
        }
        if(subscriber->persistentSubscriber){
            u_subscriberFree(subscriber->persistentSubscriber);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "user persistent subscriber freed\n");
            subscriber->persistentSubscriber = NULL;
        }
        if(subscriber->subscriber){
            u_subscriberFree(subscriber->subscriber);
            d_printTimedEvent(durability, D_LEVEL_FINEST, D_THREAD_MAIN, "user subscriber freed\n");
            subscriber->subscriber = NULL;
        }
    }
}
Beispiel #13
0
d_subscriber
d_subscriberNew(
    d_admin admin)
{
    d_subscriber    subscriber;
    d_durability    durability;
    d_configuration config;
    v_subscriberQos subscriberQos, psubscriberQos;
    c_char*         partitionExpr;
    struct initialQualityWalkData walkData;
    d_storeResult       result;
    d_nameSpace         nameSpace;
    c_iter              nameSpaces;
    c_bool              nsComplete;
    d_durabilityKind    dkind;

    subscriber = NULL;

    if(admin){
        subscriber        = d_subscriber(os_malloc(C_SIZEOF(d_subscriber)));
        d_objectInit(d_object(subscriber), D_SUBSCRIBER, d_subscriberDeinit);

        subscriber->admin = admin;
        durability        = d_adminGetDurability(admin);
        config            = d_durabilityGetConfiguration(durability);
        subscriberQos     = d_subscriberQosNew(config->partitionName);
        partitionExpr     = getPersistentPartitionExpression(admin, durability);
        psubscriberQos    = d_subscriberQosNew(partitionExpr);

        os_free(partitionExpr);

        subscriber->subscriber = u_subscriberNew (u_participant(d_durabilityGetService(durability)),
                                                  config->subscriberName,
                                                  subscriberQos,
                                                  TRUE);

        subscriber->waitset         = d_waitsetNew(subscriber, FALSE, FALSE);
        subscriber->persistentStore = d_storeOpen(durability, config->persistentStoreMode);

        if(subscriber->persistentStore) {
            if(psubscriberQos->partition){

                /* Collect nameSpaces from admin. */
                nameSpaces = d_adminNameSpaceCollect(admin);

                /* Loop nameSpaces */
                while((nameSpace = c_iterTakeFirst(nameSpaces))) {
                    dkind = d_nameSpaceGetDurabilityKind(nameSpace);

                    /* Walk only over persistent nameSpaces */
                    if((dkind == D_DURABILITY_PERSISTENT) || (dkind == D_DURABILITY_ALL)){

                        /* If persistent nameSpace is not complete, restore backup */
                        result = d_storeNsIsComplete (subscriber->persistentStore, nameSpace, &nsComplete);
                        if ( (result == D_STORE_RESULT_OK) && !nsComplete)
                        {
                            /* Incomplete namespace, restore backup. */
                            d_printTimedEvent(durability, D_LEVEL_WARNING,
                                D_THREAD_GROUP_LOCAL_LISTENER,
                                "Namespace '%s' is incomplete, trying to restore backup.\n",
                                d_nameSpaceGetName(nameSpace));

                            if (d_storeRestoreBackup (subscriber->persistentStore, nameSpace) != D_STORE_RESULT_OK)
                            {
                                d_printTimedEvent(durability, D_LEVEL_WARNING,
                                    D_THREAD_GROUP_LOCAL_LISTENER,
                                    "Backup for namespace '%s' could not be restored as no complete backup did exist on disk. Marking namespace as incomplete and continuing.\n",
                                    d_nameSpaceGetName(nameSpace));

                                OS_REPORT_1(OS_WARNING, D_CONTEXT_DURABILITY, 0,
                                    "Backup for namespace '%s' could not be restored as no complete backup did exist on disk. Marking namespace as incomplete and continuing.\n",
                                    d_nameSpaceGetName (nameSpace));

                                /* If backup fails, mark master state for nameSpace !D_STATE_COMPLETE */
                                d_nameSpaceSetMasterState (nameSpace, D_STATE_INIT);
                            }
                        }
                    }
                    d_nameSpaceFree(nameSpace);
                }

                /* Free nameSpaces iterator */
                assert(c_iterLength(nameSpaces) == 0);
                c_iterFree(nameSpaces);

                subscriber->persistentSubscriber = u_subscriberNew(u_participant(d_durabilityGetService(durability)),
                                                                   config->subscriberName,
                                                                   psubscriberQos,
                                                                   TRUE);

                assert(subscriber->persistentSubscriber);
            } else {
                subscriber->persistentSubscriber = NULL;
            }

            walkData.subscriber = subscriber;
            walkData.i = 0;
            d_adminNameSpaceWalk(admin, nsInitialQualityWalk, &walkData);

        } else {
            subscriber->persistentSubscriber = NULL;
        }
        assert(subscriber->subscriber);

        if(subscriber->subscriber){
            subscriber->statusListener            = NULL;
            subscriber->groupLocalListener        = NULL;
            subscriber->groupRemoteListener       = NULL;
            subscriber->groupsRequestListener     = NULL;
            subscriber->sampleRequestListener     = NULL;
            subscriber->sampleChainListener       = NULL;
            subscriber->nameSpacesRequestListener = NULL;
            subscriber->nameSpacesListener        = NULL;
            subscriber->persistentDataListener    = NULL;
            subscriber->deleteDataListener        = NULL;
        } else {
            d_subscriberFree(subscriber);
            subscriber = NULL;
        }
        d_subscriberQosFree(subscriberQos);
        d_subscriberQosFree(psubscriberQos);
    }
    return subscriber;
}
Beispiel #14
0
void
d_statusListenerAction(
    d_listener listener,
    d_message message)
{
    d_admin admin;
    d_durability durability;
    d_fellow fellow, fellow2;
    d_networkAddress sender;
    d_timestamp receptionTime;
    c_time t;
    d_nameSpacesRequest request;
    d_publisher publisher;
    c_bool added;
    d_serviceState oldState;

    assert(d_listenerIsValid(d_listener(listener), D_STATUS_LISTENER));
    t = v_timeGet();

    receptionTime.seconds     = t.seconds;
    receptionTime.nanoseconds = t.nanoseconds;

    admin      = d_listenerGetAdmin(listener);
    durability = d_adminGetDurability(admin);
    publisher  = d_adminGetPublisher(admin);
    sender     = d_networkAddressNew(message->senderAddress.systemId,
                                     message->senderAddress.localId,
                                     message->senderAddress.lifecycleId);
    fellow     = d_adminGetFellow(admin, sender);

    if(!fellow){
        d_printTimedEvent (durability, D_LEVEL_FINE,
                           D_THREAD_STATUS_LISTENER,
                           "Fellow %d unknown, administrating it.\n",
                           message->senderAddress.systemId);
        fellow = d_fellowNew(sender, message->senderState);
        d_fellowUpdateStatus(fellow, message->senderState, receptionTime);
        added = d_adminAddFellow(admin, fellow);

        if(added == FALSE){
            d_fellowFree(fellow);
            fellow = d_adminGetFellow(admin, sender);
            d_fellowUpdateStatus(fellow, message->senderState, receptionTime);
            assert(fellow);
        } else {
            fellow = d_adminGetFellow(admin, sender); /* This allows free at the end in all cases */
            assert(fellow);
            request = d_nameSpacesRequestNew(admin);
            d_messageSetAddressee(d_message(request), sender);
            d_publisherNameSpacesRequestWrite(publisher, request, sender);
            d_nameSpacesRequestFree(request);
        }
        d_fellowFree(fellow);
    } else {
        /* Update fellow state, or remove if it terminates */
        switch(message->senderState){
            case D_STATE_TERMINATING:
            case D_STATE_TERMINATED:
                d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_TERMINATED);
                fellow2 = d_adminRemoveFellow(admin, fellow);
                d_fellowFree(fellow);

                if(fellow2){
                    d_fellowFree(fellow2);
                }
                d_printTimedEvent(durability, D_LEVEL_INFO, D_THREAD_STATUS_LISTENER, "Fellow removed from admin.\n");
                break;
            default:
                /* Update the state of the fellow */
                oldState = d_fellowGetState(fellow);

                if(oldState != message->senderState){
                    d_printTimedEvent (durability, D_LEVEL_FINE,
                               D_THREAD_STATUS_LISTENER,
                               "Updating state of fellow '%d' to '%s'.\n",
                               message->senderAddress.systemId, d_fellowStateText(message->senderState));
                }
                d_fellowUpdateStatus(fellow, message->senderState, receptionTime);
                d_fellowFree(fellow);
                break;
        }
    }
    d_networkAddressFree(sender);

    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;
}