mama_status
mamaPublisher_sendFromInboxWithThrottle (mamaPublisher               publisher,
                                         mamaInbox                   inbox,
                                         mamaMsg                     msg,
                                         mamaThrottledSendCompleteCb sendCompleteCb,
                                         void*                       closure)
{
    mamaPublisherImpl*          impl    = (mamaPublisherImpl*)publisher;
    struct publisherClosure*    c2      = NULL;

    if (!impl) return MAMA_STATUS_NULL_ARG;

    c2 = (struct publisherClosure*)list_allocate_element(impl->mPendingActions);
    if (c2 == NULL) return MAMA_STATUS_NOMEM;

    if(!inbox)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                "mamaPublisher_sendFromInboxWithThrottle(): NULL inbox.");
        return MAMA_STATUS_INVALID_ARG;
    }

    if (!msg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                "mamaPublisher_sendFromInboxWithThrottle(): NULL msg.");
        return MAMA_STATUS_INVALID_ARG;
    }

    if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINER)
    {
        const char* msgString = mamaMsg_toString (msg);
        mama_log (MAMA_LOG_LEVEL_FINER, "INBOX REQUEST (throttled): %s", msgString);
        mamaMsg_freeString (msg, msgString);
    }

    c2->mPublisher            = publisher;
    c2->mInbox                = inbox;
    c2->mSendCompleteCallback = sendCompleteCb;
    c2->mSendCompleteClosure  = closure;

    list_push_back (impl->mPendingActions, c2);
    return mamaTransport_throttleAction (impl->mTport,
                                         MAMA_THROTTLE_DEFAULT,
                                         sendFromInboxMsgAction,
                                         impl,
                                         msg,
                                         c2,
                                         0,
                                         &c2->mAction);
}
Exemple #2
0
static void MAMACALLTYPE
subscriptionHandlerOnErrorCb (mamaDQPublisherManager manager,
                              mama_status            status,
                              const char*            errortxt,
                              mamaMsg                msg)
{
    if (msg)
    {
        printf ("Unhandled Msg: %s (%s) %s\n",
                mamaStatus_stringForStatus (status),
                mamaMsg_toString (msg),
                errortxt);
    }
    else
    {
        printf("Unhandled Msg: %s %s\n",
               mamaStatus_stringForStatus (status),
               errortxt);
    }
}
Exemple #3
0
static void MAMACALLTYPE pubCallback (mamaTimer timer, void* closure)
{
    int index =0;
    char*temp=NULL;
    char*source=NULL;
    char*           headerString = NULL;
    mamaMsg        newMessage;
    mama_status status = MAMA_STATUS_OK;

    for (index=0; index < gNumSymbols; index++)
    {
        if (gSubscriptionList[index].fileParser)
        {
            int header = 1;
            while ((header = mamaPlaybackFileParser_getNextHeader (
                    gSubscriptionList[index].fileParser, &headerString)))
            {
                if (strlen (headerString) == 0) continue;
                /*skip source and transport name*/
                temp = strchr (headerString,DELIM);
                temp++;
                source = strchr (temp,DELIM);
                source++; /*skip :*/

                temp = strchr (source, DELIM);

                if (mamaPlaybackFileParser_getNextMsg (
                        gSubscriptionList[index].fileParser, &newMessage))
                {
                    int symLength = temp - source;
                    if (0 == strncmp (gSubscriptionList[index].symbol,
                                        source,
                                        symLength)
                       &&
                        symLength == (strlen (gSubscriptionList[index].symbol))
                       )
                    {
                        mamaMsg_applyMsg (gSubscriptionList[index].cachedMsg,
                                          newMessage);

                        mama_log (MAMA_LOG_LEVEL_FINEST,
                                  "Publishing message: %s",
                                  mamaMsg_toString(newMessage));

                        mamaDQPublisher_send (gSubscriptionList[index].pub,
                                              newMessage);
                        break;
                    }
                }
            }
            if (gRewind && !header) 
            {
                mama_log (MAMA_LOG_LEVEL_FINE, 
                            "End of file reached for symbol %s - Rewinding.",
                            gSubscriptionList[index].symbol);
                status = mamaPlaybackFileParser_rewindFile(
                            gSubscriptionList[index].fileParser);

                if (MAMA_STATUS_OK != status)
                {
                  mama_log(MAMA_LOG_LEVEL_FINE, "Failed to rewind file %s",
                           mamaStatus_stringForStatus(status));
                }
            } else if (!header) {
                mama_log (MAMA_LOG_LEVEL_FINE, 
                            "End of file reached for symbol %s.", 
                            gSubscriptionList[index].symbol);
            }
        }
    }
}
Exemple #4
0
/**
 * Called when message removed from queue by dispatch thread
 *
 * @param data The Avis Attributes* clone (must be freed)
 * @param closure The subscriber
 */
