OnixS C++ FIX Engine  4.12.0
API Documentation
SessionScheduler.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 <string>
23 #include <set>
24 
25 #include <OnixS/FIXEngine/ABI.h>
26 
28 
29 namespace OnixS {
30 namespace FIX {
31 ONIXS_FIXENGINE_API_DECL(class, Session);
32 
33 namespace Scheduling {
34 ONIXS_FIXENGINE_API_DECL(class, SessionScheduler);
35 
36 ONIXS_FIXENGINE_API_DECL(class, SessionSchedule);
37 ONIXS_FIXENGINE_API_DECL(class, SessionConnectionSettings);
38 ONIXS_FIXENGINE_API_DECL(class, Counterparty);
39 
40 typedef std::string SessionScheduleId;
41 typedef std::string SessionConnectionSettingsId;
42 
43 /// SessionScheduler events notifications.
44 class
47 {
48 public:
49  /// Notifies if the FIX session is about to be closed.
50  /// @param scheduler Identifies an instance of the session
51  /// scheduler which is about to close the scheduled session.
52  /// @param session Identifies the session which is about to be closed.
53  /// @param allowLogout Defines whether the session
54  /// scheduler must perform the logout. To prohibit
55  /// the session logout it's necessary to set it to 'false'.
56  virtual
57  void
58  onLoggingOut(
59  const SessionScheduler & scheduler,
60  Session * session,
61  bool * allowLogout) = 0;
62 
63  /// Allows scheduler's users to be notified when an initiator will try
64  /// to connect to the next counterparty.
65  /// The parameter `Counterparty` provides a counterparty,
66  /// to which the session will connect.
67  virtual
68  void
70  const SessionScheduler &,
71  Session *,
72  const Counterparty &) {}
73 
74  /// Notifies about a non-critical issue occurred
75  /// while maintaining the state for the given session.
76  virtual
77  void
78  onWarning(
79  const SessionScheduler & scheduler,
80  Session * session,
81  const std::string & warningReason) = 0;
82 
83  /// Notifies about an error occurred while
84  /// maintaining the state for the given session.
85  virtual
86  void
87  onError(
88  const SessionScheduler & scheduler,
89  Session * session,
90  const std::string & errorReason) = 0;
91 
92 protected:
93  /// The class is not used for the object life time managing.
94  /// Therefore, destructor is in the protected area.
96 };
97 
98 /// The way in which the Scheduler will utilize threads.
100 {
101  enum Enum
102  {
103  /// Scheduler will use its own threads.
105 
106  /// Scheduler events are handled by rolling an event loop in a user thread.
108  };
109 
110  /// Returns the textual representation of the SchedulerThreadingModel::Enum value.
112 };
113 
114 /// The collection of miscellaneous parameters
115 /// which affect the session scheduler behavior.
116 class
119 {
120 public:
121  /// Initializes parameters with default values.
123 
124  /// Cleans everything up.
126 
127  /// The path to the scheduler configuration file.
128  const std::string & configurationFile() const;
129 
130  /// Updates the path to the scheduler configuration file.
131  void configurationFile(const std::string & file);
132 
133  /// An instance of the event listener to notify about events.
134  SessionSchedulerListener * eventListener() const;
135 
136  /// Associates the given event listener with the scheduler.
137  void eventListener(SessionSchedulerListener * listener);
138 
139  /// The threading model.
140  SchedulerThreadingModel::Enum threadingModel() const;
141 
142  /// Updates the threading model.
143  void threadingModel(SchedulerThreadingModel::Enum threadingModel);
144 
145 private:
146  std::string * configurationFile_;
147  SessionSchedulerListener * eventListener_;
148  SchedulerThreadingModel::Enum threadingModel_;
149 };
150 
151 /// The scheduler performs the session connection maintenance according
152 /// to the specified schedule for session activities. It monitors
153 /// whenever criteria to log a particular session, either on or off,
154 /// is triggered and automatically executes an appropriate action.
156 {
157 public:
158  /// Initializes the Scheduler instance according to the options
159  /// specified in the given configuration file.
160  ///
161  /// If specified, the Scheduler extracts from the configuration a set
162  /// of predefined session schedules and connection settings later
163  /// available through Schedules and ConnectionSettings properties.
165  const SessionSchedulerOptions & options);
166 
167  /// Performs the graceful shutdown of scheduling services.
168  ~SessionScheduler();
169 
170  /// Looks for the predefined session schedule
171  /// associated with the given unique names (ids) as it
172  /// was specified in the Scheduler's configuration file.
173  /// @return NULL if no a schedule available under the given id.
174  const
176  findSchedule(const SessionScheduleId & id) const;
177 
178  /// Looks for the predefined session connection settings
179  /// associated with the given unique names (ids) as it was
180  /// specified in the Scheduler's configuration file.
181  /// @return NULL if no settings available under the given id.
182  const
184  findConnectionSettings(
185  const SessionConnectionSettingsId & id) const;
186 
187  /// Adds the session to the automatic connection management.
188  ///
189  /// If the session is added during an active time frame,
190  /// it will be connected immediately. If the session is
191  /// registered during an inactive time frame and has an active state,
192  /// it will be disconnected. If the session is already registered,
193  /// an exception will be thrown.
194  ///
195  /// @param session An instance of the session to be maintained.
196  /// @param schedule The schedule which defines the session connection
197  /// time, periodicity as well as other attributes.
198  /// @param connection Settings for the given session to
199  /// be used when the session must be connected.
200  void
201  add(
202  Session * session,
203  const SessionSchedule & schedule,
204  const SessionConnectionSettings & connection);
205 
206  /// Adds the session to the automatic connection management.
207  ///
208  /// If the session is added during an active time frame,
209  /// it will be connected immediately. If the session is
210  /// registered during an inactive time frame and has an active state,
211  /// it will be disconnected. If the session is already registered,
212  /// an exception will be thrown.
213  ///
214  /// @param session An instance of the session to be maintained.
215  /// @param scheduleId The id of the predefined schedule
216  /// to use for the given session.
217  /// @param connectionId The id of the predefined connection
218  /// settings to use for the given session.
219  void
220  add(
221  Session * session,
222  const SessionScheduleId & scheduleId,
223  const SessionConnectionSettingsId & connectionId);
224 
225  /// Removes the session from the automatic connection management services.
226  /// If the session were not registered before, an exception will be thrown.
227  void remove(Session * session);
228 
229  /// Checks if the session is scheduled for the automatic connection management services.
230  /// Returns 'true' if the session is registered, otherwise - 'false'.
231  bool isScheduled(Session * session);
232 
233  /// Processes events on the Scheduler and performs the necessary session management.
234  ///
235  /// This method should be called periodically and only when the ExternalThread threading model is used.
236  /// This method is not thread-safe.
237  void dispatchEvents();
238 
239  /**
240  * Sets the CPU affinity of the Scheduler service thread.
241  */
242  void serviceThreadAffinity(const OnixS::Threading::CpuIndexes & cpuIndexes);
243 
244  /**
245  * Returns the CPU affinity of the Scheduler service thread.
246  */
247  const OnixS::Threading::CpuIndexes & serviceThreadAffinity() const;
248 
249  /**
250  * Sets the number of logon attempts in case of a logon failure.
251  */
252  void reconnectAttempts(int value);
253 
254  /**
255  * Returns the number of logon attempts in case of a logon failure.
256  * By default, the option value is equal to 3.
257  */
258  int reconnectAttempts() const;
259 
260  /**
261  * Sets the time interval between logon attempts in case of a logon failure. (in seconds).
262  */
263  void reconnectInterval(int value);
264 
265  /**
266  * Returns the time interval between logon attempts in case of a logon failure. (in seconds).
267  * By default, the option value is equal to 180 seconds.
268  */
269  int reconnectInterval() const;
270 
271  /**
272  * This property allows switching the local time to the UTC time usage.
273  */
274  void utcTimeUsage(bool value);
275 
276  /**
277  * Returns true if the UTC time is used otherwise false.
278  * By default, the option value is false.
279  */
280  bool utcTimeUsage() const;
281 
282 private:
283  class Impl;
284  Impl * impl_;
285 };
286 }
287 }
288 }
The FIX Session - a bi-directional stream of ordered messages between two parties within a continuous...
Definition: Session.h:97
The collection of connection-related attributes for the session.
static ONIXS_FIXENGINE_API const char * toString(SchedulerThreadingModel::Enum value)
Returns the textual representation of the SchedulerThreadingModel::Enum value.
SessionScheduler events notifications.
#define ONIXS_FIXENGINE_DEFAULT
Definition: Compiler.h:176
std::string SessionConnectionSettingsId
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
The collection of miscellaneous parameters which affect the session scheduler behavior.
virtual void onInitiatorConnecting(const SessionScheduler &, Session *, const Counterparty &)
Allows scheduler&#39;s users to be notified when an initiator will try to connect to the next counterpart...
std::set< CpuIndex > CpuIndexes
Definition: Thread.h:32
Defines activity time frames for the session.
The collection of parameters required to establish a connection with a counterparty (session-acceptor...
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
The way in which the Scheduler will utilize threads.
ONIXS_FIXENGINE_API_DECL(class, SessionScheduler)
Scheduler events are handled by rolling an event loop in a user thread.
The scheduler performs the session connection maintenance according to the specified schedule for ses...