RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
AbstractResourceStream.hpp
1 /*
2  * AbstractResourceStream.hpp
3  *
4  * Copyright (C) 2020 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_ABSTRACT_RESOURCE_STREAM_HPP
25 #define LAUNCHER_PLUGINS_ABSTRACT_RESOURCE_STREAM_HPP
26 
27 #include <api/stream/AbstractMultiStream.hpp>
28 
29 #include <Error.hpp>
30 #include <PImpl.hpp>
31 #include <api/Response.hpp>
32 #include <comms/AbstractLauncherCommunicator.hpp>
33 #include <jobs/JobStatusNotifier.hpp>
34 
35 namespace rstudio {
36 namespace launcher_plugins {
37 namespace api {
38 
43  public AbstractMultiStream<ResourceUtilStreamResponse, ResourceUtilData, bool>
44 {
45 public:
49  virtual ~AbstractResourceStream() = default;
50 
57  void addRequest(uint64_t in_requestId, const system::User& in_requestUser) override;
58 
64  virtual Error initialize() = 0;
65 
71  void setStreamComplete();
72 
73 protected:
81  const ConstJobPtr& in_job,
82  comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator);
83 
89  void reportData(const ResourceUtilData& in_data);
90 
98  void reportError(const Error& in_error);
99 
114  const ConstJobPtr m_job;
115 
116 private:
117 
118  // The private implementation of AbstractResourceStream
119  PRIVATE_IMPL(m_resBaseImpl);
120 };
121 
122 // Convenience Typedef
123 typedef std::shared_ptr<AbstractResourceStream> AbstractResourceStreamPtr;
124 
125 } // namespace api
126 } // namespace launcher_plugins
127 } // namespace rstudio
128 
129 #endif
rstudio::launcher_plugins::api::AbstractMultiStream
Manages the sending of streamed responses.
Definition: AbstractMultiStream.hpp:58
rstudio::launcher_plugins::api::AbstractResourceStream
Streams job resource utilization data to the Launcher.
Definition: AbstractResourceStream.hpp:42
rstudio::launcher_plugins::api::AbstractResourceStream::m_job
const ConstJobPtr m_job
The job for which resource utilization metrics should be streamed.
Definition: AbstractResourceStream.hpp:114
rstudio::launcher_plugins::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::api::ResourceUtilData
Represents the current resource utilization of a job.
Definition: ResponseTypes.hpp:111
rstudio::launcher_plugins::api::AbstractResourceStream::reportError
void reportError(const Error &in_error)
Reports an error to the Launcher.
rstudio::launcher_plugins::api::AbstractResourceStream::AbstractResourceStream
AbstractResourceStream(const ConstJobPtr &in_job, comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator)
Constructor.
rstudio::launcher_plugins::api::AbstractResourceStream::~AbstractResourceStream
virtual ~AbstractResourceStream()=default
Virtual destructor for inheritance.
rstudio::launcher_plugins::api::AbstractResourceStream::addRequest
void addRequest(uint64_t in_requestId, const system::User &in_requestUser) override
Adds a request to the stream.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::api::AbstractResourceStream::initialize
virtual Error initialize()=0
Initializes the resource utilization stream.
rstudio::launcher_plugins::api::AbstractResourceStream::setStreamComplete
void setStreamComplete()
Notifies that the data stream has completed.
rstudio::launcher_plugins::api::AbstractResourceStream::reportData
void reportData(const ResourceUtilData &in_data)
Reports resource utilization data to the Launcher.