Apache Mesos
filter.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License
12 
13 #ifndef __PROCESS_FILTER_HPP__
14 #define __PROCESS_FILTER_HPP__
15 
16 #include <process/event.hpp>
17 
18 namespace process {
19 
20 class Filter {
21 public:
22  virtual ~Filter() {}
23  virtual bool filter(const UPID& process, const MessageEvent&)
24  {
25  return false;
26  }
27  virtual bool filter(const UPID& process, const DispatchEvent&)
28  {
29  return false;
30  }
31  virtual bool filter(const UPID& process, const HttpEvent&)
32  {
33  return false;
34  }
35  virtual bool filter(const UPID& process, const ExitedEvent&)
36  {
37  return false;
38  }
39 
40  virtual bool filter(const UPID& process, Event* event)
41  {
42  bool result = false;
43  struct FilterVisitor : EventVisitor
44  {
45  explicit FilterVisitor(
46  Filter* _filter,
47  const UPID& _process,
48  bool* _result)
49  : filter(_filter),
50  process(_process),
51  result(_result) {}
52 
53  void visit(const MessageEvent& event) override
54  {
55  *result = filter->filter(process, event);
56  }
57 
58  void visit(const DispatchEvent& event) override
59  {
60  *result = filter->filter(process, event);
61  }
62 
63  void visit(const HttpEvent& event) override
64  {
65  *result = filter->filter(process, event);
66  }
67 
68  void visit(const ExitedEvent& event) override
69  {
70  *result = filter->filter(process, event);
71  }
72 
73  Filter* filter;
74  const UPID& process;
75  bool* result;
76  } visitor(this, process, &result);
77 
78  event->visit(&visitor);
79 
80  return result;
81  }
82 };
83 
84 
85 // Use the specified filter on messages that get enqueued (note,
86 // however, that you cannot filter timeout messages).
87 void filter(Filter* filter);
88 
89 } // namespace process {
90 
91 #endif // __PROCESS_FILTER_HPP__
Definition: filter.hpp:20
Definition: event.hpp:142
Definition: event.hpp:178
virtual bool filter(const UPID &process, const HttpEvent &)
Definition: filter.hpp:31
Definition: event.hpp:209
virtual bool filter(const UPID &process, const MessageEvent &)
Definition: filter.hpp:23
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
virtual ~Filter()
Definition: filter.hpp:22
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
virtual bool filter(const UPID &process, const DispatchEvent &)
Definition: filter.hpp:27
virtual bool filter(const UPID &process, Event *event)
Definition: filter.hpp:40
Definition: executor.hpp:48
Definition: event.hpp:38
Definition: event.hpp:103
Definition: event.hpp:60
virtual bool filter(const UPID &process, const ExitedEvent &)
Definition: filter.hpp:35