-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This diff reverts D63971252 removed by mistake, used in github Reviewed By: avasylev Differential Revision: D64762130 fbshipit-source-id: c9c78cf9f772cebae5f910ae6b9ffae2969c33ee
- Loading branch information
1 parent
f32bb29
commit fa184df
Showing
5 changed files
with
846 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Copyright (C) 2018-present, Facebook, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "GrpcSignalHandler.h" | ||
|
||
#include <folly/io/async/EventBase.h> | ||
|
||
namespace lb { | ||
namespace katran { | ||
|
||
GrpcSignalHandler::GrpcSignalHandler( | ||
std::shared_ptr<folly::EventBase> evb, | ||
grpc::Server* server, | ||
int32_t delay) | ||
: folly::AsyncSignalHandler(evb.get()), delay_(delay) { | ||
server_ = server; | ||
evb_ = evb; | ||
}; | ||
|
||
void GrpcSignalHandler::signalReceived(int signum) noexcept { | ||
if (shutdownScheduled_) { | ||
LOG(INFO) << "Ignoring signal: " << signum << " as we already scheduled" | ||
<< " sighandler to run."; | ||
return; | ||
}; | ||
LOG(INFO) << "Signal: " << signum << ", stopping service in " << delay_ | ||
<< " milliseconds."; | ||
evb_->runInEventBaseThread([this]() { | ||
evb_->runAfterDelay( | ||
[this]() { | ||
LOG(INFO) << "Stopping Katran!"; | ||
server_->Shutdown(); | ||
}, | ||
delay_); | ||
}); | ||
shutdownScheduled_ = true; | ||
}; | ||
} // namespace katran | ||
} // namespace lb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright (C) 2018-present, Facebook, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <folly/io/async/AsyncSignalHandler.h> | ||
#include <grpc++/grpc++.h> | ||
|
||
namespace folly { | ||
class EventBase; | ||
} | ||
|
||
namespace lb { | ||
namespace katran { | ||
|
||
/** | ||
* class which implements sighandler for katran's grpc server | ||
*/ | ||
class GrpcSignalHandler : public folly::AsyncSignalHandler { | ||
public: | ||
/** | ||
* @param EventBase* evb event base thread | ||
* @param grpc::Server* server katran's grpc server | ||
* @param int32_t delay in ms between recving signal and stopping katran | ||
*/ | ||
GrpcSignalHandler( | ||
std::shared_ptr<folly::EventBase> evb, | ||
grpc::Server* server, | ||
int32_t delay); | ||
~GrpcSignalHandler() override {} | ||
|
||
void signalReceived(int signum) noexcept override; | ||
|
||
private: | ||
grpc::Server* server_; | ||
std::shared_ptr<folly::EventBase> evb_; | ||
int32_t delay_; | ||
bool shutdownScheduled_{false}; | ||
}; | ||
|
||
} // namespace katran | ||
} // namespace lb |
Oops, something went wrong.