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