OnixS C++ CME Market Data Handler  5.4.0
API documentation
FeedEngineThreads.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <OnixS/CME/MDH/String.h>
25 
27 
28 // A bit of forward declarations.
29 
31 (
32  FeedEngineThreads
33 );
34 
35 /// Listener for thread-related events.
36 ///
37 /// Members of this classes are invoked to reflect
38 /// various life-time events of threads spawned and
39 /// used by feed engines while processing market data.
42 {
43  /// Invoked by a feed engine when a
44  /// new processing thread is spawned.
45  ///
46  /// @note Invocation is performed by the newly
47  /// started thread thus making possible application
48  /// of any thread-specific turn-up.
49  virtual
50  void
51  onFeedEngineThreadBegin
52  (
53  const FeedEngineThreads&
54  )
55  {
56  }
57 
58  /// Invoked by a feed engine when a
59  /// processing thread is about to end.
60  ///
61  /// @note Invocation is performed by the thread
62  /// thus making possible thread-specific cleanup.
63  virtual
64  void
65  onFeedEngineThreadEnd
66  (
67  const FeedEngineThreads&
68  )
69  {
70  }
71 
72  /// Invoked when a thread reaches the idle state.
73  ///
74  /// Invocation of the given member depends on the
75  /// returned value of a particular implementation of
76  /// the NetFeedEngine::process member.
77  ///
78  /// The returned value indicates whether the given event
79  /// was handled. The FeedEngineThreads makes a decision
80  /// whether the processing is to be suspended depending
81  /// on the returned value.
82  virtual
83  bool
84  onFeedEngineThreadIdle
85  (
86  const FeedEngineThreads&
87  )
88  {
89  return false;
90  }
91 
92  /// Invoked if working thread experiences an issue
93  /// while processing its tasks. Once invoked, working
94  /// thread continues performing its tasks.
95  virtual
96  void
97  onFeedEngineThreadIssue
98  (
99  const FeedEngineThreads&,
100  const Char*
101  )
102  {
103  }
104 };
105 
106 //
107 
108 /// The collection of parameters affecting behavior
109 /// of a thread pool carring out feed engine tasks.
112 {
113  ThreadPoolSettings pool_;
114  UInt32 loopBeforeIdle_;
115 
116 public:
117  /// Assigns the default values for the given
118  /// instance of the thread pool settings.
120  : loopBeforeIdle_(1)
121  {
122  }
123 
124  /// Settings related to the thread pool.
127  {
128  return pool_;
129  }
130 
131  /// Settings related to the thread pool.
132  const
134  pool() const
135  {
136  return pool_;
137  }
138 
139  /// Number of working threads in the pool.
140  UInt32
142  {
143  return loopBeforeIdle_;
144  }
145 
146  /// Defines the number of working threads in the pool.
147  void
149  {
150  loopBeforeIdle_ = value;
151  }
152 };
153 
154 /// Serializes settings defining behavior
155 /// of feed engine threads into a string.
156 ONIXS_CMEMDH_EXPORTED
157 void
158 toStr(
159  std::string&,
160  const
162 
163 /// Serializes settings defining behavior
164 /// of feed engine threads into a string.
165 inline
166 std::string
168  const
169  FeedEngineThreadSettings& settings)
170 {
171  std::string str;
172 
173  toStr(str, settings);
174 
175  return str;
176 }
177 
178 //
179 
181 (
183 );
184 
185 /// The given class represents a pool of
186 /// threads carring out feed engine tasks.
189 {
190  // The workhorse for the class.
191  class Workhorse;
192 
193  Workhorse* workhorse_;
194 
195 public:
196  /// Initializes working threads and spawns
197  /// feed engine process() routine invocation.
199  NetFeedEngine&,
200  const FeedEngineThreadSettings&,
201  FeedEngineThreadListener* = NULL);
202 
203  /// Stops carring out all tasks and
204  /// destructs the working threads.
206 };
207 
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
UInt32 UInt32
uInt32.
Definition: Fields.h:247
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:46
ThreadPoolSettings & pool()
Settings related to the thread pool.
char Char
Character type alias.
Definition: String.h:36
bool value(Number &number, const MultiContainer &container, Tag tag)
#define ONIXS_CMEMDH_EXPORTED_CLASS
Definition: Bootstrap.h:54
const ThreadPoolSettings & pool() const
Settings related to the thread pool.
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
std::string toStr(const FeedEngineThreadSettings &settings)
UInt32 loopBeforeIdle() const
Number of working threads in the pool.
#define ONIXS_CMEMDH_EXPORTED_STRUCT
Definition: Bootstrap.h:58
void loopBeforeIdle(UInt32 value)
Defines the number of working threads in the pool.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156