Exemplo n.º 1
0
static mama_status
handleStaleData (dqStrategy     strategy,
                 mamaMsg        msg,
                 mamaDqContext* ctx)
{
    const char*  symbol = NULL;
    mamaSubscription_getSymbol (self->mSubscription, &symbol);

    if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINER)
    {
        symbol = symbol == NULL ? "" : symbol;
        mama_log (MAMA_LOG_LEVEL_FINER, "%s : stale data", symbol);
    }

    msgUtils_setStatus (msg, MAMA_MSG_STATUS_STALE);

    if (ctx->mDQState != DQ_STATE_WAITING_FOR_RECAP &&
        ctx->mDQState != DQ_STATE_POSSIBLY_STALE)
    {
        void*               closure = NULL;
        mamaMsgCallbacks*   cb      = NULL;

        dqStrategy_sendRecapRequest (self, msg, ctx);

        /* Callback last in the event that client destroys */ 
        mamaSubscription_getClosure (self->mSubscription, &closure);
        cb = mamaSubscription_getUserCallbacks (self->mSubscription);

        if (cb != NULL && cb->onQuality != NULL)
        {
            short       cause;
            const void* platformInfo = NULL;
            mamaSubscription_getAdvisoryCauseAndPlatformInfo (
                                                        self->mSubscription,
                                                        &cause, &platformInfo);
            cb->onQuality (self->mSubscription, MAMA_QUALITY_STALE, symbol, 
                           cause, platformInfo, closure);
        }
    }
    else if (ctx->mDQState == DQ_STATE_POSSIBLY_STALE &&
             ctx->mDQState != DQ_STATE_WAITING_FOR_RECAP)
    {
        dqStrategy_sendRecapRequest (self, msg, ctx);
    }

    return MAMA_STATUS_OK;
}
Exemplo n.º 2
0
void dumpList (mamaCaptureList captureList)
{
    int counter = 0;
    mamaCaptureSourceList * sourceList
        = (mamaCaptureSourceList*)captureList;
    for (counter = 0; counter< gCounter; counter++)
    {
        mama_log (MAMA_LOG_LEVEL_NORMAL,
                  "Source = %s, symbol = %s, tport = %s, " \
                  "tportaddress =%p\n",
                  sourceList[counter].mySymbolNamespace,
                  sourceList[counter].mySymbol,
                  sourceList[counter].myTransportName,
                  sourceList[counter].myTransport);

    }
}
Exemplo n.º 3
0
    void MamaLogFile::setNumBackups (unsigned int newNum)
    {
        mamaTry (mama_setNumLogFiles (newNum));

        if (0 == newNum)
        {
            mama_log (MAMA_LOG_LEVEL_NORMAL,
                    "MamaLogFile::setNumBackups(newNum = %d)\n "
                    "\t- Only a single log file will be maintained\n"
                    "\t- Log file will be over written when max size exceeded\n",
                    newNum);
        }
        else
        {
            mama_setLogFilePolicy(LOGFILE_ROLL);
        }
    }
