AsyncJob.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_BASE_ASYNCJOB_H
10 #define SQUID_SRC_BASE_ASYNCJOB_H
11 
12 #include "base/AsyncCall.h"
13 #include "base/InstanceId.h"
14 #include "cbdata.h"
15 
16 template <class Cbc>
17 class CbcPointer;
18 
27 // See AsyncJobs.dox for details.
28 
31 class AsyncJob: public CbdataParent
32 {
33 public:
35 
36 public:
37  AsyncJob(const char *aTypeName);
38 
45  static void Start(const Pointer &job);
46 
47  static void RegisterWithCacheManager();
48 
49 protected:
50  // XXX: temporary method to replace "delete this" in jobs-in-transition.
51  // Will be replaced with calls to mustStop() when transition is complete.
52  void deleteThis(const char *aReason);
53 
54  // force done() for a reason but continue with the current method
55  void mustStop(const char *aReason);
56 
57  bool done() const;
58 
59  virtual void start();
60  virtual bool doneAll() const;
61  virtual void swanSong() {};
62  virtual const char *status() const;
63 
64 public:
65  bool canBeCalled(AsyncCall &call) const;
66  void callStart(AsyncCall &call);
67  virtual void callEnd();
69  virtual void callException(const std::exception &e);
71 
73  void handleStopRequest() { mustStop("externally aborted"); }
74 
76 
77 protected:
78  // external destruction prohibited to ensure swanSong() is called
79  ~AsyncJob() override;
80 
82  static void ReportAllJobs(StoreEntry *);
83 
84  const char *stopReason;
85  const char *typeName;
87 
88  bool started_ = false;
89  bool swanSang_ = false;
90 };
91 
92 #endif /* SQUID_SRC_BASE_ASYNCJOB_H */
93 
bool canBeCalled(AsyncCall &call) const
whether we can be called
Definition: AsyncJob.cc:117
bool started_
Start() has finished successfully.
Definition: AsyncJob.h:88
AsyncCall::Pointer inCall
the asynchronous call being handled, if any
Definition: AsyncJob.h:86
virtual void callEnd()
called right after the called job method
Definition: AsyncJob.cc:152
virtual void swanSong()
Definition: AsyncJob.h:61
CbcPointer< AsyncJob > Pointer
Definition: AsyncJob.h:34
const char * stopReason
reason for forcing done() to be true
Definition: AsyncJob.h:84
AsyncJob(const char *aTypeName)
Definition: AsyncJob.cc:43
~AsyncJob() override
Definition: AsyncJob.cc:51
virtual bool doneAll() const
whether positive goal has been reached
Definition: AsyncJob.cc:112
void mustStop(const char *aReason)
Definition: AsyncJob.cc:85
bool swanSang_
swanSong() was called
Definition: AsyncJob.h:89
static void RegisterWithCacheManager()
Definition: AsyncJob.cc:215
const char * typeName
kid (leaf) class name, for debugging
Definition: AsyncJob.h:85
bool done() const
the job is destroyed in callEnd() when done()
Definition: AsyncJob.cc:106
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:182
void deleteThis(const char *aReason)
Definition: AsyncJob.cc:65
static void ReportAllJobs(StoreEntry *)
writes a cache manager report about all jobs existing in this worker
Definition: AsyncJob.cc:198
void callStart(AsyncCall &call)
Definition: AsyncJob.cc:130
const InstanceId< AsyncJob > id
job identifier
Definition: AsyncJob.h:75
virtual void start()
called by AsyncStart; do not call directly
Definition: AsyncJob.cc:59
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: AsyncJob.cc:143
void handleStopRequest()
process external request to terminate now (i.e. during this async call)
Definition: AsyncJob.h:73
static void Start(const Pointer &job)
Definition: AsyncJob.cc:37

 

Introduction

Documentation

Support

Miscellaneous