static void MAMACALLTYPE
avis_queue_callback (mamaQueue queue,
                     void*     closure)
{
    mama_status status     = MAMA_STATUS_OK;
    mamaMsg     tmpMsg     = NULL;
    msgBridge   bridgeMsg  = NULL;
    const void* buf        = NULL;
    mama_size_t bufSize    = 0;

    avisCallbackContext* ctx = (avisCallbackContext*) closure;

    void* data       = ctx->attributes;
    void* subscriber = ctx->subscriber;

    /* cant do anything without a subscriber */
    if (!subscriber)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): called with NULL subscriber!");

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Make sure that the subscription is processing messages*/
    if ((!avisSub(subscriber)->mIsNotMuted) || 
        (!avisSub(subscriber)->mIsValid))
    {
        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*This is the reuseable message stored on the associated MamaQueue*/
    tmpMsg = mamaQueueImpl_getMsg(avisSub(subscriber)->mQueue);
    if (!tmpMsg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get cached mamaMsg from event queue.");

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Get the bridge message from the mamaMsg*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_getBridgeMsg (tmpMsg,
                    &bridgeMsg)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get bridge message from cached"
                  " queue mamaMsg [%d]", status);

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Set the buffer and the reply handle on the bridge message structure*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMsgBuffer (tmpMsg,
                                data,
                                0, MAMA_PAYLOAD_AVIS)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): mamaMsgImpl_setMsgBuffer() failed. [%d]",
                  status);

        attributes_destroy (data);
        free (ctx);
        return;
    }

    if (MAMA_STATUS_OK == mamaMsg_getOpaque (
            tmpMsg, ENCLOSED_MSG_FIELD_NAME, 0, &buf, &bufSize) && 
            bufSize > 0)
    {
        mamaMsg         encMsg = NULL;
        mamaBridgeImpl* bridge = 
            mamaSubscription_getBridgeImpl (avisSub(subscriber)->mMamaSubscription);

        status = mamaMsg_createFromByteBuffer (&encMsg, buf, bufSize);

        if (MAMA_STATUS_OK != status)
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "Could not create message from enclosed byte buffer. [%d]",
                      status);

            attributes_destroy (data);
            free (ctx);
            return;
        }

        mamaMsgImpl_useBridgePayload (encMsg, bridge);
        mamaMsgImpl_getBridgeMsg (encMsg, &bridgeMsg);

        /*Set the buffer and the reply handle on the bridge message structure*/
        avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

        if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST)
        {
            mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): "
                      "Received enclosed message: %s", mamaMsg_toString (encMsg));
        }

        if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                    (avisSub(subscriber)->mMamaSubscription, encMsg)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "mamaSubscription_processMsg() failed. [%d]",
                      status);
        }

        mamaMsg_destroy (encMsg);
    }
    else
    {
        avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

        if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST)
        {
            mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): "
                           "Received message: %s", mamaMsg_toString (tmpMsg));
        }

        /*Process the message as normal*/
        if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                    (avisSub(subscriber)->mMamaSubscription, tmpMsg)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "mamaSubscription_processMsg() failed. [%d]",
                      status);
        }
    }

    free (ctx);
}