Example #1
1
static void MAMACALLTYPE
dqPublisherImplMsgCb (mamaSubscription subsc,
                      mamaMsg          msg,
                      void*            closure,
                      void*            itemClosure)
{
    mama_i32_t                 msgType = 0;
    mama_i32_t                subType = 0;
    const char*                symbol    = NULL;
    mama_status             status  = MAMA_STATUS_NOT_FOUND;
    mamaPublishTopic*         info    = NULL;
    mamaDQPublisherManagerImpl* impl = (mamaDQPublisherManagerImpl*) (closure);


    if (mamaMsg_getI32 (msg, MamaFieldSubscriptionType.mName,
                        MamaFieldSubscriptionType.mFid, &subType) == MAMA_STATUS_OK)
    {
        if (mamaMsg_getString (msg, MamaFieldSubscSymbol.mName,
                               MamaFieldSubscSymbol.mFid, &symbol) != MAMA_STATUS_OK)
        {
            if (mamaMsg_getSendSubject (msg, &symbol) != MAMA_STATUS_OK)
            {
                impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl,
                                              status, "No symbol", msg);
                return;
            }
        }

        if (mamaMsg_getI32 (msg, MamaFieldSubscMsgType.mName,
                            MamaFieldSubscMsgType.mFid, &msgType) != MAMA_STATUS_OK)
        {
            impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl, status,
                                          "NO msg type", msg);
            return;
        }

        if ((info  = wtable_lookup (impl->mPublisherMap, (symbol))))
        {
            switch (msgType)
            {
            case MAMA_SUBSC_REFRESH:
                if (!impl->mRefreshResponseMsg)
                {
                    mamaMsg_create(&impl->mRefreshResponseMsg);
                    mamaMsg_addU8(impl->mRefreshResponseMsg, NULL,
                                  MamaFieldMsgStatus.mFid, MAMA_MSG_STATUS_MISC);
                    mamaMsg_addU8(impl->mRefreshResponseMsg, NULL,
                                  MamaFieldMsgType.mFid, MAMA_MSG_TYPE_REFRESH);

                }
                mamaDQPublisher_send(info->pub, impl->mRefreshResponseMsg);
                impl->mUserCallbacks.onRefresh((mamaDQPublisherManager)impl,
                                               info, subType, msgType, msg );
                break;

            default:
                impl->mUserCallbacks.onRequest ((mamaDQPublisherManager)impl,
                                                info, subType, msgType, msg);
                break;
            }
        }
        else
        {
            impl->mUserCallbacks.onNewRequest ((mamaDQPublisherManager)impl,
                                               symbol,
                                               subType,
                                               msgType,
                                               msg);
        }

    }
    else
    {
        if (impl->mUserCallbacks.onMsg)
            impl->mUserCallbacks.onMsg ((mamaDQPublisherManager)impl, msg);
    }
}
Example #2
0
mama_status mamaDQPublisherManager_addPublisher (
    mamaDQPublisherManager manager,
    const char *symbol,
    mamaDQPublisher pub,
    void * cache)
{
    mamaPublishTopic* newTopic = NULL;
    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;
    newTopic =  (mamaPublishTopic*) wtable_lookup  (impl->mPublisherMap, (char*)symbol);


    if (!newTopic)
    {
        newTopic =  (mamaPublishTopic*) calloc (1, sizeof (mamaPublishTopic));

        newTopic->pub = pub;
        newTopic->cache = cache;
        newTopic->symbol = strdup(symbol);

        if (wtable_insert  (impl->mPublisherMap, (char*)symbol, newTopic) != 1)
            return MAMA_STATUS_INVALID_ARG;
    }
    else
        return MAMA_STATUS_INVALID_ARG;

    return MAMA_STATUS_OK;
}
Example #3
0
mama_status mamaDQPublisherManager_createPublisher (
    mamaDQPublisherManager manager,
    const char *symbol,
    void * cache,
    mamaDQPublisher *newPublisher)
{
    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;
    mamaPublishTopic* newTopic = NULL;
    mama_status status = MAMA_STATUS_OK;
    char* topic;
    int length = 0;

    newTopic =  (mamaPublishTopic*)wtable_lookup (impl->mPublisherMap, (char*)symbol);

    if (!newTopic)
    {
        if ((status = mamaDQPublisher_allocate(newPublisher)) == MAMA_STATUS_OK)
        {
            newTopic =  (mamaPublishTopic*) calloc (1, sizeof (mamaPublishTopic));

            newTopic->pub = *newPublisher;
            newTopic->cache = cache;
            newTopic->symbol = strdup(symbol);

            mamaDQPublisher_setCache(*newPublisher, cache);
            mamaDQPublisher_setSenderId(*newPublisher,  impl->mSenderId);
            mamaDQPublisher_setStatus(*newPublisher,  impl->mStatus);
            mamaDQPublisher_setSeqNum(*newPublisher, impl->mSeqNum);
            mamaDQPublisher_enableSendTime(*newPublisher, impl->mEnableSendTime);

            length = strlen(impl->mNameSpace) + 1 + (strlen(symbol) + 1);
            topic = calloc(length, sizeof(char));
            strcpy (topic, impl->mNameSpace);
            strcat (topic, ".");
            strcat (topic, symbol);

            if ((status = mamaDQPublisher_create(*newPublisher,
                                                 impl->mTransport, topic)) != MAMA_STATUS_OK)
            {
                free (topic);
                return status;
            }
            free (topic);

            if (wtable_insert  (impl->mPublisherMap, (char*)symbol, newTopic) != 1)
            {
                mamaDQPublisher_destroy(*newPublisher);
                free  ((void*)newTopic->symbol);
                free  ((void*)newTopic);
                return status;
            }
            return MAMA_STATUS_OK;
        }
        return status;
    }

    return (MAMA_STATUS_INVALID_ARG);
}
Example #4
0
 MamaSubscription* MamaSource::findSubscription (const char*  symbol)
 {
     if (mySubs)
     {
         return (MamaSubscription*) wtable_lookup (mySubs, symbol);
     }
     else if (myParent)
     {
         return myParent->findSubscription (symbol);
     }
     else
     {
         return NULL;
     }
 }
