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_ASYNC_JOB_H
10#define SQUID_ASYNC_JOB_H
11
12#include "base/AsyncCall.h"
13#include "base/InstanceId.h"
14#include "cbdata.h"
15
16template <class Cbc>
17class CbcPointer;
18
27// See AsyncJobs.dox for details.
28
32{
33public:
35
36public:
37 AsyncJob(const char *aTypeName);
38
45 static void Start(const Pointer &job);
46
47 static void RegisterWithCacheManager();
48
49protected:
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
64public:
65 bool canBeCalled(AsyncCall &call) const;
66 void callStart(AsyncCall &call);
68 virtual void callEnd();
70 virtual void callException(const std::exception &e);
71
73 void handleStopRequest() { mustStop("externally aborted"); }
74
76
77protected:
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_ASYNC_JOB_H */
93
static void Start(const Pointer &job)
Definition: AsyncJob.cc:37
virtual bool doneAll() const
whether positive goal has been reached
Definition: AsyncJob.cc:112
void handleStopRequest()
process external request to terminate now (i.e. during this async call)
Definition: AsyncJob.h:73
virtual void start()
called by AsyncStart; do not call directly
Definition: AsyncJob.cc:59
static void RegisterWithCacheManager()
Definition: AsyncJob.cc:215
AsyncJob(const char *aTypeName)
Definition: AsyncJob.cc:43
bool swanSang_
swanSong() was called
Definition: AsyncJob.h:89
virtual void callEnd()
called right after the called job method
Definition: AsyncJob.cc:152
void mustStop(const char *aReason)
Definition: AsyncJob.cc:85
static void ReportAllJobs(StoreEntry *)
writes a cache manager report about all jobs existing in this worker
Definition: AsyncJob.cc:198
const char * typeName
kid (leaf) class name, for debugging
Definition: AsyncJob.h:85
bool started_
Start() has finished successfully.
Definition: AsyncJob.h:88
void deleteThis(const char *aReason)
Definition: AsyncJob.cc:65
void callStart(AsyncCall &call)
Definition: AsyncJob.cc:130
const InstanceId< AsyncJob > id
job identifier
Definition: AsyncJob.h:75
bool done() const
the job is destroyed in callEnd() when done()
Definition: AsyncJob.cc:106
virtual void swanSong()
Definition: AsyncJob.h:61
AsyncCall::Pointer inCall
the asynchronous call being handled, if any
Definition: AsyncJob.h:86
~AsyncJob() override
Definition: AsyncJob.cc:51
virtual const char * status() const
internal cleanup; do not call directly
Definition: AsyncJob.cc:182
CbcPointer< AsyncJob > Pointer
Definition: AsyncJob.h:34
bool canBeCalled(AsyncCall &call) const
whether we can be called
Definition: AsyncJob.cc:117
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: AsyncJob.cc:143
const char * stopReason
reason for forcing done() to be true
Definition: AsyncJob.h:84

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors