OnixS C++ CME MDP Conflated TCP Handler 1.3.6
API Documentation
Loading...
Searching...
No Matches
Session.h
Go to the documentation of this file.
1/*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19
20#pragma once
21
28
29namespace OnixS
30{
31namespace CME
32{
33namespace ConflatedTCP
34{
39{
40public:
41 static const UInt64 UndefinedUuid = 0;
42
57 SessionStorage *storage = ONIXS_CONFLATEDTCP_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "" );
58
60
62 UInt64 uuid() const;
63
65 const std::string id() const;
66
68 int marketSegmentId() const;
69
71 const std::string customKey() const;
72
81 Session& connect(const std::string &host, Port port);
82
92 Session& disconnect(const std::string &reason = "Terminate");
93
101 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
103
104#if defined(ONIXS_CONFLATEDTCP_CXX11)
105
113 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
115
116#endif
117
118#if defined(ONIXS_CONFLATEDTCP_CXX11)
119
127 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
129
130#endif
131
132#if defined(ONIXS_CONFLATEDTCP_CXX11)
133
141 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
143
144#endif
145
147 std::string remoteHost() const;
148
150 std::string remoteIpAddress() const;
151
154
155 // TODO: move to SessionSettings
156 std::pair<Port, Port> localPortRange() const;
157
158 // TODO: move to SessionSettings
159 Session& localPortRange(std::pair<Port, Port> portRange);
160
162 std::string localNetworkInterface() const;
163
165 Session& localNetworkInterface(const std::string &value);
166
169
171 bool tcpNoDelayOption() const;
172
175
178
181
182 static const int UndefinedAffinity = -1;
183
186
189
192
195
198
201
204
207
210
213
216
219
222
225
227 unsigned receiveSpinningTimeout() const;
228
230 Session& receiveSpinningTimeout(unsigned timeoutInUs);
231
233 unsigned sendSpinningTimeout() const;
234
236 Session& sendSpinningTimeout(unsigned timeoutInUs);
237
242
247
250
253
255 unsigned messageGrouping() const;
256
267 Session& messageGrouping(unsigned numberOfMessagesToGroup);
268
271
273 const std::string &storageId() const;
274
277
279 Session& outSeqNum(SeqNumber nextOutSeqNum);
280
283
285 Session& inSeqNum(SeqNumber nextExpectedInSeqNum);
286
293
296
304
307
317 Session& reset(bool startOfWeek = false);
318
321
324
327
329 unsigned reconnectAttempts() const;
330
333
335 unsigned reconnectInterval() const;
336
338 Session& reconnectInterval(unsigned seconds);
339
341 bool localTimeUsage() const;
342
344 Session& localTimeUsage(bool useLocalTime);
345
347 const std::string &storageDirectory() const;
348
350 bool logBeforeSending() const;
351
354
355 // @TODO: document this method.
357
358 // @TODO: document this method.
360
362 const Session& log(const std::string &message) const;
363
365 std::string toString() const;
366
367private:
368 Session(const Session& );
369 Session& operator=(const Session& );
370
372 void send(std::vector<Messaging::SbeMessage> msgs, std::vector<Messaging::SimpleOpenFramingHeader *> headers);
374
375 struct Impl;
376 Impl *const impl_;
377};
378
379template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
388
389#if defined(ONIXS_CONFLATEDTCP_CXX11)
390
391template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
398
399#endif
400
401#if defined(ONIXS_CONFLATEDTCP_CXX11)
402
403template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
405{
406 std::vector<Messaging::SbeMessage> messages(msgs.size());
407 std::vector<Messaging::SimpleOpenFramingHeader *> headers(msgs.size());
408
409 for (size_t i = 0; i < msgs.size(); ++i)
410 {
411 const Messaging::MessageSize messageSize = msgs[i].setHeader();
412 Messaging::SimpleOpenFramingHeader *const header = msgs[i].header();
413 messages[i] = Messaging::SbeMessage(header + 1, messageSize, Messaging::SbeMessage::NoCheck());
414 headers[i] = header;
415 }
416
417 send(messages, headers);
418
419 return *this;
420}
421
422#endif
423
424#if defined(ONIXS_CONFLATEDTCP_CXX11)
425
426template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
432
433#endif
434
435
436}
437}
438}
#define ONIXS_CONFLATEDTCP_EXPORTED
Definition Compiler.h:175
#define ONIXS_CONFLATEDTCP_NULLPTR
Definition Compiler.h:182
Contains the SimpleOpenFramingHeader, the SBE message, and the data buffer.
const SimpleOpenFramingHeader * header() const noexcept
MessageSize setHeader() noexcept
Calculates the binary size of the message and updates the Simple Open Framing Header accordingly.
The time point without the time-zone information.
Definition Time.h:468
unsigned receiveSpinningTimeout() const
Session & reportNewMessagesWhileWaitingForMissedMessages(bool value)
Sets the option to report new messages even when the message gap is detected, and the reply on the Re...
static const UInt64 UndefinedUuid
Definition Session.h:41
std::string localNetworkInterface() const
static const int UndefinedAffinity
Definition Session.h:182
Session & inSeqNum(SeqNumber nextExpectedInSeqNum)
Sets the expected sequence number of the next inbound message.
std::string remoteIpAddress() const
Session & outSeqNum(SeqNumber nextOutSeqNum)
Sets the sequence number of the next outgoing message.
unsigned sendSpinningTimeout() const
Session & messageGrouping(unsigned numberOfMessagesToGroup)
Sets the number of messages to be sent together.
Session & logBeforeSending(bool value)
Sets the option to log an outgoing message to the session storage before sending it to the wire.
std::string remoteHost() const
const SocketOptions & socketOptions() const
const std::string customKey() const
Session & disconnect(const std::string &reason="Terminate")
Terminates the connection.
Session & incomingMessageGapQueueMaximumSize(size_t value)
Session & localPortRange(std::pair< Port, Port > portRange)
bool reportNewMessagesWhileWaitingForMissedMessages() const
Session & sendSpinningTimeout(unsigned timeoutInUs)
Sets the send spinning timeout value (in microseconds).
Session & reconnectInterval(unsigned seconds)
Sets the time interval between retries to restore the telecommunications link (seconds).
Session & receivingThreadAffinity(const CpuIndexes &cpuIndexes)
Session & receiveSpinningTimeout(unsigned timeoutInUs)
Sets the receive spinning timeout value (in microseconds).
const std::string & storageDirectory() const
size_t incomingMessageGapQueueMaximumSize() const
Session & sendingThreadPolicy(int policy)
Session & reconnectAttempts(unsigned reconnectAttempts)
Sets the maximum number of tries to restore the telecommunications link.
SessionStorageType::Enum storageType() const
const std::string id() const
Session & receivingThreadAffinity(CpuIndex cpuIndex)
Sets the receiving thread CPU affinity.
Session & receivingThreadPriority(int priority)
Sets the scheduling priority of the receiving thread.
Session & sendingThreadAffinity(const CpuIndexes &cpuIndexes)
Sets the sending thread CPU affinity.
Session & localNetworkInterface(const std::string &value)
Sets the IP Address or name of the local network interface.
Session(const SessionSettings &settings, int marketSegmentId, SessionListener *sessionListener, MDP::MarketDataListener *marketDataListener, SessionStorageType::Enum storageType=SessionStorageType::FileBased, SessionStorage *storage=nullptr, UInt64 uuid=UndefinedUuid, const std::string &customKey="")
Constructor.
Session & tcpNoDelayOption(bool value)
Sets the TCP_NODELAY option (improve latency at the expense of message throughput).
Session & localTimeUsage(bool useLocalTime)
Specifies the usage of local time in Handler events and logs files.
Messaging::Timestamp creationTime() const
Session & receivingThreadPolicy(int policy)
Sets the receiving thread policy.
std::pair< Port, Port > localPortRange() const
Session & validateSequenceNumbers(bool validate)
Turns on/off the validation of incoming message sequence numbers.
Session & previousSeqNo(SeqNumber value)
Sets the sequence number of the last business message published by CME with the PreviousUUID.
Session & previousUuid(Messaging::UInt64 value)
Sets the UUID from the previously Established session.
Session & send(Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg)
Sends the message.
Definition Session.h:380
Session & reset(bool startOfWeek=false)
Backups the current log files, resets the sequence numbers to 1 and generates a new UUID.
void flushSessionStorage()
Flushes all internal buffers of the session storage.
const CpuIndexes & receivingThreadAffinity() const
Sets the receiving thread CPU affinity.
const Session & log(const std::string &message) const
Write the given user's message to the Handler's log file using the session formatted Id.
SessionStateId::Enum state()
const std::string & storageId() const
Session & sendingThreadAffinity(CpuIndex cpuIndex)
Sets the sending thread CPU affinity.
Session & connect(const std::string &host, Port port)
Establishes the connection.
Session & socketOptions(const SocketOptions &options)
Sets socket options.
const CpuIndexes & sendingThreadAffinity() const
int sendingThreadPolicy() const
Sets the sending thread policy.
Messaging::UInt64 previousUuid() const
Session & sendingThreadPriority(int priority)
UInt16 MessageSize
Message length type.
Definition Aliases.h:29
std::vector< MessageHolder< MessageTypeT, MaxMessageSize, MessageInitializer > > MessageHolders
unsigned short Port
Definition Defines.h:44
std::vector< SocketOption > SocketOptions
Socket options.
Definition Defines.h:77
std::set< CpuIndex > CpuIndexes
Definition Defines.h:74
Messaging::UInt32 SeqNumber
Definition Messaging.h:58
Callbacks invoked by Handler during market data processing to reflect various stages of processing.