Example #5
0
mama_status mamaDQPublisherManager_destroyPublisher (
    mamaDQPublisherManager
    manager,
    const char *symbol)
{
    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;
    mamaPublishTopic* newTopic = NULL;

    if (!(newTopic =  wtable_lookup (impl->mPublisherMap , ( char* )symbol)))
        return (MAMA_STATUS_INVALID_ARG);

    mamaDQPublisher_destroy(newTopic->pub);
    wtable_remove (impl->mPublisherMap, symbol);

    free  ((void*)newTopic->symbol);
    free  ((void*)newTopic);
    return MAMA_STATUS_OK;
}
Example #6
0
    void MamaSource::addSubscription (const char*        symbol,
                                      MamaSubscription*  sub)
    {
        if (!mySubs)
        {
            mySubs = wtable_create ("MamaSource::mySubs", 100);
        }

        MamaSubscription* foundSub = 
            (MamaSubscription*) wtable_lookup (mySubs, symbol);

        if (foundSub)
        {
            return;
        }

        wtable_insert (mySubs, symbol, sub);
    }
Example #7
0
mama_status mamaDQPublisherManager_getPublisher (
        mamaDQPublisherManager manager,
        const char *symbol,
        mamaDQPublisher* pub)
{
    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;
    mamaPublishTopic*           topic = NULL;

    if (!impl || !pub)
         return MAMA_STATUS_INVALID_ARG;

    topic = (mamaPublishTopic*) wtable_lookup (impl->mPublisherMap, (char*)symbol);

    if (!topic)
         return MAMA_STATUS_NOT_FOUND;

    *pub = topic->pub;
    return MAMA_STATUS_OK;
}
Example #8
0
static void MAMACALLTYPE
inboxMsgCb (mamaMsg msg, void *closure)
{
    const char**        topics         = NULL;
    const mama_i32_t*    types         = NULL;
    size_t                 resultLen     = 0;
    mamaPublishTopic*     info        = NULL;
    int                 i            = 0;
    mama_status          status         = MAMA_STATUS_NOT_FOUND;
    mamaDQPublisherManagerImpl* impl = (mamaDQPublisherManagerImpl*) (closure);

    if ((status = mamaMsg_getVectorString (msg,NULL, MAMA_SYNC_TOPICS_ID,
                                           &topics, &resultLen)) != MAMA_STATUS_OK)
    {
        impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl, status,
                                      "Unknown Msg", msg);
        return;
    }

    if ((status = mamaMsg_getVectorI32 (msg, NULL, MAMA_SYNC_TYPES_ID, &types,
                                        &resultLen)) != MAMA_STATUS_OK)
    {
        impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl,
                                      status, "Unknown Msg", msg);
        return;
    }

    for (i=0; i<resultLen; i++)
    {
        if ((info  = wtable_lookup (impl->mPublisherMap , ( topics[i]))))
            impl->mUserCallbacks.onRequest ((mamaDQPublisherManager)impl,
                                            info, types[i],MAMA_SUBSC_RESUBSCRIBE, msg);
        else
            impl->mUserCallbacks.onNewRequest ((mamaDQPublisherManager)impl,
                                               topics[i], types[i], MAMA_SUBSC_RESUBSCRIBE,  msg);
    }
}
Example #9
0
mama_status mamaDQPublisherManager_removePublisher (
    mamaDQPublisherManager manager,
    const char *symbol,
    mamaDQPublisher* pub)
{
    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;
    mamaPublishTopic* newTopic = NULL;


    newTopic = (mamaPublishTopic*)wtable_lookup (impl->mPublisherMap,
               (char*)symbol);

    if (newTopic)
    {
        wtable_remove  (impl->mPublisherMap, (char*)symbol);

        *pub = newTopic->pub;
        free  ((void*)newTopic->symbol);
        free  ((void*)newTopic);
        return MAMA_STATUS_OK;
    }

    return (MAMA_STATUS_INVALID_ARG);
}
int updateStatisticsCache(statsCache* sCache ,
                          const char* msgCategoryName ,
                          long         numBytesRecieved,
                          long        timeSecs,
                          long        timeMicroSecs,
                          double      cLatency,
                          struct timeval tv)
{
    int ret;
    perfData *mPData = NULL;
    double latency = 0;

