OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
Pluggable Storage Sample

This sample demonstrates how to use a pluggable session storage.

Source code

PluggableStorage.cpp

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 */
20
21#include <iostream>
22
23using namespace ONIXS_ICEBOE_NAMESPACE;
25
26#include "MySessionStorage.h"
27
28#include <Settings/Defaults.h>
29#include <Common/Helpers.h>
30#include <Common/Listener.h>
31#include <Common/Settings.h>
32#include <Common/Signal.h>
33#include <Common/Emulator.h>
34
35using namespace Samples;
36
37int main(int argc, char* argv[])
38{
39 // `--help` to show options.
41
42 try
43 {
45
46 auto settings = fillSettings(cfg);
47 const auto emulator = createEmulator(settings, cfg);
48
49 // Request Binary Order Gateway credentials from Binary Utility Service Gateway.
50 const auto bgwCredentials = receiveBgwCredentials(settings, cfg.host(), cfg.port());
51
52 MySessionStorage storage;
53 Listener listener;
54
55 // A 'BGW' session.
56 BgwSession bgwSession(settings, &listener, SessionStorageType::Pluggable, &storage);
57
58 bgwSession.connect(bgwCredentials);
59 bgwSession.send(Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()));
60
61 Samples::wait(listener.traderLoggedOn).get();
62
63 bgwSession.send(Helper::createOrder(cfg.traderId()));
64
65 SignalHelper::waitUntilKey("disconnect the BGW session and terminate the application");
66
67 bgwSession.send(Helper::createTraderLogoutRequest(cfg.traderId())).disconnect();
68 }
69 catch (const std::exception& ex)
70 {
71 std::cerr << "EXCEPTION: " << ex.what() << std::endl;
72 return 1;
73 }
74
75 return 0;
76}
#define ONIXS_ICEBOE_NAMESPACE
Definition ABI.h:113
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE
Definition ABI.h:114
int main(int argc, char *argv[])
static MessageHolder< NewOrderRequest > createOrder(const std::string &traderId)
Definition Helpers.h:104
static MessageHolder< TraderLogoutRequest > createTraderLogoutRequest(const std::string &traderId)
Definition Helpers.h:95
static MessageHolder< TraderLogonRequest > createTraderLogonRequest(const std::string &traderId, const std::string &traderPwd)
Definition Helpers.h:77
std::promise< void > traderLoggedOn
Definition Listener.h:223
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
Definition Emulator.h:157
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
Definition Listener.h:264
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
Definition Settings.h:32
std::future< T > wait(Stack &stack, std::promise< T > &promise, std::chrono::seconds timeout=std::chrono::seconds{30})
Definition Listener.h:227
@ Pluggable
Pluggable Session Storage.
static void waitUntilKey(const std::string &message)
Definition Signal.h:57
static void manageSignals() noexcept
Definition Signal.h:46

