TensorFlow Serving C++ API Documentation
static_manager.cc
1 /* Copyright 2016 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow_serving/core/static_manager.h"
17 
18 #include <memory>
19 #include <utility>
20 
21 namespace tensorflow {
22 namespace serving {
23 
24 StaticManagerBuilder::StaticManagerBuilder() {
25  BasicManager::Options basic_manager_options;
26  // We don't want multithreading.
27  basic_manager_options.num_load_threads = 0;
28  basic_manager_options.num_unload_threads = 0;
29  const Status basic_manager_status =
30  BasicManager::Create(std::move(basic_manager_options), &basic_manager_);
31  if (!basic_manager_status.ok()) {
32  LOG(ERROR) << "Error creating BasicManager: " << health_;
33  health_ = basic_manager_status;
34  }
35 }
36 
37 std::unique_ptr<Manager> StaticManagerBuilder::Build() {
38  if (!health_.ok()) {
39  LOG(ERROR) << health_;
40  return nullptr;
41  }
42 
43  // If Build() is called again, we'll produce the following error.
44  health_ = errors::FailedPrecondition(
45  "Build() already called on this StaticManagerBuilder.");
46 
47  return std::move(basic_manager_);
48 }
49 
50 } // namespace serving
51 } // namespace tensorflow