16 #ifndef TENSORFLOW_SERVING_CORE_TARGET_H_
17 #define TENSORFLOW_SERVING_CORE_TARGET_H_
23 #include "tensorflow/core/lib/core/notification.h"
24 #include "tensorflow/core/lib/core/stringpiece.h"
25 #include "tensorflow/core/lib/io/path.h"
26 #include "tensorflow/core/lib/strings/strcat.h"
27 #include "tensorflow_serving/core/servable_data.h"
28 #include "tensorflow_serving/core/source.h"
29 #include "tensorflow_serving/util/observer.h"
31 namespace tensorflow {
39 virtual ~
Target() =
default;
51 GetAspiredVersionsCallback() = 0;
80 virtual void SetAspiredVersions(
const StringPiece servable_name,
93 mutable std::shared_ptr<mutex> mu_;
97 std::shared_ptr<Notification> detached_;
100 std::unique_ptr<Observer<const StringPiece, std::vector<ServableData<T>>>>
106 template <
typename T>
112 template <
typename T>
114 std::shared_ptr<mutex> mu = mu_;
115 std::shared_ptr<Notification> detached = detached_;
117 [mu, detached,
this](
const StringPiece servable_name,
120 if (detached->HasBeenNotified()) {
124 this->SetAspiredVersions(servable_name, std::move(versions));
128 template <
typename T>
129 TargetBase<T>::~TargetBase() {
130 DCHECK(detached_->HasBeenNotified()) <<
"Detach() must be called exactly "
131 "once, at the top of the leaf "
132 "derived class's destructor";
135 template <
typename T>
137 TargetBase<T>::GetAspiredVersionsCallback() {
139 if (detached_->HasBeenNotified()) {
141 return [](
const StringPiece, std::vector<ServableData<T>>) {};
143 return observer_->Notifier();
146 template <
typename T>
147 void TargetBase<T>::Detach() {
148 DCHECK(!detached_->HasBeenNotified()) <<
"Detach() must be called exactly "
149 "once, at the top of the leaf "
150 "derived class's destructor";
155 std::unique_ptr<Observer<const StringPiece, std::vector<ServableData<T>>>>
159 detached_observer = std::move(observer_);
160 if (!detached_->HasBeenNotified()) {
166 template <
typename T>
167 void ConnectSourceToTarget(Source<T>* source, Target<T>* target) {
168 source->SetAspiredVersionsCallback(target->GetAspiredVersionsCallback());
std::function< void(const StringPiece servable_name, std::vector< ServableData< T > > versions)> AspiredVersionsCallback