TEST_F(MamaSubscriptionTest, Subscription_RecreateOnDestroy)
{
    // Create a callback object
    TestCallback_RecreateOnDestroy *testCallback = new TestCallback_RecreateOnDestroy(m_bridge, m_transport);
    if(NULL != testCallback)
    {
        // Allocate a subscription
        MamaSubscription *subscription = new MamaSubscription();
        if(NULL != subscription)
        {        
            // Get the default queue
            MamaQueue *queue = Mama::getDefaultEventQueue(m_bridge);

            // Create the subscription
            subscription->create(m_transport, queue, testCallback, "CTA_3", "IBM");

            // Process messages until the first message is received
            Mama::start(m_bridge);

            // Destroy the subscription
            subscription->destroy();    

            // Keep processing messages until the destroy is received
            Mama::start(m_bridge);

            // Delete the subscription
            delete subscription;
        }

        delete testCallback;
    }
}
void MamaSymbolListSubscriber::createSymbolListSubscription ()
{
    MamaSubscription* sub       = NULL;
    const char* symbolListName  = "SYMBOL_LIST_NORMAL";

    sub = new MamaSubscription;
    mSymbolListSubscriptionCallback = new SymbolListSubscriptionCallback (this);

    sub->setSubscriptionType (MAMA_SUBSC_TYPE_SYMBOL_LIST);
    sub->create (mTransport,
                 mDefaultQueue,
                 (SymbolListSubscriptionCallback*)mSymbolListSubscriptionCallback,
                 mSourceName,
                 symbolListName,
                 NULL);
}
void MamaEntitle::subscribeToSymbol (const char* symbol)
{
    static int howMany = 0;

    if (!mDisplayCallback)
    {
        mDisplayCallback = new DisplayCallback (this);
    }
    
    MamaSubscription* sub = NULL;
    sub = new MamaSubscription;
    
    sub->setRetries (3);
    sub->setRequiresInitial (mRequireInitial);
        
    if (mSnapshot)
    {
        sub->setSubscriptionType (MAMA_SUBSC_TYPE_NORMAL);
        sub->setServiceLevel (MAMA_SERVICE_LEVEL_SNAPSHOT, 0);
    }
    else if (mGroupSubscription)
    {
        sub->setSubscriptionType (MAMA_SUBSC_TYPE_GROUP);
        sub->setServiceLevel (MAMA_SERVICE_LEVEL_REAL_TIME, 0);
    }
    else
    {
        sub->setSubscriptionType (MAMA_SUBSC_TYPE_NORMAL);
        sub->setServiceLevel (MAMA_SERVICE_LEVEL_REAL_TIME, 0);
    }
    
    sub->create (
        mTransport,
        mQueueGroup->getNextQueue (),
        (DisplayCallback*)mDisplayCallback,
        mSource,
        symbol,
        NULL);
    
    mSubscriptionList.push_back (sub);

    if (++howMany % 1000 == 0)
    {
        printf ("Subscribed to %d subjects.\n", howMany);
    }
}
void MamaSymbolListSubscriber::subscribeToSymbols ()
{
    mQueueGroup           = new MamaQueueGroup (mThreads, mBridgeImpl);
    mSubscriptionCallback = new SubscriptionCallback (this);

    vector<string>::iterator i;
    for (i=mSubjectList.begin(); i != mSubjectList.end(); i++)
    {
        MamaSubscription* sub = NULL;
        sub = new MamaSubscription;
        string symbol = *(i);

        sub->create (mTransport,
                     mQueueGroup->getNextQueue (),
                     (SubscriptionCallback*)mSubscriptionCallback,
                     mSourceName,
                     symbol.c_str(),
                     NULL);

        mSubscriptionList.push_back (sub);
    }
}
Example #5
0
int main(int argc, const char** argv)
{
    //MamaQueue* mDefaultQueue = NULL;

    const char* symbol = "";
    const char* source = "";
    const char* middleware = "";
    const char* transportname = "";
    const char* output_filename = "";
    const char* symbol_filename = "";
    GzFileHandler* gzfh = NULL;
    set<string> all_symbols;

    int i = 1;

    for (i = 1; i < argc;)
    {
        if (strcmp (argv[i], "-S") == 0)
        {
            source = argv[i + 1];
            i += 2;
        }
        else if (strcmp (argv[i], "-tport") == 0)
        {
            transportname = argv[i + 1];
            i += 2;
        }
        else if (strcmp (argv[i], "-f") == 0)
        {
            char sbuf[128];
            symbol_filename = argv[i + 1];
            i += 2;
            FILE *sfile = fopen(symbol_filename, "r");
            while(fgets(sbuf, 128, sfile) != NULL)
            {
                char* nl_find = strchr(sbuf, '\n');
                if(nl_find != NULL)
                    *nl_find = '\0';
                string str = sbuf;
                all_symbols.insert(sbuf);
            }
        }
        else if (strcmp (argv[i], "-s") == 0)
        {
            symbol = argv[i + 1];
            i += 2;
            all_symbols.insert(symbol);
        }
        else if (strcmp (argv[i], "-m") == 0)
        {
            middleware = argv[i + 1];
            i += 2;
        }
        else if (strcmp (argv[i], "-o") == 0)
        {
            output_filename = argv[i + 1];
            i += 2;
        }
    }

    gzfh = new GzFileHandler(output_filename, GZ_FILE_HANDLER_WRITE);
    t_rmsc = new RecordingMamaSubscriptionCallback(gzfh);
    int number_threads = 1;

    // Load all required bridges at this point
    mBridgeImpl = Mama::loadBridge (middleware);

    // Open up the MAMA api
    Mama::open ();

    Mama::enableLogging (MAMA_LOG_LEVEL_NORMAL, stderr);
    MamaQueue* mDefaultQueue = Mama::getDefaultEventQueue (mBridgeImpl);
    transport = new MamaTransport;
    transport->create(transportname, mBridgeImpl);
    set<string>::iterator it;
    MamaSource* mDictSource = new MamaSource ("WOMBAT", transport, "WOMBAT");

    DictionaryCallback cb (mBridgeImpl);
    MamaDictionary* mDictionary = new MamaDictionary;
    mDictionary->create (mDefaultQueue, &cb, mDictSource, 3, 10);
    Mama::start (mBridgeImpl);
    printf("Writing Dictionary...\n");
    mDictionary->writeToFile("/home/frank/wush/fquinn/openmamacapture/data.dict");
    mQueueGroup = new MamaQueueGroup (number_threads, mBridgeImpl);

    for(it = all_symbols.begin(); it != all_symbols.end(); it++)
    {
        printf("Setting up MAMA Subscription for %s\n", (*it).c_str());
        MamaSubscription* sub = new MamaSubscription;
        mVectorMamaSubscription.push_back(sub);
        sub->create (transport, mQueueGroup->getNextQueue (), (RecordingMamaSubscriptionCallback*)t_rmsc,
                 source, (*it).c_str(), NULL);
    }
    signal(SIGINT, cleanup);
    printf("Starting...\n");
    Mama::start(mBridgeImpl);
}