Apache Mesos
executor.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MESOS_V1_EXECUTOR_HPP__
18 #define __MESOS_V1_EXECUTOR_HPP__
19 
20 #include <functional>
21 #include <queue>
22 #include <map>
23 #include <string>
24 
25 #include <mesos/http.hpp>
26 
27 #include <mesos/v1/mesos.hpp>
28 
30 
31 #include <process/owned.hpp>
32 
33 namespace mesos {
34 namespace v1 {
35 namespace executor {
36 
37 class MesosProcess; // Forward declaration.
38 
39 class MesosBase
40 {
41 public:
42  // Empty virtual destructor (necessary to instantiate subclasses).
43  virtual ~MesosBase() {}
44  virtual void send(const Call& call) = 0;
45 };
46 
47 
48 // Interface to Mesos for an executor.
49 //
50 // Expects three callbacks, 'connected', 'disconnected', and
51 // 'received' which will get invoked _serially_ when it's determined
52 // that we've connected (i.e. established TCP connection), disconnected
53 // (i.e, connection is broken), or received events from the agent.
54 // Note that we drop events while disconnected.
55 class Mesos : public MesosBase
56 {
57 public:
58  // The other constructor overload that accepts `environment`
59  // argument is preferable to this one in a multithreaded environment,
60  // because the implementation of this one accesses global environment
61  // which is unsafe due to a potential concurrent modification of the
62  // environment by another thread.
63  Mesos(ContentType contentType,
64  const std::function<void(void)>& connected,
65  const std::function<void(void)>& disconnected,
66  const std::function<void(const std::queue<Event>&)>& received);
67 
68  Mesos(ContentType contentType,
69  const std::function<void(void)>& connected,
70  const std::function<void(void)>& disconnected,
71  const std::function<void(const std::queue<Event>&)>& received,
72  const std::map<std::string, std::string>& environment);
73 
74  // Delete copy constructor.
75  Mesos(const Mesos& other) = delete;
76 
77  // Delete assignment operator.
78  Mesos& operator=(const Mesos& other) = delete;
79 
80  ~Mesos() override;
81 
82  // Attempts to send a call to the agent.
83  //
84  // Some local validation of calls is performed which may result in dropped
85  // events without ever being sent to the agent.
86  void send(const Call& call) override;
87 
88 private:
90 };
91 
92 } // namespace executor {
93 } // namespace v1 {
94 } // namespace mesos {
95 
96 #endif // __MESOS_V1_EXECUTOR_HPP__
ContentType
Definition: http.hpp:43
virtual void send(const Call &call)=0
mesos::v1::scheduler::Call Call
Definition: mesos.hpp:2851
mesos::v1::scheduler::Mesos Mesos
Definition: mesos.hpp:2853
virtual ~MesosBase()
Definition: executor.hpp:43
Environment * environment
Definition: agent.hpp:25
Definition: executor.hpp:55
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: executor.hpp:39