static mama_status mamaQueue_createReuseableMsg (mamaQueueImpl* impl) { mama_status status = MAMA_STATUS_OK; /*Create the reuseable cached mamaMsg for this queue*/ if (MAMA_STATUS_OK != (status = mamaMsgImpl_createForPayload (&(impl->mMsg), NULL,NULL,0))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): " "Could not create message for queue."); mamaQueue_destroy ((mamaQueue)impl); return status; } /*Set the bridge impl structure on the new message. It will be needed for any bridge specific operations.*/ if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setBridgeImpl (impl->mMsg, impl->mBridgeImpl))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): " "Could not set bridge impl on new message."); mamaQueue_destroy ((mamaQueue)impl); return status; } /*We don't want to destroy the bridge message when the mamamsg is * destroyed as we won't own it*/ if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMessageOwner (impl->mMsg, 0))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create():" " Could not set owner on new message."); return status; } /*Associate the queue with the message*/ if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setQueue (impl->mMsg, (mamaQueue)impl))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): " "Could not set queue on new message."); mamaQueue_destroy ((mamaQueue)impl); return status; } return status; }
/* Description: Create a mamaIo, then destroy it. * * Expected Result: MAMA_STATUS_OK */ TEST_F (MamaIoTestC, CreateDestroy) { mamaIo io = NULL; mamaQueue queue = NULL; uint32_t descriptor = 1; mamaIoType ioType = MAMA_IO_READ; ASSERT_EQ (MAMA_STATUS_OK, mamaQueue_create (&queue, mBridge)); ASSERT_EQ (MAMA_STATUS_OK, mamaIo_create (&io, queue, descriptor, onIo, ioType, m_this)); ASSERT_EQ (MAMA_STATUS_OK, mamaIo_destroy (io)); ASSERT_EQ (MAMA_STATUS_OK, mamaQueue_destroy (queue)); }
mama_status mamaQueue_enableStats(mamaQueue queue) { mamaQueueImpl* impl = (mamaQueueImpl *)queue; const char* middleware = NULL; mama_status status = MAMA_STATUS_OK; if (gGenerateQueueStats) { middleware = impl->mBridgeImpl->bridgeGetName(); if (MAMA_STATUS_OK != (status=mamaStatsCollector_create ( &(impl->mStatsCollector), MAMA_STATS_COLLECTOR_TYPE_QUEUE, impl->mQueueName, middleware))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): " "Could not create stats collector."); mamaQueue_destroy ((mamaQueue)impl); return status; } /* Stats are logged by default - requires explicit property not to log */ if (!gLogQueueStats) { if (MAMA_STATUS_OK != (status=mamaStatsCollector_setLog ( impl->mStatsCollector, 0))) { return status; } } /* Stats are not published by default - requires explicit property to publish */ if (gPublishQueueStats) { if (MAMA_STATUS_OK != (status=mamaStatsCollector_setPublish ( impl->mStatsCollector, 1))) { return status; } mama_log (MAMA_LOG_LEVEL_NORMAL, "Stats publishing enabled for queue %s", impl->mQueueName); } status = mamaStat_create (&impl->mInitialStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatInitials.mName, MamaStatInitials.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mRecapStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatRecaps.mName, MamaStatRecaps.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mUnknownMsgStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatUnknownMsgs.mName, MamaStatUnknownMsgs.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mMessageStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatNumMessages.mName, MamaStatNumMessages.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mQueueSizeStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatQueueSize.mName, MamaStatQueueSize.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mSubscriptionStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatNumSubscriptions.mName, MamaStatNumSubscriptions.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mTimeoutStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatTimeouts.mName, MamaStatTimeouts.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mWombatMsgsStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatWombatMsgs.mName, MamaStatWombatMsgs.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mFastMsgsStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatFastMsgs.mName, MamaStatFastMsgs.mFid); if (status != MAMA_STATUS_OK) return status; status = mamaStat_create (&impl->mRvMsgsStat, impl->mStatsCollector, MAMA_STAT_NOT_LOCKABLE, MamaStatRvMsgs.mName, MamaStatRvMsgs.mFid); if (status != MAMA_STATUS_OK) return status; if (mamaInternal_getStatsGenerator()) { if (MAMA_STATUS_OK != ( status=mamaStatsGenerator_addStatsCollector ( mamaInternal_getStatsGenerator(), impl->mStatsCollector))) { mama_log(MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): " "Could not add queue stats collector."); return status; } } mamaStat_setPollCallback (impl->mQueueSizeStat, mamaQueue_pollQueueSizeCb, queue); } return status; }
mama_status mamaQueue_create (mamaQueue* queue, mamaBridge bridgeImpl) { mama_status status = MAMA_STATUS_OK; mamaBridgeImpl* bImpl = (mamaBridgeImpl*)bridgeImpl; mamaQueueImpl* impl = NULL; if (!bridgeImpl) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL bridge."); return MAMA_STATUS_NO_BRIDGE_IMPL; } if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL queue" " address."); return MAMA_STATUS_NULL_ARG; } /*Create the queue structure*/ impl = (mamaQueueImpl*)calloc (1, sizeof (mamaQueueImpl)); if (!impl) return MAMA_STATUS_NOMEM; impl->mBridgeImpl = bImpl; impl->mMamaQueueBridgeImpl = NULL; impl->mDispatcher = NULL; impl->mQueueName = strdup ("NO_NAME"); impl->mHighWatermark = 0; impl->mLowWatermark = 1; impl->mQueueMonitorCallbacks.onQueueHighWatermarkExceeded = NULL; impl->mQueueMonitorCallbacks.onQueueLowWatermark = NULL; impl->mQueueMonitorClosure = NULL; /* Create the counter lock. */ wInterlocked_initialize(&impl->mNumberOpenObjects); wInterlocked_set(0, &impl->mNumberOpenObjects); /* Call the bridge impl specific queue create function*/ if (MAMA_STATUS_OK!=(status=impl->mBridgeImpl->bridgeMamaQueueCreate (&(impl->mMamaQueueBridgeImpl), impl))) { mama_log (MAMA_LOG_LEVEL_ERROR, "Could not create queue bridge."); mamaQueue_destroy ((mamaQueue)impl); return status; } /* Determine if object lock tracking is enabled. */ { const char *propValue = mama_getProperty(MAMAQUEUE_PROPERTY_OBJECT_LOCK_TRACKING); /* Only do this if it's set. */ if(NULL != propValue) { impl->mTrackObjectLocks = strtobool(propValue); } } *queue = (mamaQueue)impl; mamaQueue_enableStats((mamaQueue)impl); return MAMA_STATUS_OK; }
mama_status mamaQueue_create_usingNative (mamaQueue* queue, mamaBridge bridgeImpl, void* nativeQueue) { mama_status status = MAMA_STATUS_OK; mamaBridgeImpl* bImpl = (mamaBridgeImpl*)bridgeImpl; mamaQueueImpl* impl = NULL; char queueName[32]; if (!bridgeImpl) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL bridge."); return MAMA_STATUS_NO_BRIDGE_IMPL; } if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL queue" " address."); return MAMA_STATUS_NULL_ARG; } /* Generate a unique queue name */ snprintf (queueName, sizeof(queueName), "NO_NAME_%d", wInterlocked_increment(&gQueueNumber)); /*Create the queue structure*/ impl = (mamaQueueImpl*)calloc (1, sizeof (mamaQueueImpl)); if (!impl) return MAMA_STATUS_NOMEM; impl->mBridgeImpl = bImpl; impl->mMamaQueueBridgeImpl = NULL; impl->mDispatcher = NULL; impl->mQueueName = strdup (queueName); impl->mHighWatermark = 0; impl->mLowWatermark = 1; impl->mQueueMonitorCallbacks.onQueueHighWatermarkExceeded = NULL; impl->mQueueMonitorCallbacks.onQueueLowWatermark = NULL; impl->mQueueMonitorClosure = NULL; /* Create the counter lock. */ wInterlocked_set(0, &impl->mNumberOpenObjects); mamaQueue_createReuseableMsg(impl); /* Call the bridge impl specific queue create function*/ if (MAMA_STATUS_OK!=(status=impl->mBridgeImpl->bridgeMamaQueueCreateUsingNative (&(impl->mMamaQueueBridgeImpl), impl, nativeQueue))) { mama_log (MAMA_LOG_LEVEL_ERROR, "Could not create queue bridge."); mamaQueue_destroy ((mamaQueue)impl); return status; } *queue = (mamaQueue)impl; return MAMA_STATUS_OK; }