proxygen
AcceptRoutingHandler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
21 
22 namespace wangle {
23 
38 template <typename Pipeline, typename R>
40 
41 template <typename Pipeline, typename R>
42 class AcceptRoutingHandler : public wangle::InboundHandler<AcceptPipelineType>,
43  public RoutingDataHandler<R>::Callback {
44  public:
47  std::shared_ptr<RoutingDataHandlerFactory<R>> routingHandlerFactory,
49  childPipelineFactory)
50  : server_(CHECK_NOTNULL(server)),
51  routingHandlerFactory_(routingHandlerFactory),
52  childPipelineFactory_(childPipelineFactory) {}
53 
54  // InboundHandler implementation
55  void read(Context* ctx, AcceptPipelineType conn) override;
56  void readEOF(Context* ctx) override;
57  void readException(Context* ctx, folly::exception_wrapper ex) override;
58 
59  // RoutingDataHandler::Callback implementation
60  void onRoutingData(
61  uint64_t connId,
62  typename RoutingDataHandler<R>::RoutingData& routingData) override;
63  void onError(uint64_t connId, folly::exception_wrapper ex) override;
64 
65  size_t getRoutingPipelineCount() const {
66  return routingPipelines_.size();
67  }
68 
69  private:
70  void populateAcceptors();
72  return DefaultPipeline::create();
73  }
74 
76  std::shared_ptr<RoutingDataHandlerFactory<R>> routingHandlerFactory_;
77  std::shared_ptr<RoutingDataPipelineFactory<Pipeline, R>>
79 
80  std::vector<Acceptor*> acceptors_;
81  std::map<uint64_t, DefaultPipeline::Ptr> routingPipelines_;
83 };
84 
85 template <typename Pipeline, typename R>
87  public:
90  std::shared_ptr<RoutingDataHandlerFactory<R>> routingHandlerFactory,
92  childPipelineFactory)
93  : server_(CHECK_NOTNULL(server)),
94  routingHandlerFactory_(routingHandlerFactory),
95  childPipelineFactory_(childPipelineFactory) {}
96 
98  auto pipeline = AcceptPipeline::create();
99  pipeline->addBack(AcceptRoutingHandler<Pipeline, R>(
101  pipeline->finalize();
102 
103  return pipeline;
104  }
105 
106  protected:
108  std::shared_ptr<RoutingDataHandlerFactory<R>> routingHandlerFactory_;
109  std::shared_ptr<RoutingDataPipelineFactory<Pipeline, R>>
111 };
112 
113 template <typename Pipeline, typename R>
115  public:
117 
118  virtual typename Pipeline::Ptr newPipeline(
119  std::shared_ptr<folly::AsyncTransportWrapper> socket,
120  const R& routingData,
121  RoutingDataHandler<R>* routingHandler,
122  std::shared_ptr<TransportInfo> transportInfo) = 0;
123 };
124 
125 } // namespace wangle
126 
AcceptRoutingPipelineFactory(ServerBootstrap< Pipeline > *server, std::shared_ptr< RoutingDataHandlerFactory< R >> routingHandlerFactory, std::shared_ptr< RoutingDataPipelineFactory< Pipeline, R >> childPipelineFactory)
boost::variant< folly::IOBuf *, folly::AsyncTransportWrapper *, ConnInfo &, ConnEvent, std::tuple< folly::IOBuf *, std::shared_ptr< folly::AsyncUDPSocket >, folly::SocketAddress > > AcceptPipelineType
Definition: Pipeline.h:277
void readException(Context *ctx, folly::exception_wrapper ex) override
ServerBootstrap< Pipeline > * server_
void readEOF(Context *ctx) override
AcceptRoutingHandler(ServerBootstrap< Pipeline > *server, std::shared_ptr< RoutingDataHandlerFactory< R >> routingHandlerFactory, std::shared_ptr< RoutingDataPipelineFactory< Pipeline, R >> childPipelineFactory)
std::shared_ptr< RoutingDataPipelineFactory< Pipeline, R > > childPipelineFactory_
ServerBootstrap< Pipeline > * server_
void onError(uint64_t connId, folly::exception_wrapper ex) override
std::map< uint64_t, DefaultPipeline::Ptr > routingPipelines_
AcceptPipeline::Ptr newPipeline(Acceptor *) override
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
std::shared_ptr< RoutingDataHandlerFactory< R > > routingHandlerFactory_
std::shared_ptr< RoutingDataHandlerFactory< R > > routingHandlerFactory_
void read(Context *ctx, AcceptPipelineType conn) override
static Ptr create()
Definition: Pipeline.h:174
std::shared_ptr< Pipeline > Ptr
Definition: Pipeline.h:172
std::shared_ptr< RoutingDataPipelineFactory< Pipeline, R > > childPipelineFactory_
void onRoutingData(uint64_t connId, typename RoutingDataHandler< R >::RoutingData &routingData) override
virtual DefaultPipeline::Ptr newRoutingPipeline()
std::vector< Acceptor * > acceptors_