NCBI C++ ToolKit
grid_worker_app.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CONNECT_SERVICES__GRID_WORKER_APP_HPP
2 #define CONNECT_SERVICES__GRID_WORKER_APP_HPP
3 
4 
5 /* $Id: grid_worker_app.hpp 87987 2019-10-29 17:07:52Z sadyrovr $
6  * ===========================================================================
7  *
8  * PUBLIC DOMAIN NOTICE
9  * National Center for Biotechnology Information
10  *
11  * This software/database is a "United States Government Work" under the
12  * terms of the United States Copyright Act. It was written as part of
13  * the author's official duties as a United States Government employee and
14  * thus cannot be copyrighted. This software/database is freely available
15  * to the public for use. The National Library of Medicine and the U.S.
16  * Government have not placed any restriction on its use or reproduction.
17  *
18  * Although all reasonable efforts have been taken to ensure the accuracy
19  * and reliability of the software and data, the NLM and the U.S.
20  * Government do not and cannot warrant the performance or results that
21  * may be obtained by using this software or data. The NLM and the U.S.
22  * Government disclaim all warranties, express or implied, including
23  * warranties of performance, merchantability or fitness for any particular
24  * purpose.
25  *
26  * Please cite the author in any work or product based on this material.
27  *
28  * ===========================================================================
29  *
30  * Authors: Maxim Didenko, Anatoliy Kuznetsov, Dmitry Kazimirov
31  *
32  * File Description:
33  * NetSchedule Worker Node Framework Application.
34  *
35  */
36 
37 /// @file grid_worker_app.hpp
38 /// NetSchedule worker node application.
39 ///
40 
41 
43 #include <corelib/ncbiapp.hpp>
44 
46 
47 /// Listener of events generated by CGridWorkerNodeApp.
48 /// @see CGridWorkerApp::SetListener().
50 {
51 public:
52  /// Perform the necessary pre-init checks. Throw an exception
53  /// if the worker node cannot be launched at this time.
54  /// The method is called from the Init() method of the
55  /// worker node application prior to daemonizing.
57 
58  /// @deprecated, use OnInit(IWorkerNodeInitBaseContext*) instead
59  NCBI_DEPRECATED virtual void OnInit(CNcbiApplication*) final {}
60 
61  /// Notify that CGridWorkerNode::Run() is about to be executed.
62  /// This method can be overridden to implement worker node-
63  /// specific initialization.
64  virtual void OnGridWorkerStart() = 0;
65 
66  /// Notify that CGridWorkerNode::Run() has just finished.
67  virtual void OnGridWorkerStop() = 0;
68 
70 };
71 
72 /// An adapter class for IGridWorkerNodeApp_Listener.
74 {
75  virtual void OnGridWorkerStart() {}
76  virtual void OnGridWorkerStop() {}
77 };
78 
79 /// Main Worker Node application
80 ///
81 /// @note
82 /// Worker node application is parameterized using INI file settings.
83 /// Please read the sample ".ini" file for more information.
84 ///
86 {
87 public:
89  const SBuildInfo& build_info = NCBI_SBUILDINFO_DEFAULT());
90 
92  const CVersionInfo& version_info,
93  const SBuildInfo& build_info = NCBI_SBUILDINFO_DEFAULT());
94 
95  /// Register a listener of events of this class.
96  ///
97  /// @note
98  /// This object takes ownership over the listener object
99  /// and will automatically 'delete' it.
100  ///
101  /// @param listener A pointer to the listener object.
102  /// NULL can be passed to stop listening and reset the
103  /// internal pointer to the default handler.
104  void SetListener(IGridWorkerNodeApp_Listener* listener);
105 
106  /// If you override this method, do call CGridWorkerApp::Init()
107  /// from inside of your overriding method.
108  virtual void Init(void);
109 
110  /// Do not override this method yourself! It includes all the Worker Node
111  /// specific machinery. If you override it, do call CGridWorkerApp::Run()
112  /// from inside your overriding method.
113  virtual int Run(void);
114 
115  virtual void SetupArgDescriptions(CArgDescriptions* arg_desc);
116 
117  void RequestShutdown();
118 
119  CGridWorkerNode GetWorkerNode() const {return m_WorkerNode;}
120 
121 private:
122  void Construct(IWorkerNodeJobFactory* job_factory);
123 
125 
128 };
129 
131 {
132  m_WorkerNode.SetListener(listener);
133 }
134 
135 // Define GRID_WORKER_APP_NAME for use by the logging system.
136 #ifndef GRID_WORKER_APP_NAME
137 #ifdef GRID_APP_NAME
138 #define GRID_WORKER_APP_NAME GRID_APP_NAME
139 #else
140 #define GRID_WORKER_APP_NAME NcbiEmptyString
141 #endif
142 #endif
143 
144 #ifdef NCBI_BUILD_TAG
145 # define GRID_WORKER_APP_BUILD_TAG NCBI_AS_STRING(NCBI_BUILD_TAG)
146 #else
147 # define GRID_WORKER_APP_BUILD_TAG kEmptyStr
148 #endif
149 
150 #ifdef NCBI_WORKERNODE_CLASS
151 #error \
152  NCBI_WORKERNODE_CLASS is not supported anymore. \
153  Replace NCBI_WORKERNODE_* with corresponding NCBI_WORKERNODE_*_DERIVED providing app class. \
154  Please be aware that your app class is required to accept SBuildInfo and pass it to CGridWorkerApp.
155 #endif
156 
157 #define NCBI_WORKERNODE_MAIN_IMPL(TFactory, CGridWorkerApp, Version, SetListener) \
158  int main(int argc, const char* argv[]) \
159  { \
160  GetDiagContext().SetOldPostFormat(false); \
161  CGridWorkerApp app(new TFactory, \
162  CVersionInfo(#Version, NCBI_TEAMCITY_PROJECT_NAME_PROXY), \
163  NCBI_APP_SBUILDINFO_DEFAULT()); \
164  SetListener; \
165  return app.AppMain(argc, argv, NULL, eDS_ToStdlog, \
166  NcbiEmptyCStr, GRID_WORKER_APP_NAME); \
167  }
168 
169 #define NCBI_WORKERNODE_MAIN(TWorkerNodeJob, Version) \
170  NCBI_WORKERNODE_MAIN_DERIVED(TWorkerNodeJob, CGridWorkerApp, Version)
171 
172 #define NCBI_WORKERNODE_MAIN_DERIVED(TWorkerNodeJob, CGridWorkerApp, Version) \
173  NCBI_DECLARE_WORKERNODE_FACTORY(TWorkerNodeJob, Version) \
174  NCBI_WORKERNODE_MAIN_IMPL(TWorkerNodeJob##Factory, CGridWorkerApp, Version, )
175 
176 #define NCBI_WORKERNODE_MAIN_WITH_LISTENER(TWorkerNodeJob, Version, ListenerClass) \
177  NCBI_WORKERNODE_MAIN_WITH_LISTENER_DERIVED(TWorkerNodeJob, CGridWorkerApp, Version, ListenerClass)
178 
179 #define NCBI_WORKERNODE_MAIN_WITH_LISTENER_DERIVED(TWorkerNodeJob, CGridWorkerApp, Version, ListenerClass) \
180  NCBI_DECLARE_WORKERNODE_FACTORY(TWorkerNodeJob, Version) \
181  NCBI_WORKERNODE_MAIN_IMPL(TWorkerNodeJob##Factory, CGridWorkerApp, Version, app.SetListener(new ListenerClass))
182 
183 #define NCBI_WORKERNODE_MAIN_EX(TWorkerNodeJob, TWorkerNodeIdleTask, Version) \
184  NCBI_WORKERNODE_MAIN_EX_DERIVED(TWorkerNodeJob, TWorkerNodeIdleTask, CGridWorkerApp, Version)
185 
186 #define NCBI_WORKERNODE_MAIN_EX_DERIVED(TWorkerNodeJob, TWorkerNodeIdleTask, CGridWorkerApp, Version) \
187  NCBI_DECLARE_WORKERNODE_FACTORY_EX(TWorkerNodeJob, TWorkerNodeIdleTask, Version) \
188  NCBI_WORKERNODE_MAIN_IMPL(TWorkerNodeJob##FactoryEx, CGridWorkerApp, Version, )
189 
190 #define NCBI_GRID_PKG_WORKER_NODE_MAIN(TWorkerNodeJob, \
191  TWorkerNodeJobFactoryClass, ListenerClass) \
192  int main(int argc, const char* argv[]) \
193  { \
194  GRID_APP_CHECK_VERSION_ARGS(); \
195  GetDiagContext().SetOldPostFormat(false); \
196  CGridWorkerApp app(new TWorkerNodeJobFactoryClass); \
197  app.SetListener(new ListenerClass); \
198  return app.AppMain(argc, argv, NULL, eDS_ToStdlog, \
199  NcbiEmptyCStr, GRID_WORKER_APP_NAME); \
200  }
201 
202 /* @} */
203 
204 
206 
207 #endif //CONNECT_SERVICES__GRID_WORKER_APP_HPP
CArgDescriptions –.
Definition: ncbiargs.hpp:541
Main Worker Node application.
CGridWorkerNode GetWorkerNode() const
CGridWorkerApp(const CGridWorkerApp &)
void SetListener(IGridWorkerNodeApp_Listener *listener)
Register a listener of events of this class.
CGridWorkerApp & operator=(const CGridWorkerApp &)
CGridWorkerNode m_WorkerNode
An adapter class for IGridWorkerNodeApp_Listener.
virtual void OnGridWorkerStart()
Notify that CGridWorkerNode::Run() is about to be executed.
virtual void OnGridWorkerStop()
Notify that CGridWorkerNode::Run() has just finished.
Grid Worker Node.
CVersionInfo –.
Listener of events generated by CGridWorkerNodeApp.
virtual void OnInit(CNcbiApplication *) final
virtual void OnGridWorkerStop()=0
Notify that CGridWorkerNode::Run() has just finished.
virtual void OnInit(IWorkerNodeInitBaseContext *)
Perform the necessary pre-init checks.
virtual void OnGridWorkerStart()=0
Notify that CGridWorkerNode::Run() is about to be executed.
Worker Node initialize context.
Worker Node Job Factory interface.
static void Init(void)
Definition: cursor6.c:76
Grid Framework specs.
void SetListener(IGridWorkerNodeApp_Listener *listener)
#define NCBI_DEPRECATED
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void Run(void)
Enter the main loop.
#define NCBI_SBUILDINFO_DEFAULT()
Definition: version.hpp:119
#define NCBI_XCONNECT_EXPORT
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
This class allows to add build info (date and tag) to application version.
Definition: version_api.hpp:62
Modified on Fri Sep 20 14:57:22 2024 by modify_doxy.py rev. 669887