mama_status avisBridgeMamaQueue_destroy (queueBridge queue) { wombatQueueStatus status = WOMBAT_QUEUE_OK; avisQueueBridge* impl = (avisQueueBridge*) queue; /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Destroy the underlying wombatQueue - can be called from any thread*/ wthread_mutex_lock (&impl->mDispatchLock); status = wombatQueue_destroy (impl->mQueue); wthread_mutex_unlock (&impl->mDispatchLock); /* Free the avisQueueImpl container struct */ free (impl); if (WOMBAT_QUEUE_OK != status) { mama_log (MAMA_LOG_LEVEL_WARN, "avisBridgeMamaQueue_destroy (): " "Failed to destroy wombat queue (%d).", status); return MAMA_STATUS_PLATFORM; } return MAMA_STATUS_OK; }
mama_status avisBridgeMamaQueue_dispatchEvent (queueBridge queue) { wombatQueueStatus status; avisQueueBridge* impl = (avisQueueBridge*) queue; /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Check the watermarks to see if thresholds have been breached */ avisBridgeMamaQueueImpl_checkWatermarks (impl); /* Attempt to dispatch the queue with a timeout once */ status = wombatQueue_dispatch (impl->mQueue, NULL, NULL); /* If dispatch failed, report here */ if (WOMBAT_QUEUE_OK != status && WOMBAT_QUEUE_TIMEOUT != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridgeMamaQueue_dispatchEvent (): " "Failed to dispatch Avis Middleware queue (%d).", status); return MAMA_STATUS_PLATFORM; } return MAMA_STATUS_OK; }
static void* main_loop_routine(void* arg) { int rc; Notification notification; while (loop_count--) { rc = SEND(request_queue, request); CHECK_QUEUE(rc); if (rc == QREMOVED) { fprintf(stderr, "%s\n", queue_removed); break; } else { CHECK_VALUE(rc, QSUCCESS, rc); } pthread_cleanup_push(cancel_server_thread, NULL); rc = RECEIVE(notify_client_queue, notification, (long) getpid()); CHECK_QUEUE(rc); if (rc == QREMOVED) { fprintf(stderr, "%s\n", queue_removed); break; } else { CHECK_VALUE(rc, QSUCCESS, rc); } sleep(sleep_time); rc = SEND(notify_server_queue, notification); CHECK_QUEUE(rc); if (rc == QREMOVED) { fprintf(stderr, "%s\n", queue_removed); break; } else { CHECK_VALUE(rc, QSUCCESS, rc); } pthread_cleanup_pop(false); } synchronized_cancel(&signal_handler); return NULL; }
mama_status avisBridgeMamaQueue_stopDispatch (queueBridge queue) { avisQueueBridge* impl = (avisQueueBridge*) queue; /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Tell this implementation to stop dispatching */ impl->mIsDispatching = 0; return MAMA_STATUS_OK; }
mama_status avisBridgeMamaQueue_removeEnqueueCallback (queueBridge queue) { avisQueueBridge* impl = (avisQueueBridge*) queue; /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Set the enqueue callback to NULL */ impl->mEnqueueCallback = NULL; impl->mEnqueueClosure = NULL; return MAMA_STATUS_OK; }
mama_status avisBridgeMamaQueue_dispatch (queueBridge queue) { wombatQueueStatus status; avisQueueBridge* impl = (avisQueueBridge*) queue; /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Lock for dispatching */ wthread_mutex_lock (&impl->mDispatchLock); impl->mIsDispatching = 1; /* * Continually dispatch as long as the calling application wants dispatching * to be done and no errors are encountered */ do { /* Check the watermarks to see if thresholds have been breached */ avisBridgeMamaQueueImpl_checkWatermarks (impl); /* * Perform a dispatch with a timeout to allow the dispatching process * to be interrupted by the calling application between iterations */ status = wombatQueue_timedDispatch (impl->mQueue, NULL, NULL, AVIS_QUEUE_DISPATCH_TIMEOUT); } while ( (WOMBAT_QUEUE_OK == status || WOMBAT_QUEUE_TIMEOUT == status) && impl->mIsDispatching); /* Unlock the dispatch lock */ wthread_mutex_unlock (&impl->mDispatchLock); /* Timeout is encountered after each dispatch and so is expected here */ if (WOMBAT_QUEUE_OK != status && WOMBAT_QUEUE_TIMEOUT != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridgeMamaQueue_dispatch (): " "Failed to dispatch Avis Middleware queue (%d). ", status); return MAMA_STATUS_PLATFORM; } return MAMA_STATUS_OK; }
static void cancel_server_thread(void* arg) { Notification notification; int rc; notification.pid = getpid(); notification.type = FROM_CLIENT; rc = SEND(terminate_queue, notification); CHECK_QUEUE(rc); if (rc == QREMOVED) { fprintf(stderr, "%s\n", queue_removed); } else { CHECK_VALUE(rc, QSUCCESS, rc); } }
mama_status avisBridgeMamaQueue_setLowWatermark (queueBridge queue, size_t lowWatermark) { avisQueueBridge* impl = (avisQueueBridge*) queue; if (0 == lowWatermark) { return MAMA_STATUS_NULL_ARG; } /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Set the low water mark */ impl->mLowWatermark = lowWatermark; return MAMA_STATUS_OK; }
mama_status zmqBridgeMamaQueue_setHighWatermark (queueBridge queue, size_t highWatermark) { zmqQueueBridge* impl = (zmqQueueBridge*) queue; if (0 == highWatermark) { return MAMA_STATUS_NULL_ARG; } /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Set the high water mark */ impl->mHighWatermark = highWatermark; return MAMA_STATUS_OK; }
mama_status avisBridgeMamaQueue_getNativeHandle (queueBridge queue, void** nativeHandle) { avisQueueBridge* impl = (avisQueueBridge*) queue; if (NULL == nativeHandle) { return MAMA_STATUS_NULL_ARG; } /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Return the handle to the native queue */ *nativeHandle = queue; return MAMA_STATUS_OK; }
mama_status avisBridgeMamaQueue_setEnqueueCallback (queueBridge queue, mamaQueueEnqueueCB callback, void* closure) { avisQueueBridge* impl = (avisQueueBridge*) queue; if (NULL == callback) { return MAMA_STATUS_NULL_ARG; } /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Set the enqueue callback and closure */ impl->mEnqueueCallback = callback; impl->mEnqueueClosure = closure; return MAMA_STATUS_OK; }
mama_status avisBridgeMamaQueue_getEventCount (queueBridge queue, size_t* count) { avisQueueBridge* impl = (avisQueueBridge*) queue; int countInt = 0; if (NULL == count) return MAMA_STATUS_NULL_ARG; /* Perform null checks and return if null arguments provided */ CHECK_QUEUE(impl); /* Initialize count to zero */ *count = 0; /* Get the wombatQueue size */ wombatQueue_getSize (impl->mQueue, &countInt); *count = (size_t)countInt; return MAMA_STATUS_OK; }
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; }