OnixS C++ FIX Engine  4.2.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 
39 typedef std::string SessionScheduleId;
40 typedef std::string SessionConnectionSettingsId;
41 
42 /// SessionScheduler events notifications.
43 class
46 {
47 public:
48  /// Notifies FIX session is about to be closed.
49  /// @param scheduler identifies instance of session
50  /// scheduler which is about to close scheduled session.
51  /// @param session session which is about to be closed.
52  /// @param allowLogout defines whether the session
53  /// scheduler must perform logout. To prohibit
54  /// session logout it's necessary to set to 'false'.
55  virtual
56  void
57  onLoggingOut(
58  const SessionScheduler & scheduler,
59  Session * session,
60  bool * allowLogout) = 0;
61 
62  /// Notifies about non-critical issue occurred
63  /// while maintaining state for the given session.
64  virtual
65  void
66  onWarning(
67  const SessionScheduler & scheduler,
68  Session * session,
69  const std::string & warningReason) = 0;
70 
71  /// Notifies about error occurred while
72  /// maintaining state for the given session.
73  virtual
74  void
75  onError(
76  const SessionScheduler & scheduler,
77  Session * session,
78  const std::string & errorReason) = 0;
79 
80 protected:
81  /// Class is not used for object life time managing.
82  /// Therefore, destructor is in protected area.
83  virtual ~SessionSchedulerListener();
84 };
85 
86 /// Collection of miscellaneous parameters
87 /// which affect session scheduler behavior.
88 class
91 {
92 public:
93  /// Initializes parameters with default values.
95 
96  /// Initializes clone of the given instance.
98 
99  /// Cleans everything up.
101 
102  /// Path to scheduler configuration file.
103  const std::string & configurationFile() const;
104 
105  /// Updates path to scheduler configuration file.
106  void configurationFile(const std::string & file);
107 
108  /// Instance of event listener to notify about events.
109  SessionSchedulerListener * eventListener() const;
110 
111  /// Associates given event listener with the scheduler.
112  void eventListener(SessionSchedulerListener * listener);
113 
114  /// Reinitializes instance from the other one.
116  operator = (const SessionSchedulerOptions & other);
117 
118 private:
119  std::string * configurationFile_;
120  SessionSchedulerListener * eventListener_;
121 };
122 
123 /// Scheduler performs session connection maintenance according
124 /// to the specified schedule for session activities. It monitors
125 /// whenever criteria to log a particular session either on or off
126 /// is triggered and automatically executes appropriate action.
128 {
129 public:
130  /// Initializes Scheduler instance according to the options
131  /// specified in given configuration file.
132  ///
133  /// If specified, Scheduler extracts from configuration a set
134  /// of predefined session schedules and connection settings later
135  /// available through Schedules and ConnectionSettings properties.
137  const SessionSchedulerOptions & options);
138 
139  /// Performs graceful shutdown of scheduling services.
140  ~SessionScheduler();
141 
142  /// Looks for the predefined session schedule
143  /// associated with given unique names (ids) as it
144  /// was specified in Scheduler's configuration file.
145  /// @return NULL if no schedule available under given id.
146  const
148  findSchedule(const SessionScheduleId & id) const;
149 
150  /// Looks for the predefined session connection settings
151  /// associated with given unique names (ids) as it was
152  /// specified in Scheduler's configuration file.
153  /// @return NULL if no settings available under given id.
154  const
156  findConnectionSettings(
157  const SessionConnectionSettingsId & id) const;
158 
159  /// Adds session to automatic connection management.
160  ///
161  /// If session is being added during active time frame,
162  /// it will be connected immediately. If session is being
163  /// registered during inactive time frame and has active state,
164  /// it will be disconnected. If session already registered,
165  /// exception will be thrown.
166  ///
167  /// @param session Instance of session to be maintained.
168  /// @param schedule Schedule which defines session connection
169  /// time, periodicity as well as other attributes.
170  /// @param connection settings for given session to
171  /// be used when session must be connected.
172  void
173  add(
174  Session * session,
175  const SessionSchedule & schedule,
176  const SessionConnectionSettings & connection);
177 
178  /// Adds session to automatic connection management.
179  ///
180  /// If session is being added during active time frame,
181  /// it will be connected immediately. If session is being
182  /// registered during inactive time frame and has active state,
183  /// it will be disconnected. If session already registered,
184  /// exception will be thrown.
185  ///
186  /// @param session Instance of session to be maintained.
187  /// @param scheduleId Id of predefined schedule
188  /// to use for given session.
189  /// @param connectionId Id of predefined connection
190  /// settings to use for given session.
191  void
192  add(
193  Session * session,
194  const SessionScheduleId & scheduleId,
195  const SessionConnectionSettingsId & connectionId);
196 
197  /// Removes session from automatic connection management services.
198  /// If session were not registered before, does actually nothing.
199  void remove(Session * session);
200 
201  /**
202  * Sets the CPU affinity of the Scheduller service thread.
203  */
204  void serviceThreadAffinity(const OnixS::Threading::CpuIndexes & cpuIndexes);
205 
206  /**
207  * Returns the CPU affinity of the Scheduller service thread.
208  */
209  const OnixS::Threading::CpuIndexes & serviceThreadAffinity() const;
210 
211  /**
212  * Sets the number of logon attempts in case of a logon failure.
213  */
214  void reconnectAttempts(int value);
215 
216  /**
217  * Returns the number of logon attempts in case of a logon failure.
218  * By default, the option value is equal to 3.
219  */
220  int reconnectAttempts() const;
221 
222  /**
223  * Sets the time interval between the logon attempts in case of a logon failure. (in seconds).
224  */
225  void reconnectInterval(int value);
226 
227  /**
228  * Returns the time interval between the logon attempts in case of a logon failure. (in seconds).
229  * By default, the option value is equal to 180 second.
230  */
231  int reconnectInterval() const;
232 
233  /**
234  * This property allows switching local time to UTC time usage.
235  */
236  void utcTimeUsage(bool value);
237 
238  /**
239  * Returns true if the UTC time is used otherwise false.
240  * By default, the option value is false.
241  */
242  bool utcTimeUsage() const;
243 
244 private:
245  class Impl;
246  Impl * impl_;
247 };
248 }
249 }
250 }
Collection of miscellaneous parameters which affect session scheduler behavior.
FIX Session - a bi-directional stream of ordered messages between two parties within a continuous seq...
Definition: Session.h:58
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
Collection of connection-related attributes for the session.
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
std::string SessionConnectionSettingsId
ONIXS_FIXENGINE_API_DECL(class, SessionScheduler)
Defines activity time frames for the session.
SessionScheduler events notifications.
Scheduler performs session connection maintenance according to the specified schedule for session act...
std::set< CpuIndex > CpuIndexes
Definition: Thread.h:32