Beispiel #1
0
mama_status
avisBridgeMamaSubscription_destroy (subscriptionBridge subscriber)
{
    mama_status status = MAMA_STATUS_OK;
    wombatQueue   queue = NULL;

    CHECK_SUBSCRIBER(subscriber);

    elvin_subscription_remove_listener(avisSub(subscriber)->mAvisSubscription, avis_callback);

    if (!elvin_unsubscribe(avisSub(subscriber)->mAvis, avisSub(subscriber)->mAvisSubscription)) {
        // NOTE: elvin_unsubscribe sometimes returns failure for no apparent reason, so dont log errors here:
        // 2011-09-02 11:59:10: avis error code=2, error msg=Illegal frame size: 61
        //log_avis_error(MAMA_LOG_LEVEL_ERROR, avisSub(subscriber)->mAvis);
        //status = MAMA_STATUS_PLATFORM;
    }

    free(avisSub(subscriber)->mAvisSubscription);

    mamaQueue_getNativeHandle(avisSub(subscriber)->mQueue, &queue);
    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get event queue.");
        return MAMA_STATUS_PLATFORM;
    }

    wombatQueue_enqueue (queue, destroy_callback,
    		(void*)subscriber, NULL);

    return status;
}
Beispiel #2
0
static void
avis_callback(
    Subscription*   subcription,
    Attributes*     attributes,
    bool            secure,
    void*           subscriber)
{
    wombatQueue queue = NULL;

    /* 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;

    mamaQueue_getNativeHandle(avisSub(subscriber)->mQueue, &queue);
    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get event queue.");
        return;
    }

    wombatQueue_enqueue (queue, avis_queue_callback,
        attributes_clone(attributes), subscriber);

    return;
}
Beispiel #3
0
mama_status
avisBridgeMamaSubscription_destroy (subscriptionBridge subscriber)
{
    mama_status          status        = MAMA_STATUS_OK;
    wombatQueue          queue         = NULL;
    avisTransportBridge* avisTransport = NULL;

    CHECK_SUBSCRIBER(subscriber);

    mamaTransport_getBridgeTransport (
        avisSub(subscriber)->mTransport, (void*) &avisTransport);

    if (!avisTransport)
        return MAMA_STATUS_INVALID_ARG;

    if (avisTransportBridge_isDispatching (avisTransport))
    {
        elvin_invoke (avisSub(subscriber)->mAvis, &unsubscribeAvis, 
                      avisSub(subscriber)->mAvisSubscription);
    }
    else
    {
        unsubscribeAvis (avisSub(subscriber)->mAvis,
                         avisSub(subscriber)->mAvisSubscription);
    }

    avisSub(subscriber)->mAvisSubscription = NULL;
    
    mamaQueue_getNativeHandle(avisSub(subscriber)->mQueue, &queue);

    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avisBridgeMamaSubscription_destroy(): "
                  "Could not get event queue.");
        return MAMA_STATUS_PLATFORM;
    }
                            
    avisSub(subscriber)->mMamaCallback.onDestroy (
        avisSub(subscriber)->mMamaSubscription, 
        avisSub(subscriber)->mClosure);

    wsem_destroy(&avisSub(subscriber)->mCreateDestroySem);

    free(avisSub(subscriber)->mSubject);
    free(avisSub(subscriber));

    return status;
}
Beispiel #4
0
mama_status
mamaIo_create (mamaIo*    result,
               mamaQueue  queue,
               uint32_t   descriptor,
               mamaIoCb   action, 
               mamaIoType ioType,
               void*      closure)
{
    mama_status     status              =   MAMA_STATUS_OK;
    mamaIoImpl*     impl                =   NULL;
    mamaBridgeImpl* bridgeImpl          =   NULL;
    void*           nativeQueueHandle   =   NULL;

    if (!result)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaIo_create(): NULL"
                  "IO address.");
        return MAMA_STATUS_NULL_ARG;
    }

    *result = NULL;

    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaIo_create(): NULL queue.");
        return MAMA_STATUS_INVALID_QUEUE;
    }

    /*Get the bridge impl from the queue - mandatory*/
    bridgeImpl = mamaQueueImpl_getBridgeImpl (queue);

    if (!bridgeImpl)
        return MAMA_STATUS_NO_BRIDGE_IMPL;

    /*Get the native queue handle*/
    mamaQueue_getNativeHandle (queue, &nativeQueueHandle);
    if (!nativeQueueHandle)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaIo_create():"
                  "Could not get native queue handle.");
        return MAMA_STATUS_INVALID_QUEUE;
    }
     
    impl = (mamaIoImpl*)calloc (1, sizeof(mamaIoImpl));

    if (!impl)
        return MAMA_STATUS_NOMEM;

    /*Needed for later bridge invocations*/
    impl->mBridgeImpl = bridgeImpl;

    /*Create the correct corresponding bridge implementation of the io*/
    if (MAMA_STATUS_OK!=(status=bridgeImpl->bridgeMamaIoCreate(
                            &impl->mMamaIoBridgeImpl,
                            nativeQueueHandle,
                            descriptor,
                            action,
                            ioType,
                            (mamaIo)impl,/*Pass this as the parent to the bridge
                                         object*/
                            closure)))
    {
        free (impl);
        return status;
    }
   
    *result = (mamaIo)impl;

    return MAMA_STATUS_OK;
}
mama_status
qpidBridgeMamaSubscription_create (subscriptionBridge* subscriber,
                                   const char*         source,
                                   const char*         symbol,
                                   mamaTransport       tport,
                                   mamaQueue           queue,
                                   mamaMsgCallbacks    callback,
                                   mamaSubscription    subscription,
                                   void*               closure)
{
    qpidSubscription*       impl        = NULL;
    qpidTransportBridge*    transport   = NULL;
    mama_status             status      = MAMA_STATUS_OK;
    pn_data_t*              data        = NULL;

    if ( NULL == subscriber || NULL == subscription || NULL == tport )
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                "qpidBridgeMamaSubscription_create(): something NULL");
        return MAMA_STATUS_NULL_ARG;
    }

    status = mamaTransport_getBridgeTransport (tport,
                                               (transportBridge*) &transport);

    if (MAMA_STATUS_OK != status || NULL == transport)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                "qpidBridgeMamaSubscription_create(): something NULL");
        return MAMA_STATUS_NULL_ARG;
    }

    /* Allocate memory for qpid subscription implementation */
    impl = (qpidSubscription*) calloc (1, sizeof (qpidSubscription));
    if (NULL == impl)
    {
        return MAMA_STATUS_NOMEM;
    }

    mamaQueue_getNativeHandle(queue, &impl->mQpidQueue);
    impl->mMamaCallback        = callback;
    impl->mMamaSubscription    = subscription;
    impl->mMamaQueue           = queue;
    impl->mTransport           = (mamaTransport)transport;
    impl->mSymbol              = symbol;
    impl->mClosure             = closure;
    impl->mIsNotMuted          = 1;
    impl->mIsTportDisconnected = 1;
    impl->mSubjectKey          = NULL;

    /* Use a standard centralized method to determine a topic key */
    qpidBridgeMamaSubscriptionImpl_generateSubjectKey (NULL,
                                                       source,
                                                       symbol,
                                                       &impl->mSubjectKey);

    /* Register the endpoint */
    endpointPool_registerWithoutIdentifier (transport->mSubEndpoints,
                                            impl->mSubjectKey,
                                            &impl->mEndpointIdentifier,
                                            impl);

    /* Notify the publisher that you have an interest in this topic */
    pn_message_clear        (transport->mMsg);

    /* Set the message meta data to reflect a subscription request */
    qpidBridgePublisherImpl_setMessageType (transport->mMsg,
                                            QPID_MSG_SUB_REQUEST);

    /* Set the outgoing address as provided by the transport configuration */
    pn_message_set_address  (transport->mMsg,
                             transport->mOutgoingAddress);

    /* Set the reply address */
    pn_message_set_reply_to (transport->mMsg,
                             transport->mReplyAddress);

    /* Get the proton message's body data for writing */
    data = pn_message_body  (transport->mMsg);

    /* Add in the subject key as the only string inside */
    pn_data_put_string      (data, pn_bytes (strlen (impl->mSubjectKey),
                                             impl->mSubjectKey));

    /* Send out the subscription registration of interest message */
    if (NULL != transport->mOutgoingAddress)
    {
        pn_messenger_put    (transport->mOutgoing, transport->mMsg);

        if (0 != PN_MESSENGER_SEND (transport->mOutgoing))
        {
            const char* qpid_error = PN_MESSENGER_ERROR (transport->mOutgoing);
            mama_log (MAMA_LOG_LEVEL_SEVERE,
                      "qpidBridgeMamaSubscription_create(): "
                      "pn_messenger_send Error:[%s]", qpid_error);
            return MAMA_STATUS_PLATFORM;
        }
    }

    mama_log (MAMA_LOG_LEVEL_FINEST,
              "qpidBridgeMamaSubscription_create(): "
              "created interest for %s.",
              impl->mSubjectKey);

    /* Mark this subscription as valid */
    impl->mIsValid = 1;

    *subscriber =  (subscriptionBridge) impl;

    return MAMA_STATUS_OK;
}