NCBI C++ ToolKit
wn_cleanup.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: wn_cleanup.cpp 64070 2014-08-14 21:35:38Z kazimird $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitry Kazimirov
27  *
28  * File Description:
29  * NetSchedule Worker Node - per-job and global clean-up, declarations.
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "wn_cleanup.hpp"
35 #include "grid_worker_impl.hpp"
36 
38 
39 
40 #define NCBI_USE_ERRCODE_X ConnServ_WorkerNode
41 
43 
45 {
47  m_Listeners.insert(listener);
48 }
49 
52 {
54  m_Listeners.erase(listener);
55 }
56 
58 {
59  TListeners listeners;
60  {
62  listeners.swap(m_Listeners);
63  }
64 
65  ITERATE(TListeners, it, listeners) {
66  try {
67  (*it)->HandleEvent(
69  delete *it;
70  }
71  NCBI_CATCH_ALL_X(39, "Job clean-up error");
72  }
73 }
74 
76  const CWorkerNodeCleanup::TListeners& listeners)
77 {
79  ITERATE(TListeners, it, listeners) {
80  m_Listeners.erase(*it);
81  }
82 }
83 
86 {
89 }
90 
93 {
96 }
97 
99 {
100  {
103  }
105 }
106 
108 {
111  m_Semaphore.Post();
112 
113  return NULL;
114 }
115 
117 {
118  CRef<CGridCleanupThread> cleanup_thread(
119  new CGridCleanupThread(this, m_Listener.get()));
120 
121  cleanup_thread->Run();
122 
123  if (cleanup_thread->Wait(m_ThreadPoolTimeout)) {
124  cleanup_thread->Join();
125  LOG_POST_X(58, Info << "Cleanup thread finished");
126  } else {
127  ERR_POST_X(59, "Clean-up thread timed out");
128  }
129 
131 }
132 
CSemaphore m_Semaphore
Definition: wn_cleanup.hpp:95
SGridWorkerNodeImpl * m_WorkerNode
Definition: wn_cleanup.hpp:93
virtual void * Main()
Derived (user-created) class must provide a real thread function.
Definition: wn_cleanup.cpp:107
IGridWorkerNodeApp_Listener * m_Listener
Definition: wn_cleanup.hpp:94
int GetExitCode() const
static CGridGlobals & GetInstance()
CRef –.
Definition: ncbiobj.hpp:618
TListeners m_Listeners
Definition: wn_cleanup.hpp:55
CFastMutex m_ListenersLock
Definition: wn_cleanup.hpp:56
virtual void CallEventHandlers()
Definition: wn_cleanup.cpp:57
virtual void RemoveListener(IWorkerNodeCleanupEventListener *listener)
Definition: wn_cleanup.cpp:50
void RemoveListeners(const TListeners &listeners)
Definition: wn_cleanup.cpp:75
virtual void AddListener(IWorkerNodeCleanupEventListener *listener)
Definition: wn_cleanup.cpp:44
virtual void AddListener(IWorkerNodeCleanupEventListener *listener)
Definition: wn_cleanup.cpp:84
virtual void CallEventHandlers()
Definition: wn_cleanup.cpp:98
CWorkerNodeCleanup * m_WorkerNodeCleanup
Definition: wn_cleanup.hpp:73
virtual void RemoveListener(IWorkerNodeCleanupEventListener *listener)
Definition: wn_cleanup.cpp:91
virtual void OnGridWorkerStop()=0
Notify that CGridWorkerNode::Run() has just finished.
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
void erase(iterator pos)
Definition: set.hpp:151
void swap(this_type &m)
Definition: set.hpp:102
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST_X(err_subcode, message)
Definition: ncbidiag.hpp:553
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
@ eRegularCleanup
For jobs – run from the same thread after Do() is done; for the whole WN – run from a separate (clean...
Definition: grid_worker.hpp:82
#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 Post(unsigned int count=1)
Increment the semaphore by "count".
Definition: ncbimtx.cpp:1971
unique_ptr< IGridWorkerNodeApp_Listener > m_Listener
CRef< CWorkerNodeCleanup > m_CleanupEventSource
int g(Seg_Gsm *spe, Seq_Mtf *psm, Thd_Gsm *tdg)
Definition: thrddgri.c:44
Modified on Sat May 04 13:14:09 2024 by modify_doxy.py rev. 669887