    if(timeSecs != 0 || timeMicroSecs != 0)
       calcLatency(timeSecs,timeMicroSecs,&latency,tv);
    else
       latency=cLatency;
                                                                                
    if(sCache->mNumMsg>0 && sCache->mSymbolTable)
    {
        /* More than one category*/
        mPData = 
            (perfData*) wtable_lookup (sCache->mSymbolTable,msgCategoryName);
        /* If category doesn't already exist*/
        if (!mPData)
        {
            /* Then create & init*/
            mPData = (perfData*)calloc(1,sizeof(perfData));    
            initPerfData(mPData,sCache->mOutfile,msgCategoryName);
        }        
    }
    else
    {
        /* No categories */
        mPData = sCache->mPData;
    }

    /* Update statistics for period    */
    mPData->mMsgCountP++;
    mPData->mByteCountP += (double)numBytesRecieved;
    
    /* change to get rid of spurious results*/
    /*    if (latency > 0) */
    if (/*latency >0  &&*/ latency<999999999)
    {
        mPData->mLatMsgCountP++;
        mPData->mLatAccumP += latency;
        if (latency < mPData->mMinLatencyP)
        {
            mPData->mMinLatencyP = latency;
        }
        if (latency > mPData->mMaxLatencyP)
        {
            mPData->mMaxLatencyP = latency;
        }
        mPData->mLatSquareP += (latency*latency);
    }     

    /* Update table in structure if more than one category*/
    if(sCache->mNumMsg>0)
    {
        ret=
        wtable_insert(sCache->mSymbolTable,msgCategoryName, (void*) mPData);
        if(ret>0)
        {
            /*error in insert*/    
        }  
             
    }

    sCache->mNumMessages++; 
    sCache->mNumBytes+=numBytesRecieved;
    return STATS_OK;
}