int mamaCapture_closeFile (mamaPlaybackCapture mamaCapture)
{
    int result = -1;
    mamaCaptureConfigImpl* impl = (mamaCaptureConfigImpl*)mamaCapture;
    if (myPlaybackFile)
    {
        result= fclose (myPlaybackFile);
    }
    if (result != 0)
    {
        mama_log (MAMA_LOG_LEVEL_FINE,
                  "mamaCapture_closeFile: Error closing file %s",
                  impl->myPlayBackFileName);
        return EOF;
    }
    return result;
}
Exemplo n.º 5
0
mama_status
mamaQueue_timedDispatch (mamaQueue queue,
                         uint64_t  timeout)
{
    mamaQueueImpl* impl   = (mamaQueueImpl*)queue;

    if (!impl)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "mamaQueue_timedDispatch(): NULL queue.");
        return MAMA_STATUS_NULL_ARG;
    }

    wInterlocked_set (1, &impl->mIsDispatching);
    return impl->mBridgeImpl->bridgeMamaQueueTimedDispatch
                            (impl->mMamaQueueBridgeImpl, timeout);
}
Exemplo n.º 6
0
mama_status
mamaQueue_dispatch (mamaQueue queue)
{
    mamaQueueImpl* impl   = (mamaQueueImpl*)queue;
    mama_status    status = MAMA_STATUS_OK;

    if (!impl)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "mamaQueue_dispatch(): NULL queue.");
        return MAMA_STATUS_NULL_ARG;
    }

    wInterlocked_set (1, &impl->mIsDispatching);
    return impl->mBridgeImpl->bridgeMamaQueueDispatch
                                (impl->mMamaQueueBridgeImpl);
}
Exemplo n.º 7
0
mama_status
mamaConflationManager_flush (mamaConflationManager mgr)
{
    mamaConflationMgr* impl  = (mamaConflationMgr*)mgr;

    if (impl == NULL)
        return MAMA_STATUS_INVALID_ARG;

    if (wombatQueue_flush (impl->mMsgQueue, flushCallback, impl) !=
        WOMBAT_QUEUE_OK)
    {
        mama_log (MAMA_LOG_LEVEL_FINE, "Error flushing queue (%p)", impl);
        return MAMA_STATUS_CONFLATE_ERROR;
    }

    return MAMA_STATUS_OK;
}
Exemplo n.º 8
0
static
void unsubscribeAvis (Elvin* avis,
                      void*  closure)
{
    Subscription* sub = (Subscription*) closure;

    elvin_subscription_remove_listener (sub, avis_callback);

    if (!elvin_unsubscribe(avis, sub))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "unsubscribeAvis(): "
                                        "Failed to unsubscribe to: %s",
                                        sub->subscription_expr);
    }

    free (sub);
}
Exemplo n.º 9
0
mama_status
mamaQueue_enqueueEvent  (mamaQueue        queue,
                         mamaQueueEventCB callback,
                         void*            closure)
{
    mamaQueueImpl* impl = (mamaQueueImpl*)queue;

    if (!impl)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "mamaQueue_enqueueEvent(): NULL queue.");
        return MAMA_STATUS_NULL_ARG;
    }

    return impl->mBridgeImpl->bridgeMamaQueueEnqueueEvent
                        (impl->mMamaQueueBridgeImpl, callback, closure);
}
Exemplo n.º 10
0
static void MAMACALLTYPE dictionarySubOnMsg (mamaSubscription subsc, 
                                mamaMsg          msg,
                                void*            closure, 
                                void*            itemClosure)
{
    mama_status status = MAMA_STATUS_OK;
    status = mamaPublisher_sendReplyToInbox (gDictionaryPublisher,
                                             msg,
                                             gDictionaryMessage);

    if (MAMA_STATUS_OK != status) 
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "Failed to send dictionary message.");
        exit (1);
    }
}
Exemplo n.º 11
0
void UPAConsumer::RecoverConnection()
{

   // notify listeners that we are not connected
   mama_log (MAMA_LOG_LEVEL_FINE, "Recovering Connection");
   NotifyListeners(false, "Recovering Connection");

   // reset the channel
   if ((rsslConsumerChannel_ != NULL) && (rsslConsumerChannel_->socketId != -1))
   {
      RemoveChannel(rsslConsumerChannel_);
      rsslConsumerChannel_ = NULL;
   }
   // and flag a reconnect
   shouldRecoverConnection_ = RSSL_TRUE;

}
Exemplo n.º 12
0
void RMDSBridgeSubscription::OnMessage( mamaMsg msg, mamaMsgType msgType )
{
	if (isShutdown_ || ((0 != source_) && source_->IsPausedUpdates()))
	{
		// just don't bother with making the callback
		return;
	}

	// send the message
	mama_status status = MAMA_STATUS_OK;

	if (msgType == MAMA_MSG_TYPE_INITIAL || msgType == MAMA_MSG_TYPE_REFRESH || msgType == MAMA_MSG_TYPE_RECAP || msgType == MAMA_MSG_TYPE_BOOK_INITIAL || msgType == MAMA_MSG_TYPE_BOOK_RECAP)
	{
		gotImage_ = true;
	}
	else if (msgType == MAMA_MSG_TYPE_SEC_STATUS)
	{
		// Let status go through
	}
	else
	{
		if (!gotImage_)
		{
			t42log_debug("Ignoring Update type %d with no image for %s : %s \n", msgType, symbol_.c_str(), sourceName_.c_str() );
			return;
		}
	}

	try
	{
		status = mamaSubscription_processMsg(subscription_, msg);
	}
	catch (...)
	{
		t42log_error("RMDSBridgeSubscription::OnMessage - caught exception calling mamaSubscription_processMsg for %s", symbol_.c_str());
	}

	if (MAMA_STATUS_OK != status)
	{
		mama_log (MAMA_LOG_LEVEL_ERROR,
			"RMDSBridgeSubscription::OnMessage: "
			"mamaSubscription_processMsg() failed. [%d]",
			status);
	}
}
Exemplo n.º 13
0
int main(int argc, const char* argv[])
{
    mamaCaptureConfig mCapture = NULL;
    mamaCaptureList mCaptureList     = NULL;
    mamaCaptureConfig_create (&mCapture);

    if (mCapture == NULL)
    {
        mama_log (MAMA_LOG_LEVEL_NORMAL,
                  "Allocation of memory for capture failed!!!!");
        exit (1);
    }

    gCapture  = &mCapture;
    parseCommandLine (mCapture , &mCaptureList, argc, argv);

    /*Set up a signal handler so that we don't
      just stop without cleaning up*/
    gCaptureList = &mCaptureList;
    initializeMama (mCapture);

    mamaCaptureList_parseCommandInput (mCapture,
                                       mCaptureList, gSource);
    mamaCapture_openFile (&mCapture->myCapture,
                       mCapture->myCaptureFilename);


    buildDataDictionary(mCapture);
    dumpDataDictionary (mCapture);

    if (mCapture->myDumpList)
    {
        dumpList (mCaptureList);
    }
    subscribeToSymbols (mCapture,mCaptureList);

    mama_logStdout (MAMA_LOG_LEVEL_NORMAL, "Type CTRL-C to exit.\n\n");

    mama_start (mCapture->myBridge);

    mamaCapture_closeFile(mCapture->myCapture);
    msshutdown (mCapture,mCaptureList);

    return 0;
}
Exemplo n.º 14
0
   void CTick42Logger::operator()(const char *format, ...)
   {
      va_list ap;
      va_start(ap, format);

      // Only process if this logging level is enabled
      if (enabled_)
      {
         char *buf = static_cast<char *>(alloca(logBufferSize_ * sizeof(*buf)));
         int off = snprintf(buf, logBufferSize_ - 1, "%s(%u): ", filename_, lineNumber_);
         off += vsnprintf(buf + off, logBufferSize_ - off, format, ap);

         // Strip one trailing '\n', if there is one
         // If you want a blank line in the debug log file, then include
         // two '\n' sequences at the end of your format string
         if ((0 < off) && (buf[off - 1] == '\n'))
         {
            buf[--off]  = '\0';
         }

#ifdef _WIN32
         if (logODS_)
         {
            buf[off++] = '\r';
            buf[off++] = '\n';
            buf[off] = '\0';
            OutputDebugStringA(buf);
         }
         else
#endif // _WIN32
         {
            mama_log(logLevel_, "%s", buf);
         }

         if (logConsole_)
         {
            utils::thread::T42Lock sync(&lock_);
            fprintf(stdout, "%s\n", buf);
            fflush(stdout);
         }
      }
      va_end(ap);
   }