MySessionStorage.cpp

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#include "MySessionStorage.h"
20
21#include <Common/Helpers.h>
22#include <Common/Listener.h>
23
24namespace Samples {
25namespace {
26
27 const char* begin(const NetworkMessage message) noexcept
28 {
29 return static_cast<const char*>(message.data());
30 }
31
32 const char* end(const NetworkMessage message) noexcept
33 {
34 return static_cast<const char*>(advanceByBytes(message.data(), message.size()));
35 }
36
37 void storeMessage(MySessionStorage::Messages & storage, const NetworkMessage message)
38 {
39 storage.push_back(MySessionStorage::Message(begin(message), end(message)));
40
41 if (!processTypified(message.message(), MessagePrinter()))
42 throw std::runtime_error("Unknown message type");
43 }
44}
45
47 inSeqNum_(1),
48 outSeqNum_(1),
49 id_(std::to_string(IdGenerator::newId())),
50 terminated_(false),
51 sessionCreationTime_()
52{}
53
54void MySessionStorage::close(bool doBackup)
55{
56 std::clog << "\nClose the session storage (doBackup=" << doBackup << ").\n";
57
58 inSeqNum_ = 1;
59 outSeqNum_ = 1;
60 terminated_ = false;
61 inboundMessages_.clear();
62 outboundMessages_.clear();
63}
64
65const std::string & MySessionStorage::id() const
66{
67 return id_;
68}
69
71{
72 return inSeqNum_;
73}
74
76{
77 std::clog << "\nSet inSeqNum to " << msgSeqNum << ".\n";
78 inSeqNum_ = msgSeqNum;
79}
80
82{
83 return outSeqNum_;
84}
85
87{
88 std::clog << "\nSet outSeqNum to " << msgSeqNum << ".\n";
89 outSeqNum_ = msgSeqNum;
90}
91
93{
94 return sessionCreationTime_;
95}
96
98{
99 std::clog << "\nSet sessionCreationTime to " << time << "\n";
100 sessionCreationTime_ = time;
101}
102
104{
105 std::clog << "\nStore inbound message:\n";
106 storeMessage(inboundMessages_, message);
107
108 inSeqNum_ = msgSeqNum;
109}
110
112{
113 std::clog << "\nStore outbound message:\n";
114 storeMessage(outboundMessages_, message);
115
116 outSeqNum_ = msgSeqNum;
117}
118
120{
121}
122
124{
125}
126
127}
SbeMessage message() const noexcept
Retrieves the underlying SBE message.
The time point without the time-zone information.
Definition Time.h:470
void flush() override
Flushes all internal buffers.
void storeOutboundMessage(const NetworkMessage message, SeqNumber msgSeqNum, Timestamp messageSendingUtcTimestamp=Timestamp()) override
Logs the given outgoing message.
Timestamp sessionCreationTime() const override
std::vector< char > Message
void close(bool doBackup=false) override
Closes the storage.
void warmup(size_t, Timestamp) override
Warmup the storage.
SeqNumber outSeqNum() const override
SeqNumber inSeqNum() const override
std::list< Message > Messages
void storeInboundMessage(const NetworkMessage message, SeqNumber msgSeqNum, Timestamp messageReceivingUtcTimestamp=Timestamp()) override
Logs the given inbound message.
const std::string & id() const override
bool processTypified(SbeMessage binary, Processor &&processor)
Casts a given binary message according to template/type information and processes the cast messages b...
ONIXS_ICEBOE_FORCEINLINE Type * advanceByBytes(Type *pointer, ptrdiff_t distance) noexcept
Advances the pointer to a given offset (distance) in bytes.
Definition Memory.h:110
decltype(std::declval< const Messaging::SbeMessage & >().sequenceId()) SeqNumber
Definition Messaging.h:53

MySessionStorage.h

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#pragma once
20
22
23#include <vector>
24#include <list>
25
26namespace Samples {
27
28using namespace ONIXS_ICEBOE_NAMESPACE;
30
31class MySessionStorage final : public SessionStorage
32{
33public:
35
36 const std::string & id() const override;
37
38 SeqNumber inSeqNum() const override;
39
40 void inSeqNum(SeqNumber msgSeqNum) override;
41
42 SeqNumber outSeqNum() const override;
43
44 void outSeqNum(SeqNumber msgSeqNum) override;
45
46 Timestamp sessionCreationTime() const override;
47
48 void sessionCreationTime(Timestamp) override;
49
50 void close(bool doBackup = false) override;
51
52 void storeInboundMessage(const NetworkMessage message, SeqNumber msgSeqNum, Timestamp messageReceivingUtcTimestamp = Timestamp()) override;
53
54 void storeOutboundMessage(const NetworkMessage message, SeqNumber msgSeqNum, Timestamp messageSendingUtcTimestamp = Timestamp()) override;
55
56 void flush() override;
57
58 void warmup(size_t, Timestamp) override;
59
60 using Message = std::vector<char>;
61 using Messages = std::list<Message>;
62
63private:
64 SeqNumber inSeqNum_;
65 SeqNumber outSeqNum_;
66 std::string id_;
67 bool terminated_;
68 Timestamp sessionCreationTime_;
69 Messages inboundMessages_;
70 Messages outboundMessages_;
71};
72
73}