Loading...
Searching...
No Matches
service_network.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21#include <memory>
22
31
32namespace resdb {
33
34// ServiceNetwork is a service running in BFT environment.
35// It receives messages from other servers or clients and delivers them to
36// ServiceInterface to process.
37// service will be running in a multi-thread module.
39 public:
40 // While running ServiceNetwork, it will lisenten to ip:port.
41 ServiceNetwork(const ResDBConfig& config,
42 std::unique_ptr<ServiceInterface> service);
43 virtual ~ServiceNetwork();
44
45 // Run ServiceNetwork as background.
46 void Run();
47 void Stop();
48 // Whether the service is ready to process the request.
49 bool ServiceIsReady() const;
50
51 private:
52 void Process();
53 void Process(std::unique_ptr<QueueItem> client_socket);
54 bool IsRunning();
55 void InputProcess();
56 void AcceptorHandler(const char* buffer, size_t data_len);
57
58 private:
59 std::unique_ptr<Acceptor> acceptor_;
60 std::unique_ptr<ServiceInterface> service_;
61 bool is_running = false;
62 LockFreeQueue<QueueItem> input_queue_, resp_queue_;
63 std::unique_ptr<AsyncAcceptor> async_acceptor_;
64 ResDBConfig config_;
65 Stats* global_stats_;
66};
67
68} // namespace resdb