Exemplo n.º 15
0
mama_status
zmqBridge_close (mamaBridge bridgeImpl)
{
    mama_status      status      = MAMA_STATUS_OK;
    mamaBridgeImpl*  bridge      = (mamaBridgeImpl*) bridgeImpl;
    wthread_t        timerThread;

    if (NULL ==  bridgeImpl)
    {
        return MAMA_STATUS_NULL_ARG;
    }

    /* Remove the timer heap */
    if (NULL != gOmzmqTimerHeap)
    {
        /* The timer heap allows us to access it's thread ID for joining */
        timerThread = timerHeapGetTid (gOmzmqTimerHeap);
        if (0 != destroyHeap (gOmzmqTimerHeap))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "zmqBridge_close(): Failed to destroy zmq timer heap.");
            status = MAMA_STATUS_PLATFORM;
        }
        /* The timer thread expects us to be responsible for terminating it */
        wthread_join    (timerThread, NULL);
    }
    gOmzmqTimerHeap = NULL;

    /* Destroy once queue has been emptied */
    mamaQueue_destroyTimedWait (bridge->mDefaultEventQueue,
                                ZMQ_SHUTDOWN_TIMEOUT);

    /* Stop and destroy the io thread */
    zmqBridgeMamaIoImpl_stop ();

    /* Wait for zmqBridge_start to finish before destroying implementation */
    if (NULL != bridgeImpl)
    {
        free (bridgeImpl);
    }

    return status;
}
Exemplo n.º 16
0
mama_status
mamaQueueImpl_lowWatermarkExceeded (mamaQueue queue,
                                    size_t    size)
{
    mamaQueueImpl* impl = (mamaQueueImpl*)queue;

    if (!impl) return MAMA_STATUS_NULL_ARG;

    if (impl->mQueueMonitorCallbacks.onQueueLowWatermark)
    {
        mama_log (MAMA_LOG_LEVEL_FINE,
                  "Low water mark for queue [%s] exceeded : %d",
                  impl->mQueueName, size);
        impl->mQueueMonitorCallbacks.onQueueLowWatermark (
                                queue,
                                size,
                                impl->mQueueMonitorClosure);
    }
    return MAMA_STATUS_OK;
}
Exemplo n.º 17
0
mama_status qpidBridgeMamaMsgImpl_setStringValue (char*         dest,
                                                  const char*   value)
{
    strncpy (dest, value, QPID_MSG_PROPERTY_LEN);

    /* ISO C - remaining bytes from strncpy are null unless overrun occurred */
    if (dest[QPID_MSG_PROPERTY_LEN - 1] != '\0')
    {
        /* Terminate string to at least make it usable (though truncated) */
        dest[QPID_MSG_PROPERTY_LEN - 1] = '\0';
        mama_log (MAMA_LOG_LEVEL_WARN,
                  "qpidBridgeMamaMsgImpl_setStringValue(): "
                  "Unable to set value '%s': Property too long for buffer. ",
                  "Truncated to '%s'",
                  value,
                  dest);
        return MAMA_STATUS_PROPERTY_TOO_LONG;
    }
    return MAMA_STATUS_OK;
}
Exemplo n.º 18
0
mama_status
wombatThrottle_removeMessagesForOwner (wombatThrottle throttle, void *owner)
{
    biclosure  closure;
    
    if (NULL==throttle)
      return MAMA_STATUS_NULL_ARG;

    closure.impl     = self;
    closure.owner    = owner;

    gRemoveCount = 0;

    list_for_each (self->mMsgQueue, removeMessagesForOwnerCb,
                                                     (void*)(&closure));
    mama_log (MAMA_LOG_LEVEL_FINE, "wombatThrottle_removeMessagesForOwner (): "
              "%d Messages removed from queue.",
              gRemoveCount);

    return MAMA_STATUS_OK;
}
Exemplo n.º 19
0
void RMDSBridgeSubscription::SendStatusMessage( mamaMsgStatus secStatus )
{
	if (isShutdown_)
	{
		// just don't bother making the callback
		return;
	}
	// create and send a message containing the (failed) status
	mamaMsg msg;
	mamaMsg_createForPayload(&msg, MAMA_PAYLOAD_TICK42RMDS);

	mamaMsg_addI32(msg, MamaFieldMsgType.mName, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_SEC_STATUS);
	mamaMsg_addI32(msg, MamaFieldMsgStatus.mName, MamaFieldMsgStatus.mFid, secStatus);

    const CommonFields &commonFields = UpaMamaCommonFields::CommonFields();
	mamaMsg_addString(msg, commonFields.wIssueSymbol.mama_field_name.c_str(),commonFields.wIssueSymbol.mama_fid, symbol_.c_str());
	mamaMsg_addString(msg, commonFields.wSymbol.mama_field_name.c_str(), commonFields.wSymbol.mama_fid, symbol_.c_str());

	mama_status status = MAMA_STATUS_OK;
	try
	{
		status = mamaSubscription_processMsg(subscription_, msg);
	}
	catch (...)
	{
		mamaMsg_destroy(msg);	
		t42log_error("RMDSBridgeSubscription::OnMessage - caught exception calling mamaSubscription_processMsg for %s", symbol_.c_str());
	}


	if (MAMA_STATUS_OK != status)
	{
		mama_log (MAMA_LOG_LEVEL_ERROR,
			"RMDSBridgeSubscription::OnMessage: "
			"mamaSubscription_processMsg() failed. [%d]",
			status);
	}

	mamaMsg_destroy(msg);	
}
Exemplo n.º 20
0
mama_status
avisBridgeMamaTransport_destroy (transportBridge transport)
{
    mama_status status;
    avisTransportBridge* transportBridge = (avisTransportBridge*) transport;
    mamaBridgeImpl*      bridgeImpl      = NULL;

    if (!transport) return MAMA_STATUS_NULL_ARG;
    
    bridgeImpl = mamaTransportImpl_getBridgeImpl(
        avisTransport(transport)->mTransport);
    if (!bridgeImpl) 
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, 
            "avisBridgeMamaTransport_destroy(): Could not get bridge");
        free(transport);
        return MAMA_STATUS_PLATFORM;
    }

    if (1 == wInterlocked_read (&transportBridge->mDispatching))
    {
        avisTransportBridge_stop (transportBridge);
    }

    elvin_remove_close_listener (transportBridge->mAvis, closeListener);

    if (!elvin_close (transportBridge->mAvis)) 
    {
        /* there appears to be a race condition in Avis libs where router socket
         * can sometimes be closed before we receive the disconnect reply -- log
         * it, and continue */
        log_avis_error(MAMA_LOG_LEVEL_FINE, transportBridge->mAvis);
    }

    wInterlocked_destroy (&transportBridge->mDispatching);
    wsem_destroy(&avisTransport(transport)->mAvisDispatchSem);
    free(avisTransport(transport)->mAvis);
    free(avisTransport(transport));
    return MAMA_STATUS_OK;
}
Exemplo n.º 21
0
mama_status
mamaConflationManager_start (mamaConflationManager mgr)
{
    mamaConflationMgr* impl = (mamaConflationMgr*)mgr;

    if (impl == NULL || impl->mConnection == NULL || !impl->mInstalled)
        return MAMA_STATUS_INVALID_ARG;

    if (mamaTransportImpl_startConnectionConflation (
            impl->mTransport, 
            mgr, 
            impl->mConnection)!=MAMA_STATUS_OK)
    {
        mama_log (MAMA_LOG_LEVEL_FINE, "Failed to start. "
                  "startConnectionConflationManager ()");
        return MAMA_STATUS_CONFLATE_ERROR;
    }

    impl->mStarted = 1;

    return  MAMA_STATUS_OK;
}
Exemplo n.º 22
0
mama_status
avisBridgeMamaQueue_enqueueEvent (queueBridge        queue,
                                  mamaQueueEventCB   callback,
                                  void*              closure)
{
    wombatQueueStatus   status;
    avisQueueBridge*    impl = (avisQueueBridge*) queue;

    if (NULL == callback)
        return MAMA_STATUS_NULL_ARG;

    /* Perform null checks and return if null arguments provided */
    CHECK_QUEUE(impl);

    /* Call the underlying wombatQueue_enqueue method */
    status = wombatQueue_enqueue (impl->mQueue,
                                  (wombatQueueCb) callback,
                                  impl->mParent,
                                  closure);

    /* Call the enqueue callback if provided */
    if (NULL != impl->mEnqueueCallback)
    {
        impl->mEnqueueCallback (impl->mParent, impl->mEnqueueClosure);
    }

    /* If dispatch failed, report here */
    if (WOMBAT_QUEUE_OK != status)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avisBridgeMamaQueue_enqueueEvent (): "
                  "Failed to enqueueEvent (%d). Callback: %p; Closure: %p",
                  status, callback, closure);
        return MAMA_STATUS_PLATFORM;
    }

    return MAMA_STATUS_OK;
}
Exemplo n.º 23
0
static void
avis_callback(
    Subscription*   subcription,
    Attributes*     attributes,
    bool            secure,
    void*           subscriber)
{
    /* cant do anything without a subscriber */
    if (!avisSub(subscriber)) {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!");
        return;
    }

    /*Make sure that the subscription is processing messages*/
    if ((!avisSub(subscriber)->mIsNotMuted) || (!avisSub(subscriber)->mIsValid)) return;

    avisCallbackContext* ctx = (avisCallbackContext*) malloc (sizeof (avisCallbackContext));
    ctx->attributes = attributes_clone (attributes);
    ctx->subscriber = subscriber;

    mamaQueue_enqueueEvent (avisSub (subscriber)->mQueue,
                            avis_queue_callback, ctx);
}
Exemplo n.º 24
0
    MamaQueue* Mama::getDefaultEventQueue (mamaBridge bridgeImpl)
    {
        MamaQueue* defaultQueue = NULL;
        mamaQueue  defaultQueueC;

        if (MAMA_STATUS_OK == 
            mama_getDefaultEventQueue (bridgeImpl, &defaultQueueC))
        {
            mamaQueue_getClosure (defaultQueueC, (void**)(&defaultQueue));
            if (defaultQueue == NULL)
            {
                defaultQueue = new MamaQueue(defaultQueueC);
                mamaQueue_setClosure(defaultQueueC, (void*) defaultQueue);
            }
            return defaultQueue;
        }
        else
        {
            mama_log (MAMA_LOG_LEVEL_ERROR, "Mama::getDefaultEventQueue(): "
                      "Could not get C default event queue.");
            return NULL;
        }
    }
