OnixS ICE iMpact Multicast Price Feed Handler C++ library 8.18.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Product Definition Cache Sample

Shows how to warm and reuse a product definition cache. A first Handler runs in receiveProductDefinitionsOnly mode to download the definitions for all subscriptions and store them in the cache directory; two further Handlers then start simultaneously and load the cached definitions instead of downloading them again.

Source code

#include "../Common/Defaults.h"
#include "../Common/ServiceEventTracer.h"
#include "../Common/Utils.h"
#include <cstdlib>
#ifndef _WIN32
# include <pthread.h>
# include <csignal>
# include <cstdio>
# include <vector>
#endif
int main(int /*argc*/, char** /*argv*/)
{
try
{
introduceMyself("Product Definition Cache");
FeedEngineSettings feedEngineSettings;
FeedEngine feedEngine(feedEngineSettings);
HandlerSettings handlerSettings;
// For most of Linux operating systems it would be
// better to define following parameter to be able to
// successfully receive market data from multicast feeds.
handlerSettings.networkInterface = NETWORK_INTERFACE;
// Let's activate logging to get data for support.
handlerSettings.logLevel = LogLevels::Debug;
handlerSettings.logDirectory = LOG_DIRECTORY;
handlerSettings.logFileNamePrefix = LOG_FILE_NAME_PREFIX;
// By default, license is stored in lib folder of the distribute
// package. Instead of copying, let's use original file.
handlerSettings.licenseDirectory = LICENSE_DIRECTORY;
// Enable product definition cache.
handlerSettings.productDefinitionCacheDirectory = PRODUCT_DEFINITION_CACHE_DIRECTORY;
// Allow only product definition receiving.
handlerSettings.receiveProductDefinitionsOnly = true;
// Primary settings - connectivity configuration.
handlerSettings.connectivityConfiguration = AP1_C10Y_FILE;
// Constructs handler with custom license root and enabled logging.
// It will be used to download the product definitions for all market
// subscriptions.
Handler handler(handlerSettings);
// Binds the handler to the feed engine.
handler.bindFeedEngine(feedEngine);
// Traces all service events coming from handlers.
ServiceEventTracer serviceEventTracer;
serviceEventTracer.attachTo(handler);
// Making subscription.
MarketSubscriptions subscriptions;
MarketSubscription ipeGasOilFutures(
);
MarketSubscription brentFutures(
);
subscriptions.insert(ipeGasOilFutures);
subscriptions.insert(brentFutures);
// Start the Handler to download product definitions
// for all market subscriptions and store them in cache.
handler.start(subscriptions);
while (handler.state() != HandlerStates::Stopped)
{
CurrentThread::sleep(1000);
}
// Allow multicast data receiving.
handlerSettings.receiveProductDefinitionsOnly = false;
// Create separate handlers.
handlerSettings.logDirectory = LOG_DIRECTORY "-1";
Handler handler1(handlerSettings);
handler1.bindFeedEngine(feedEngine);
ServiceEventTracer serviceEventTracer1;
serviceEventTracer1.attachTo(handler1);
handlerSettings.logDirectory = LOG_DIRECTORY "-2";
Handler handler2(handlerSettings);
handler2.bindFeedEngine(feedEngine);
ServiceEventTracer serviceEventTracer2;
serviceEventTracer2.attachTo(handler2);
// Start instances simultaneously.
handler1.start(ipeGasOilFutures);
handler2.start(brentFutures);
// Wait until handlers receive all product definitions.
while (
)
{
CurrentThread::sleep(1000);
}
// Stop handlers.
handler1.stop();
handler2.stop();
std::cout << "Done." << std::endl;
}
catch (const std::exception& ex)
{
std::cerr << "Error: " << ex.what() << std::endl;
return EXIT_FAILURE;
}
catch (...)
{
std::cerr << "Unknown exception." << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}