Skip to content

Commit

Permalink
Revert D63971252
Browse files Browse the repository at this point in the history
Summary:
This diff reverts D63971252
removed by mistake, used in github

Reviewed By: avasylev

Differential Revision: D64762130

fbshipit-source-id: c9c78cf9f772cebae5f910ae6b9ffae2969c33ee
  • Loading branch information
generatedunixname89002005232357 authored and facebook-github-bot committed Oct 22, 2024
1 parent f32bb29 commit fa184df
Show file tree
Hide file tree
Showing 5 changed files with 846 additions and 0 deletions.
52 changes: 52 additions & 0 deletions example_grpc/GrpcSignalHandler.cpp
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
57 changes: 57 additions & 0 deletions example_grpc/GrpcSignalHandler.h
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
Loading

0 comments on commit fa184df

Please sign in to comment.