Files

577 lines
16 KiB
C++

// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
//
// This software owned by Onix Solutions Limited [OnixS] and is
// protected by copyright law and international copyright treaties.
//
// Access to and use of the software is governed by the terms of the applicable
// OnixS Software Services Agreement (the Agreement) and Customer end user license
// agreements granting a non-assignable, non-transferable and non-exclusive license
// to use the software for it's own data processing purposes under the terms defined
// in the Agreement.
//
// Except as otherwise granted within the terms of the Agreement, copying or
// reproduction of any part of this source code or associated reference material
// to any other location for further reproduction or redistribution, and any
// amendments to this copyright notice, are expressly prohibited.
//
// Any reproduction or redistribution for sale or hiring of the Software not in
// accordance with the terms of the Agreement is a violation of copyright law.
//
#pragma once
#include <string>
#include <OnixS/CME/MDH/Integral.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Collection of parameters common for all types of feeds.
template
<
typename Layout
>
class FeedSettingsBase
{
Layout layout_;
UInt32 heartbeatInterval_;
std::string feedANetworkInterfaces_;
std::string feedBNetworkInterfaces_;
protected:
/// Initializes instance with default values.
FeedSettingsBase(
Layout layout,
UInt32 heartbeat)
: layout_(layout)
, heartbeatInterval_(heartbeat)
{
}
public:
/// Defines feed layout for a feed group.
Layout layout() const
{
return layout_;
}
/// Defines feed layout for recovery feed group.
void layout(Layout value)
{
layout_ = value;
}
/// Specifies maximal time interval between two
/// network packets. If no data is received during
/// specified time frame, corresponding event is raised
/// and further behavior is defined by feed layout.
///
/// Interval is measured in seconds.
UInt32 heartbeatInterval() const
{
return heartbeatInterval_;
}
/// Specifies maximal time interval between two packets.
void heartbeatInterval(UInt32 value)
{
heartbeatInterval_ = value;
}
/// Specifies one or more network interfaces to use for
/// "A" feeds while joining the multicast group; use
/// semi-colon delimited list if more than one.
///
/// @note On Linux the network interface is specified
/// by its name, on Windows - by IP address.
///
/// @note If the value is empty or absent then the
/// Settings::networkInterface value is used.
const
std::string&
feedANetworkInterfaces() const
{
return feedANetworkInterfaces_;
}
/// Specifies one or more network interfaces to use for
/// "A" feeds while joining the multicast group; use
/// semi-colon delimited list if more than one.
void
feedANetworkInterfaces(
const std::string& interfaces)
{
feedANetworkInterfaces_ = interfaces;
}
/// Specifies one or more network interfaces to use for "B"
/// feeds while joining the multicast group; use semi-colon
/// delimited list if more than one.
///
/// @note On Linux the network interface is specified by
/// its name, on Windows - by IP address.
///
/// @note If the value is empty or absent then the
/// Settings::networkInterface value is used.
const
std::string&
feedBNetworkInterfaces() const
{
return feedBNetworkInterfaces_;
}
/// Specifies one or more network interfaces to use for
/// "B" feeds while joining the multicast group; use
/// semi-colon delimited list if more than one.
void
feedBNetworkInterfaces(
const std::string& interfaces)
{
feedBNetworkInterfaces_ = interfaces;
}
};
/// Defines feed layout alternates available for
/// recovery feeds like instrument and snapshot.
ONIXS_CMEMDH_LTWT_STRUCT RecoveryFeedLayout
{
/// Integral type used as basement for constants.
typedef UInt32 Base;
enum Enum
{
/// Indicates only feed A is used as source for market data.
FeedAOnly,
/// Indicates only feed B is used as source for market data.
FeedBOnly,
/// Feed A is used as primary source of market data. If Handler
/// detects absence of market data on feed A, it switches to
/// feed B to continue market data processing. Feed B is used
/// by Handler until market data absence is detected on it. In
/// that case Handler will switch back to feed A. In other words,
/// this layout instructs Handler to cycle between feeds if data
/// absence is detected starting from feed A.
FeedAWithFailoverToFeedB,
/// Feed B is used as primary source of market data. If Handler
/// detects absence of market data on feed B, it switches to
/// feed A to continue market data processing. Feed A is used
/// by Handler until market data absence is detected on it. In
/// that case Handler will switch back to feed B. In other words,
/// this layout instructs Handler to cycle between feeds if data
/// absence is detected starting from feed B.
FeedBWithFailoverToFeedA
};
};
/// Appends string presentation of feed layout.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
RecoveryFeedLayout::Enum);
/// Returns string presentation of feed layout.
inline
std::string
toStr(
RecoveryFeedLayout::Enum layout)
{
std::string str;
toStr(str, layout);
return str;
}
/// Collection of parameters affecting recovery feeds behavior.
ONIXS_CMEMDH_LTWT_CLASS
RecoveryFeedSettings
: public FeedSettingsBase
<
RecoveryFeedLayout::Enum
>
{
public:
/// Initializes instance with default values.
///
/// By default, feed A is used as the primary source
/// of market recovery data with fail-over to the feed B.
/// Heartbeats are expected within 30 seconds periodicy.
RecoveryFeedSettings()
: FeedSettingsBase<RecoveryFeedLayout::Enum>(
RecoveryFeedLayout::
FeedAWithFailoverToFeedB,
30)
{
}
};
/// Serializes feed settings into string.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
const RecoveryFeedSettings&);
/// Serializes feed settings into string.
inline
std::string
toStr(
const RecoveryFeedSettings& settings)
{
std::string str;
toStr(str, settings);
return str;
}
/// Defines feed layout alternates available
/// for real-time feed like incremental one.
ONIXS_CMEMDH_LTWT_STRUCT RealtimeFeedLayout
{
/// Integral type used as basement for constants.
typedef UInt32 Base;
enum Enum
{
/// Indicates only feed A is used as source for market data.
FeedAOnly,
/// Indicates only feed B is used as source for market data.
FeedBOnly,
/// Feed A is used as primary source of market data. If Handler
/// detects absence of market data on feed A, it switches to
/// feed B to continue market data processing. Feed B is used
/// by Handler until market data absence is detected on it. In
/// that case Handler will switch back to feed A. In other words,
/// this layout instructs Handler to cycle between feeds if data
/// absence is detected starting from feed A.
FeedAWithFailoverToFeedB,
/// Feed B is used as primary source of market data. If Handler
/// detects absence of market data on feed B, it switches to
/// feed A to continue market data processing. Feed A is used
/// by Handler until market data absence is detected on it. In
/// that case Handler will switch back to feed B. In other words,
/// this layout instructs Handler to cycle between feeds if data
/// absence is detected starting from feed B.
FeedBWithFailoverToFeedA,
/// Handler arbitrates between both feeds A and B.
BothFeedsWithArbitrage
};
};
/// Appends string presentation of feed layout.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
RealtimeFeedLayout::Enum);
/// Returns string presentation of feed layout.
inline
std::string
toStr(
RealtimeFeedLayout::Enum layout)
{
std::string str;
toStr(str, layout);
return str;
}
/// Collection of parameters affecting real-time feeds behavior.
ONIXS_CMEMDH_LTWT_CLASS
RealtimeFeedSettings
: public FeedSettingsBase
<
RealtimeFeedLayout::Enum
>
{
UInt32 outOfOrderPacketMaxInterval_;
UInt32 lostPacketWaitTime_;
public:
/// Initializes instance with default values.
///
/// By default, arbitrage between feeds A and B is done.
/// Heartbeats are expected within 30 seconds periodicy.
RealtimeFeedSettings()
: FeedSettingsBase<RealtimeFeedLayout::Enum>(
RealtimeFeedLayout::
BothFeedsWithArbitrage,
30)
, outOfOrderPacketMaxInterval_(3)
, lostPacketWaitTime_(100000)
{
}
/// Defines value of threshold used by Handler to differ
/// out-of-order packets from gaps.
///
/// Due to unreliable nature of multicast, packets transmitted by MDP
/// may be received in the order different to original. To differ the
/// case when Handler received out-of-order packets from the case when
/// some of packets were completely lost, Handler uses given parameter.
/// It defines size of interval for incoming packets starting from the
/// last received. Packet is considered as out-of-order if its sequence
/// number fits into interval [seqNumberOfLastReceivedPacket,
/// seqNumberOfLastReceivedPacket + outOfOrderPacketsMaxInterval].
/// In that case Handler waits for other packets to fulfill the incoming
/// sequence. If received packet has greater sequence number than
/// 'seqNumberOfLastReceivedPacket + outOfOrderPacketsMaxInterval',
/// then Handler makes a decision on packets lost and gap is reported.
///
/// @note When out-of-order packet is received, Handler makes a decision
/// on data loss if either waiting time is over or if newly received packet
/// has sequence number greater than 'seqNumberOfLastReceivedPacket +
/// outOfOrderPacketMaxInterval'.
///
/// @see 'lostPacketWaitTime' parameter for more information.
///
/// @note The default value is '3'.
UInt32 outOfOrderPacketMaxInterval() const
{
return outOfOrderPacketMaxInterval_;
}
/// Defines value of threshold used by Handler
/// to differ out-of-order packets from gaps.
void outOfOrderPacketMaxInterval(UInt32 value)
{
outOfOrderPacketMaxInterval_ = value;
}
/// Indicates for how long Handler should wait for
/// the packet before it's considered as totally lost.
///
/// Due to unreliable nature of multicast, data transmitted by MDP
/// may come in order other than original or be completely lost. When
/// Handler receives packet with sequence number greater than expected,
/// it considers received data as out-of-order. If for a certain time
/// interval Handler receives missing data, Handler resumes normal data
/// processing. However, if no data is received for predefined time frame,
/// Handler considers missing data as lost and raises packet gap event.
/// Given parameter defines size of time interval Handler waits for missing
/// data.
///
/// @note When out-of-order packet is received, Handler makes a decision
/// on data loss if either waiting time is over or if newly received packet
/// has sequence number greater than 'seqNumberOfLastReceivedPacket +
/// outOfOrderPacketMaxInterval'.
///
/// @see 'outOfOrderPacketMaxInterval' parameter for more information.
///
/// Time interval is measured in microseconds (usec).
///
/// @note The default value is '100000' (100 milliseconds).
UInt32 lostPacketWaitTime() const
{
return lostPacketWaitTime_;
}
/// Indicates for how long Handler should wait for
/// the packet before it's considered as totally lost.
void lostPacketWaitTime(UInt32 value)
{
lostPacketWaitTime_ = value;
}
};
/// Serializes feed settings into string.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
const RealtimeFeedSettings&);
/// Serializes feed settings into string.
inline
std::string
toStr(
const RealtimeFeedSettings& settings)
{
std::string str;
toStr(str, settings);
return str;
}
// Parameters affecting all feeds involved into market data processing.
ONIXS_CMEMDH_LTWT_CLASS FeedSettings
{
std::string connectivityConfigurationFile_;
UInt16 maxPacketSize_;
RecoveryFeedSettings instrumentFeeds_;
RealtimeFeedSettings incrementalFeeds_;
RecoveryFeedSettings snapshotFeeds_;
RecoveryFeedSettings mboSnapshotFeeds_;
public:
/// Initializes instance with default values.
FeedSettings()
: maxPacketSize_(1420)
{
}
/// Path to the connectivity configuration file.
const
std::string&
connectivityConfigurationFile() const
{
return connectivityConfigurationFile_;
}
/// Sets path to the connectivity configuration file.
void
connectivityConfigurationFile(
const std::string& configurationFile)
{
connectivityConfigurationFile_ = configurationFile;
}
/// Specifies one or more network interfaces to use for
/// "A" feeds while joining the multicast group; use
/// semi-colon delimited list if more than one.
void
feedANetworkInterfaces(
const std::string& interfaces)
{
instrumentFeeds_.
feedANetworkInterfaces
(interfaces);
incrementalFeeds_.
feedANetworkInterfaces
(interfaces);
snapshotFeeds_.
feedANetworkInterfaces
(interfaces);
mboSnapshotFeeds_.
feedANetworkInterfaces
(interfaces);
}
/// Specifies one or more network interfaces to use for
/// "B" feeds while joining the multicast group; use
/// semi-colon delimited list if more than one.
void
feedBNetworkInterfaces(
const std::string& interfaces)
{
instrumentFeeds_.
feedBNetworkInterfaces
(interfaces);
incrementalFeeds_.
feedBNetworkInterfaces
(interfaces);
snapshotFeeds_.
feedBNetworkInterfaces
(interfaces);
mboSnapshotFeeds_.
feedBNetworkInterfaces
(interfaces);
}
/// Max size for network packet transmitted by MDP.
///
/// @note Default value is '1420'.
UInt16 maxPacketSize() const
{
return maxPacketSize_;
}
/// Max size for network packet transmitted by MDP.
void maxPacketSize(UInt16 value)
{
maxPacketSize_ = value;
}
/// Reference to parameters affecting instrument feeds.
const RecoveryFeedSettings& instrumentFeeds() const
{
return instrumentFeeds_;
}
/// Reference to parameters affecting instrument feeds.
RecoveryFeedSettings& instrumentFeeds()
{
return instrumentFeeds_;
}
/// Reference to parameters affecting incremental feeds.
const RealtimeFeedSettings& incrementalFeeds() const
{
return incrementalFeeds_;
}
/// Reference to parameters affecting incremental feeds.
RealtimeFeedSettings& incrementalFeeds()
{
return incrementalFeeds_;
}
/// Reference to parameters affecting snapshot feeds.
const RecoveryFeedSettings& snapshotFeeds() const
{
return snapshotFeeds_;
}
/// Reference to parameters affecting snapshot feeds.
RecoveryFeedSettings& snapshotFeeds()
{
return snapshotFeeds_;
}
/// Reference to parameters affecting snapshot feeds.
const RecoveryFeedSettings& mboSnapshotFeeds() const
{
return mboSnapshotFeeds_;
}
/// Reference to parameters affecting snapshot feeds.
RecoveryFeedSettings& mboSnapshotFeeds()
{
return mboSnapshotFeeds_;
}
};
/// Serializes feed settings into string.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
const FeedSettings&);
/// Serializes feed settings into string.
inline
std::string
toStr(
const FeedSettings& settings)
{
std::string str;
toStr(str, settings);
return str;
}
ONIXS_CMEMDH_NAMESPACE_END