static void MAMACALLTYPE dqPublisherImplMsgCb (mamaSubscription subsc, mamaMsg msg, void* closure, void* itemClosure) { mama_i32_t msgType = 0; mama_i32_t subType = 0; const char* symbol = NULL; mama_status status = MAMA_STATUS_NOT_FOUND; mamaPublishTopic* info = NULL; mamaDQPublisherManagerImpl* impl = (mamaDQPublisherManagerImpl*) (closure); if (mamaMsg_getI32 (msg, MamaFieldSubscriptionType.mName, MamaFieldSubscriptionType.mFid, &subType) == MAMA_STATUS_OK) { if (mamaMsg_getString (msg, MamaFieldSubscSymbol.mName, MamaFieldSubscSymbol.mFid, &symbol) != MAMA_STATUS_OK) { if (mamaMsg_getSendSubject (msg, &symbol) != MAMA_STATUS_OK) { impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl, status, "No symbol", msg); return; } } if (mamaMsg_getI32 (msg, MamaFieldSubscMsgType.mName, MamaFieldSubscMsgType.mFid, &msgType) != MAMA_STATUS_OK) { impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl, status, "NO msg type", msg); return; } if ((info = wtable_lookup (impl->mPublisherMap, (symbol)))) { switch (msgType) { case MAMA_SUBSC_REFRESH: if (!impl->mRefreshResponseMsg) { mamaMsg_create(&impl->mRefreshResponseMsg); mamaMsg_addU8(impl->mRefreshResponseMsg, NULL, MamaFieldMsgStatus.mFid, MAMA_MSG_STATUS_MISC); mamaMsg_addU8(impl->mRefreshResponseMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_REFRESH); } mamaDQPublisher_send(info->pub, impl->mRefreshResponseMsg); impl->mUserCallbacks.onRefresh((mamaDQPublisherManager)impl, info, subType, msgType, msg ); break; default: impl->mUserCallbacks.onRequest ((mamaDQPublisherManager)impl, info, subType, msgType, msg); break; } } else { impl->mUserCallbacks.onNewRequest ((mamaDQPublisherManager)impl, symbol, subType, msgType, msg); } } else { if (impl->mUserCallbacks.onMsg) impl->mUserCallbacks.onMsg ((mamaDQPublisherManager)impl, msg); } }
void MAMACALLTYPE subscriptionOnMsg (mamaSubscription subscription, mamaMsg msg, void *closure, void *itemClosure) { pubCache* cache = (pubCache*) closure; switch (mamaMsgType_typeForMsg (msg)) { case MAMA_MSG_TYPE_DELETE: case MAMA_MSG_TYPE_EXPIRE: mamaSubscription_destroy (subscription); mamaSubscription_deallocate (subscription); if (cache->pub) mamaDQPublisher_send(cache->pub, msg); cache->sub = NULL; return; default: break; } switch (mamaMsgStatus_statusForMsg (msg)) { case MAMA_MSG_STATUS_BAD_SYMBOL: case MAMA_MSG_STATUS_EXPIRED: case MAMA_MSG_STATUS_TIMEOUT: mamaSubscription_destroy (subscription); mamaSubscription_deallocate (subscription); if (cache->pub) mamaDQPublisher_send(cache->pub, msg); cache->sub = NULL; return; default: break; } mamaMsg_applyMsg(cache->cachedMsg, msg); if (cache->pub) { mamaDQPublisher_setStatus(cache->pub, mamaMsgStatus_statusForMsg (msg)); mamaDQPublisher_send(cache->pub, msg); } fflush(stdout); }
static void MAMACALLTYPE subscriptionHandlerOnRequestCb (mamaDQPublisherManager manager, mamaPublishTopic* publishTopicInfo, short subType, short msgType, mamaMsg msg) { int index =0; mama_log (MAMA_LOG_LEVEL_NORMAL, "Received request: %s", publishTopicInfo->symbol); switch (msgType) { case MAMA_SUBSC_SUBSCRIBE: case MAMA_SUBSC_SNAPSHOT: index = ((pubCache*) publishTopicInfo->cache)->index; if (subType == MAMA_SUBSC_TYPE_BOOK) { mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_BOOK_INITIAL); } else { mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL); } mamaDQPublisher_sendReply (gSubscriptionList[index].pub, msg, gSubscriptionList[index].cachedMsg); break; case MAMA_SUBSC_DQ_SUBSCRIBER: case MAMA_SUBSC_DQ_PUBLISHER: case MAMA_SUBSC_DQ_NETWORK: case MAMA_SUBSC_DQ_UNKNOWN: case MAMA_SUBSC_DQ_GROUP_SUBSCRIBER: index = (int) ((pubCache*)publishTopicInfo->cache)->index; mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_RECAP); mamaDQPublisher_send (gSubscriptionList[index].pub, gSubscriptionList[index].cachedMsg); break; case MAMA_SUBSC_UNSUBSCRIBE: case MAMA_SUBSC_RESUBSCRIBE: case MAMA_SUBSC_REFRESH: default: break; } }
static void MAMACALLTYPE sendRecap (mamaQueue queue, void* closure) { recapInfo* info = (recapInfo*) closure; mamaMsg_updateU8(gSubscriptionList[info->index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL); if (info->msg) { mamaDQPublisher_sendReply(gSubscriptionList[info->index].pub, info->msg, gSubscriptionList[info->index].cachedMsg); mamaMsg_destroy( info->msg); } else mamaDQPublisher_send(gSubscriptionList[info->index].pub, gSubscriptionList[info->index].cachedMsg); free (info); }
void MamaDQPublisher::send (MamaMsg* msg) { mamaDQPublisher_send(mImpl->mDQPublisher, msg->getUnderlyingMsg()); }
static void MAMACALLTYPE subscriptionHandlerOnNewRequestCb (mamaDQPublisherManager manager, const char* symbol, short subType, short msgType, mamaMsg msg) { int index = 0; char* headerString; char *temp; char * source; mamaMsg newMessage; for (index=0; index < gNumSymbols; index++) { if (strcmp (gSubscriptionList[index].symbol, symbol) == 0) break; } if (index == gNumSymbols) { mama_log (MAMA_LOG_LEVEL_WARN, "Received request for unknown symbol: %s", symbol); return; } mama_log (MAMA_LOG_LEVEL_NORMAL, "Received new request: %s", symbol); mamaDQPublisherManager_createPublisher (manager, symbol, (void*)&gSubscriptionList[index], &gSubscriptionList[index].pub); mamaPlaybackFileParser_allocate (&gSubscriptionList[index].fileParser); mamaPlaybackFileParser_openFile(gSubscriptionList[index].fileParser, (char*)gFilename); mamaMsg_create(&gSubscriptionList[index].cachedMsg); while (mamaPlaybackFileParser_getNextHeader(gSubscriptionList[index].fileParser, &headerString)) { /* skip source and transport name */ temp = strchr (headerString,DELIM); temp++; source = strchr (temp,DELIM); source++; /* skip : */ temp = strchr (source,DELIM); if ((strncmp (gSubscriptionList[index].symbol, source, temp-source) == 0) && (strlen(gSubscriptionList[index].symbol) == temp-source)) break; mamaPlaybackFileParser_getNextMsg (gSubscriptionList[index].fileParser, &newMessage); } if (mamaPlaybackFileParser_getNextMsg (gSubscriptionList[index].fileParser, &newMessage)) { mamaMsg_applyMsg (gSubscriptionList[index].cachedMsg, newMessage); switch (msgType) { case MAMA_SUBSC_SUBSCRIBE: case MAMA_SUBSC_SNAPSHOT: if (subType == MAMA_SUBSC_TYPE_BOOK) { mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_BOOK_INITIAL); } else { mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL); } mamaDQPublisher_sendReply (gSubscriptionList[index].pub, msg, gSubscriptionList[index].cachedMsg); break; default: mama_log (MAMA_LOG_LEVEL_NORMAL, "Publishing MAMA_MSG_TYPE_RECAP"); mamaMsg_updateU8 (gSubscriptionList[index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_RECAP); mamaDQPublisher_send (gSubscriptionList[index].pub, gSubscriptionList[index].cachedMsg); break; } } }
static void MAMACALLTYPE pubCallback (mamaTimer timer, void* closure) { int index =0; char*temp=NULL; char*source=NULL; char* headerString = NULL; mamaMsg newMessage; mama_status status = MAMA_STATUS_OK; for (index=0; index < gNumSymbols; index++) { if (gSubscriptionList[index].fileParser) { int header = 1; while ((header = mamaPlaybackFileParser_getNextHeader ( gSubscriptionList[index].fileParser, &headerString))) { if (strlen (headerString) == 0) continue; /*skip source and transport name*/ temp = strchr (headerString,DELIM); temp++; source = strchr (temp,DELIM); source++; /*skip :*/ temp = strchr (source, DELIM); if (mamaPlaybackFileParser_getNextMsg ( gSubscriptionList[index].fileParser, &newMessage)) { int symLength = temp - source; if (0 == strncmp (gSubscriptionList[index].symbol, source, symLength) && symLength == (strlen (gSubscriptionList[index].symbol)) ) { mamaMsg_applyMsg (gSubscriptionList[index].cachedMsg, newMessage); mama_log (MAMA_LOG_LEVEL_FINEST, "Publishing message: %s", mamaMsg_toString(newMessage)); mamaDQPublisher_send (gSubscriptionList[index].pub, newMessage); break; } } } if (gRewind && !header) { mama_log (MAMA_LOG_LEVEL_FINE, "End of file reached for symbol %s - Rewinding.", gSubscriptionList[index].symbol); status = mamaPlaybackFileParser_rewindFile( gSubscriptionList[index].fileParser); if (MAMA_STATUS_OK != status) { mama_log(MAMA_LOG_LEVEL_FINE, "Failed to rewind file %s", mamaStatus_stringForStatus(status)); } } else if (!header) { mama_log (MAMA_LOG_LEVEL_FINE, "End of file reached for symbol %s.", gSubscriptionList[index].symbol); } } } }