Exemplo n.º 25
0
void buildDataDictionary (mamaCaptureConfig subCapture)
{
    mamaCapture * capture = (mamaCapture*)subCapture;
    mamaDictionaryCallbackSet dictionaryCallback;
    mama_status result;

    if (capture->myBuildDataDict)
    {
        dictionaryCallback.onComplete = completeCb;
        dictionaryCallback.onTimeout  = timeoutCb;
        dictionaryCallback.onError = errorCb;

        result = mama_createDictionary  (&capture->myDictionary,
                                         capture->myDefaultQueue,
                                         dictionaryCallback,
                                         capture->myDictSource,
                                         10.0,
                                         3,
                                         capture);

        if (result != MAMA_STATUS_OK)
        {
            mama_logStdout (MAMA_LOG_LEVEL_NORMAL, "Exception creating "
                            "dictionary: MamaStatus: %s\n",
                            mamaStatus_stringForStatus (result));
            exit (1);
        }

        mama_start (capture->myBridge);

        if (!capture->myDictionaryComplete)
        {
            mama_log(MAMA_LOG_LEVEL_NORMAL, "MamaCapture Could not create dictionary.\n" );
            exit(1);
        }
    }
}
Exemplo n.º 26
0
mama_status
mamaPublisher_sendWithThrottle (mamaPublisher               publisher,
                                mamaMsg                     msg,
                                mamaThrottledSendCompleteCb sendCompleteCb,
                                void*                       closure)
{
    mamaPublisherImpl*       impl     = (mamaPublisherImpl*)publisher;
    struct publisherClosure* pClosure = NULL;

    if (!publisher) return MAMA_STATUS_NULL_ARG;

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

    pClosure = list_allocate_element (impl->mPendingActions);
    if (!pClosure) return MAMA_STATUS_NOMEM;

    list_push_back (impl->mPendingActions, pClosure);

    /*Initializse the closuse for the throttle*/
    pClosure->mPublisher            = publisher;
    pClosure->mSendCompleteCallback = sendCompleteCb;
    pClosure->mSendCompleteClosure  = closure;

    return mamaTransport_throttleAction (impl->mTport,
                                         MAMA_THROTTLE_DEFAULT,
                                         sendMsgAction,
                                         impl,
                                         msg, /*1st closure*/
                                         pClosure, /*2nd Closure*/
                                         0,
                                         &pClosure->mAction);
}
Exemplo n.º 27
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 (void* data, void* closure)
{
    mama_status status;
    mamaMsg tmpMsg;
    msgBridge bridgeMsg;

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

    /*Make sure that the subscription is processing messages*/
    if ((!avisSub(closure)->mIsNotMuted) || (!avisSub(closure)->mIsValid)) return;


    /*This is the reuseable message stored on the associated MamaQueue*/
    tmpMsg = mamaQueueImpl_getMsg(avisSub(closure)->mQueue);
    if (!tmpMsg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get cached mamaMsg from event queue.");
        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);
        return;
    }

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

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

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

    attributes_free ((Attributes*)data);
    free ((Attributes*)data);
}
Exemplo n.º 28
0
mama_status
avisBridgeMamaSubscription_create (subscriptionBridge* subscriber,
                                    const char*         source,
                                    const char*         symbol,
                                    mamaTransport       transport,
                                    mamaQueue           queue,
                                    mamaMsgCallbacks    callback,
                                    mamaSubscription    subscription,
                                    void*               closure)
{
    avisSubscription* impl = NULL;
    
    if (!subscriber || !subscription || !transport )
        return MAMA_STATUS_NULL_ARG;

    impl = (avisSubscription*)calloc (1, sizeof(avisSubscription));
    if (impl == NULL)
       return MAMA_STATUS_NOMEM;

    impl->mAvis = getAvis(transport);
    if (!impl->mAvis)
       return MAMA_STATUS_INVALID_ARG;

    if (source != NULL && source[0])
    {
        impl->mSource = source;
    }
    else
    {
        impl->mSource = "";
    }

    if (symbol != NULL && symbol[0])
    {
        impl->mSymbol = symbol;
        snprintf (impl->mSubject, sizeof(impl->mSubject), "%s.%s",
                  impl->mSource, impl->mSymbol);
    }
    else
    {
        impl->mSymbol = "";
        snprintf (impl->mSubject, sizeof(impl->mSubject), "%s",
                  impl->mSource );
    }

    impl->mMamaCallback       = callback;
    impl->mMamaSubscription   = subscription;
    impl->mQueue              = queue;
    impl->mTransport          = transport;
    impl->mClosure            = closure;
    impl->mIsNotMuted         = 1;
    impl->mIsValid            = 1;

    impl->mAvisSubscription = elvin_subscribe(impl->mAvis, makeAvisSubject(impl->mSubject));
    if (impl->mAvisSubscription == NULL)
       return MAMA_STATUS_PLATFORM;

    elvin_subscription_add_listener(impl->mAvisSubscription, avis_callback, impl);
    mama_log (MAMA_LOG_LEVEL_FINER,
              "Made Avis subscription to: %s", impl->mSubject);

    *subscriber =  (subscriptionBridge) impl;
    return MAMA_STATUS_OK;
}
Exemplo n.º 29
0
mama_status
avisBridgeMamaQueue_create (queueBridge* queue,
                            mamaQueue    parent)
{
    /* Null initialize the queue to be created */
    avisQueueBridge*    impl                = NULL;
    wombatQueueStatus   underlyingStatus    = WOMBAT_QUEUE_OK;

    if (queue == NULL || parent == NULL)
    {
        return MAMA_STATUS_NULL_ARG;
    }

    /* Null initialize the queueBridge */
    *queue = NULL;

    /* Allocate memory for the avis queue implementation */
    impl = (avisQueueBridge*) calloc (1, sizeof (avisQueueBridge));
    if (NULL == impl)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avisBridgeMamaQueue_create (): "
                  "Failed to allocate memory for queue.");
        return MAMA_STATUS_NOMEM;
    }

    /* Initialize the dispatch lock */
    wthread_mutex_init (&impl->mDispatchLock, NULL);

    /* Back-reference the parent for future use in the implementation struct */
    impl->mParent = parent;

    /* Allocate and create the wombat queue */
    underlyingStatus = wombatQueue_allocate (&impl->mQueue);
    if (WOMBAT_QUEUE_OK != underlyingStatus)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avisBridgeMamaQueue_create (): "
                  "Failed to allocate memory for underlying queue.");
        free (impl);
        return MAMA_STATUS_NOMEM;
    }

    underlyingStatus = wombatQueue_create (impl->mQueue,
                                           AVIS_QUEUE_MAX_SIZE,
                                           AVIS_QUEUE_INITIAL_SIZE,
                                           AVIS_QUEUE_CHUNK_SIZE);
    if (WOMBAT_QUEUE_OK != underlyingStatus)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avisBridgeMamaQueue_create (): "
                  "Failed to create underlying queue.");
        wombatQueue_deallocate (impl->mQueue);
        free (impl);
        return MAMA_STATUS_PLATFORM;
    }

    /* Populate the queueBridge pointer with the implementation for return */
    *queue = (queueBridge) impl;

    return MAMA_STATUS_OK;
}
Exemplo n.º 30
0
mama_status
mamaQueue_destroy (mamaQueue queue)
{
    mamaQueueImpl* impl = (mamaQueueImpl*)queue;
    mama_status    status = MAMA_STATUS_OK;

    mama_log (MAMA_LOG_LEVEL_FINEST, "Entering mamaQueue_destroy for queue 0x%X.", queue);

    impl->mIsDispatching = 0;
    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_destroy(): NULL queue.");
        return MAMA_STATUS_NULL_ARG;
    }

    /* The queue can only be destroyed if there are no open event objects. */
    status = MAMA_STATUS_QUEUE_OPEN_OBJECTS;

    /* Only continue if the object count is 0. */
    if(0 == wInterlocked_read(&impl->mNumberOpenObjects))
    {
        if (impl->mMamaQueueBridgeImpl)
        {
            if (MAMA_STATUS_OK!=(status=impl->mBridgeImpl->bridgeMamaQueueDestroy (
                        impl->mMamaQueueBridgeImpl)))
            {
                mama_log (MAMA_LOG_LEVEL_ERROR,
                      "mamaQueue_destroy(): Could not destroy queue bridge.");
                     /*We should continue and free up the rest of the structure.*/
            }
        }

        if (impl->mDispatcher)
        {
            /* We don't want the dispatcher to access a destroyed queue */
            ((mamaDispatcherImpl*)(impl->mDispatcher))->mIsDispatching = 0;
            ((mamaDispatcherImpl*)(impl->mDispatcher))->mQueue = NULL;
        }

        /*Destroy the cached mamaMsg - no longer needed*/
        if (impl->mMsg) mamaMsg_destroy (impl->mMsg);

        if (impl->mInitialStat)
        {
            mamaStat_destroy (impl->mInitialStat);
            impl->mInitialStat = NULL;
        }

        if (impl->mRecapStat)
        {
            mamaStat_destroy (impl->mRecapStat);
            impl->mRecapStat = NULL;
        }

        if (impl->mUnknownMsgStat)
        {
            mamaStat_destroy (impl->mUnknownMsgStat);
            impl->mUnknownMsgStat = NULL;
        }

        if (impl->mMessageStat)
        {
            mamaStat_destroy (impl->mMessageStat);
            impl->mMessageStat = NULL;
        }

        if (impl->mQueueSizeStat)
        {
            mamaStat_destroy (impl->mQueueSizeStat);
            impl->mQueueSizeStat = NULL;
        }

        if (impl->mSubscriptionStat)
        {
            mamaStat_destroy (impl->mSubscriptionStat);
            impl->mSubscriptionStat = NULL;
        }

        if (impl->mTimeoutStat)
        {
            mamaStat_destroy (impl->mTimeoutStat);
            impl->mTimeoutStat = NULL;
        }

        if (impl->mWombatMsgsStat)
        {
            mamaStat_destroy (impl->mWombatMsgsStat);
            impl->mWombatMsgsStat = NULL;
        }

        if (impl->mFastMsgsStat)
        {
            mamaStat_destroy (impl->mFastMsgsStat);
            impl->mFastMsgsStat = NULL;
        }

        if (impl->mRvMsgsStat)
        {
            mamaStat_destroy (impl->mRvMsgsStat);
            impl->mRvMsgsStat = NULL;
        }

        if (impl->mStatsCollector)
        {
            mamaStatsGenerator_removeStatsCollector  (mamaInternal_getStatsGenerator(), impl->mStatsCollector);
            mamaStatsCollector_destroy (impl->mStatsCollector);
            impl->mStatsCollector = NULL;
        }
         if (impl->mQueueName)
            free ((void*)impl->mQueueName);

        impl->mBridgeImpl          = NULL;
        impl->mMamaQueueBridgeImpl = NULL;
        impl->mMsg                 = NULL;

        /* Destroy the counter lock */
        wInterlocked_destroy(&impl->mNumberOpenObjects);

        free (impl);

        mama_log (MAMA_LOG_LEVEL_FINEST, "Leaving mamaQueue_destroy for queue 0x%X.", queue);
        status = MAMA_STATUS_OK;
    }

    return status;
}