OnixS C++ CME iLink 3 Binary Order Entry Handler 1.18.9
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
22#include <limits.h>
23
33
34namespace OnixS
35{
36namespace CME
37{
38namespace iLink3
39{
40// Forward declarations
41class TcpDirectStack;
42namespace AdHoc { struct SessionHelper; };
43
48{
49public:
50 static const UInt64 UndefinedUuid = 0;
51
65 SessionStorage *storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
66
67 Session(SessionReactor & stack, const SessionSettings & settings, int marketSegmentId,
69 SessionStorage * storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
70
72
75
77 std::string id() const;
78
81
83 std::string customKey() const;
84
86 bool negotiated() const;
87
92
95
98
107 Session& connect(const std::string &host, Port port);
108
115 Threading::SharedFuture<void> connectAsync(const std::string & host, Port port);
116
126 Session& disconnect(const std::string &reason = "");
127
133 Threading::SharedFuture<void> disconnectAsync(const std::string & reason = "");
134
140
144 Threading::SharedFuture<void> breakConnectionAsync();
145
156 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
157 Session& send(
158 Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer> &msg,
159 Messaging::Timestamp sendingTime = UtcWatch::now());
160
161#if defined (ONIXS_ILINK3_CXX11)
162
172 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
173 Session& send(
175 Messaging::Timestamp sendingTime = UtcWatch::now());
176
177#endif
178
180 static const size_t CmeMaxPacketSize = 1420;
181
182#if defined (ONIXS_ILINK3_CXX11)
183
199 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
200 Session& send(
202 Messaging::Timestamp sendingTime = UtcWatch::now(),
203 size_t maxPacketSize = CmeMaxPacketSize);
204
222 Messaging::Timestamp sendingTime = UtcWatch::now(),
223 size_t maxPacketSize = CmeMaxPacketSize);
224
225#endif
226
239
251 template <typename SbeMessageType, size_t MaxMessageSize>
254 Messaging::Timestamp sendingTime = UtcWatch::now(),
255 int warmupFlags = 0);
256
257
258#if defined (ONIXS_ILINK3_CXX11)
259
275 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
278 Messaging::Timestamp sendingTime = UtcWatch::now(),
279 size_t maxPacketSize = CmeMaxPacketSize,
280 int warmupFlags = 0);
281
299 size_t maxPacketSize = CmeMaxPacketSize, int warmupFlags = 0);
300#endif
301
309
316 size_t tryThrottle();
317
326 Session & throttlingLimit(size_t messagesCount, size_t intervalInMs = 1000);
327
329 std::string remoteHost() const;
330
332 std::string remoteIpAddress() const;
333
336
338 std::pair<Port, Port> localPortRange() const ONIXS_ILINK3_NOTHROW;
339
341 Session& localPortRange(std::pair<Port, Port> portRange);
342
344 std::string localNetworkInterface() const;
345
347 Session& localNetworkInterface(const std::string &value);
348
351
353 bool tcpNoDelayOption() const;
354
357
360
363
364 static const int UndefinedAffinity = -1;
365
368
371
374
377
380
383
386
389
392
395
398
401
404
407
410
412 Session& receiveSpinningTimeout(unsigned timeoutInUs);
413
416
418 Session& sendSpinningTimeout(unsigned timeoutInUs);
419
424
429
432
443 Session& messageGrouping(unsigned numberOfMessagesToGroup);
444
447
449 const std::string &storageId() const ONIXS_ILINK3_NOTHROW;
450
453
455 Session& outSeqNum(SeqNumber nextOutSeqNum);
456
459
461 Session& inSeqNum(SeqNumber nextExpectedInSeqNum);
462
469
472
480
483
493 Session& reset(bool startOfWeek = false);
494
496 SessionStateId::Enum state() const;
497
500
503
505 unsigned reconnectAttempts() const;
506
509
511 unsigned reconnectInterval() const;
512
514 Session& reconnectInterval(unsigned seconds);
515
517 bool localTimeUsage() const;
518
520 Session& localTimeUsage(bool useLocalTime);
521
523 const std::string &storageDirectory() const;
524
526 bool logBeforeSending() const;
527
530
533
536
538 const Session& log(const std::string &message) const;
539
541 std::string toString() const;
542
545
548
551
554
557
562
565
572
574 static const std::string& version() ONIXS_ILINK3_NOTHROW;
575
576private:
577 Session(const Session& );
578 Session& operator=(const Session& );
579
580 void send(NetworkMessage msg, Messaging::Timestamp ts);
581 void send(NetMessages& msgs, size_t maxPacketSize, Messaging::Timestamp ts);
582 void warmUp(NetworkMessage msg, int warmupFlags, Messaging::Timestamp ts);
583 void warmUp(NetMessages& msgs, size_t maxPacketSize, int warmupFlags, Messaging::Timestamp ts);
584
585 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
586 void validate(const Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer> &msg) const;
587
588 void validateVersion(Messaging::SchemaVersion version) const;
589
590 Session& sendRetransmitRequest(UInt64 uuid, SeqNumber from, SeqNumber to);
591
592 struct Impl;
593 Impl *const impl_;
594
595friend struct AdHoc::SessionHelper;
596};
597
602{
603public:
616 SessionStorage *storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
617
629 CgwSession(SessionReactor & stack, const SessionSettings & settings,
631 SessionStorage * storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
632
633private:
634 int marketSegmentId() const ONIXS_ILINK3_NOTHROW;
635 static const int marketSegmentId_ = INT_MAX;
636};
637
638template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
640Session& Session::send(Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer> &msg, Messaging::Timestamp ts)
641{
642 assert(ts != Messaging::Timestamp());
643
644#ifndef NDEBUG
645 validate(msg);
646#endif
647
648 send(msg.toNetworkMessage(), ts);
649
650 return *this;
651}
652
653template <typename SbeMessageType, size_t MaxMessageSize>
657 Messaging::Timestamp sendingTime,
658 int warmupFlags)
659{
660 warmUp(msg.toNetworkMessage(), warmupFlags, sendingTime);
661
662 return *this;
663}
664
665#if defined (ONIXS_ILINK3_CXX11)
666
667template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
676
677#endif
678
679#if defined (ONIXS_ILINK3_CXX11)
680
681template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
686 size_t maxPacketSize)
687{
688 assert(ts != Messaging::Timestamp());
689
690 send(msgs.netMsgs_, maxPacketSize, ts);
691 return *this;
692}
693
694template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
698 Messaging::Timestamp ts, size_t maxPacketSize, int flags)
699{
700 assert(ts != Messaging::Timestamp());
701
702 warmUp(msgs.netMsgs_, maxPacketSize, flags, ts);
703 return *this;
704}
705
706#endif
707
708template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
710{
711 Messaging::validate(holder);
712 validateVersion(holder->version());
713}
714
715}
716}
717}
#define ONIXS_ILINK3_HOTPATH
Definition Compiler.h:187
#define ONIXS_ILINK3_NULLPTR
Definition Compiler.h:182
#define ONIXS_ILINK3_EXPORTED
Definition Compiler.h:175
#define ONIXS_ILINK3_NOTHROW
Definition Compiler.h:176
CgwSession(SessionReactor &stack, const SessionSettings &settings, SessionListener *listener, SessionStorageType::Enum storageType=SessionStorageType::FileBased, SessionStorage *storage=nullptr, UInt64 uuid=UndefinedUuid, const std::string &customKey="")
Constructor.
CgwSession(const SessionSettings &settings, SessionListener *listener, SessionStorageType::Enum storageType=SessionStorageType::FileBased, SessionStorage *storage=nullptr, UInt64 uuid=UndefinedUuid, const std::string &customKey="")
Constructor.
The class can be used to combine messages with different types to the batch for sending.
Contains the SimpleOpenFramingHeader, the SBE message, and the data buffer.
The time point without the time-zone information.
Definition Time.h:468
Session's network stack reactor interface.
static const UInt64 UndefinedUuid
Definition Session.h:50
Messaging::Timestamp licenseExpirationDate() const
unsigned messageGrouping() const noexcept
std::string localNetworkInterface() const
std::string customKey() const
static const std::string & version() noexcept
Threading::SharedFuture< void > breakConnectionAsync()
Breaks the connection non-gracefully asynchronously.
friend struct AdHoc::SessionHelper
Definition Session.h:595
static const int UndefinedAffinity
Definition Session.h:364
static const size_t CmeMaxPacketSize
CME states: Packet size maximum behavior based on MTU (Maximum Transmission Unit) - 1420 bytes,...
Definition Session.h:180
std::string remoteIpAddress() const
Session & throttle()
Performs the throttling of a session that must be called before each send function call.
Session(SessionReactor &stack, const SessionSettings &settings, int marketSegmentId, SessionListener *listener, SessionStorageType::Enum storageType=SessionStorageType::FileBased, SessionStorage *storage=nullptr, UInt64 uuid=UndefinedUuid, const std::string &customKey="")
std::string toString() const
Session & breakConnection()
Breaks the connection non-gracefully.
std::string remoteHost() const
const SocketOptions & socketOptions() const
unsigned reconnectAttempts() const
bool reportNewMessagesWhileWaitingForMissedMessages() const
Session & throttlingLimit(size_t messagesCount, size_t intervalInMs=1000)
Sets throttling limit parameters.
Messaging::FTI::Enum faultToleranceIndicator() const
SeqNumber outSeqNum() const noexcept
Messaging::SchemaVersion messagingVersion() const noexcept
std::pair< Port, Port > localPortRange() const noexcept
const std::string & storageDirectory() const
size_t incomingMessageGapQueueMaximumSize() const
bool getTcpInfo(TcpInfo &)
Gets information about the underlying TCP connection.
bool detectMessageGapForPreviousUuid() const
Session & sendSequenceMessage(Messaging::KeepAliveLapsed::Enum keepAliveLapsed=Messaging::KeepAliveLapsed::Lapsed)
Send the Sequence message.
unsigned receiveSpinningTimeout() const noexcept
Session & warmUp(Messaging::MessageHolder< SbeMessageType, MaxMessageSize > &msg, Messaging::Timestamp sendingTime=UtcWatch::now(), int warmupFlags=0)
Warms up the sending path.
Definition Session.h:655
Handle socketHandle()
Returns the socket handle which the session uses to transmit data.
Session & receivingThreadAffinity(CpuIndex cpuIndex)
Sets the receiving thread CPU affinity.
int marketSegmentId() const noexcept
unsigned reconnectInterval() const
SessionStorageType::Enum storageType() const noexcept
Messaging::UInt64 previousUuid() const noexcept
UInt64 uuid() const noexcept
size_t outboundQueueBytes()
Returns the total number of bytes in the outbound queue.
const std::string & storageId() const noexcept
Session & send(MessageBatchCombiner &msgs, Messaging::Timestamp sendingTime=UtcWatch::now(), size_t maxPacketSize=CmeMaxPacketSize)
Sends messages.
size_t tryThrottle()
Checks the throttling of a session that must be called before each send function call.
static const Handle InvalidSocketHandle
Represents invalid value of socket handle.
Definition Session.h:556
Session & disconnect(const std::string &reason="")
Terminates the connection.
Messaging::Timestamp creationTime() const noexcept
Session & reset(bool startOfWeek=false)
Backups the current log files, resets the sequence numbers to 1 and generates a new UUID.
SessionStateId::Enum state() const
void flushSessionStorage()
Flushes all internal buffers of the session storage.
SeqNumber inSeqNum() const
Session & send(Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, Messaging::Timestamp sendingTime=UtcWatch::now())
Sends the message.
Definition Session.h:640
int receivingThreadPriority() const
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.
Session & sendingThreadAffinity(CpuIndex cpuIndex)
Sets the sending thread CPU affinity.
Session & connect(const std::string &host, Port port)
Establishes the connection.
SeqNumber previousSeqNo() const noexcept
Session & warmUp(MessageBatchCombiner &msgs, Messaging::Timestamp sendingTime=UtcWatch::now(), size_t maxPacketSize=CmeMaxPacketSize, int warmupFlags=0)
Warms up the sending path.
unsigned sendSpinningTimeout() const noexcept
Session(const SessionSettings &settings, int marketSegmentId, SessionListener *listener, SessionStorageType::Enum storageType=SessionStorageType::FileBased, SessionStorage *storage=nullptr, UInt64 uuid=UndefinedUuid, const std::string &customKey="")
Constructor.
int sendingThreadPolicy() const
Sets the sending thread policy.
Threading::SharedFuture< void > disconnectAsync(const std::string &reason="")
Terminates the connection asynchronously.
Threading::SharedFuture< void > connectAsync(const std::string &host, Port port)
Establishes the connection asynchronously.
A high-level wrapper over the TCPDirect network stack.
void validate(const Message &)
Definition Validation.h:32
MessageHeader::Version SchemaVersion
SBE-encoded data version type.
std::vector< NetworkMessage > NetMessages
unsigned short Port
Definition Defines.h:44
std::vector< SocketOption > SocketOptions
Socket options.
Definition Defines.h:77
int Handle
Type alias for socket handle.
Definition Defines.h:56
std::set< CpuIndex > CpuIndexes
Definition Defines.h:73
Messaging::UInt32 SeqNumber
Definition Messaging.h:60
@ FileBased
File-based Session Storage.
TCP state information.
Definition TcpInfo.h:31