]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/transport/TSocketPool.h
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 #ifndef _THRIFT_TRANSPORT_TSOCKETPOOL_H_
21 #define _THRIFT_TRANSPORT_TSOCKETPOOL_H_ 1
24 #include <thrift/transport/TSocket.h>
31 * Class to hold server information for TSocketPool
34 class TSocketPoolServer
{
38 * Default constructor for server info
43 * Constructor for TSocketPool server
45 TSocketPoolServer(const std::string
& host
, int port
);
53 // Socket for the server
54 THRIFT_SOCKET socket_
;
56 // Last time connecting to this server failed
59 // Number of consecutive times connecting to this server failed
60 int consecutiveFailures_
;
64 * TCP Socket implementation of the TTransport interface.
67 class TSocketPool
: public TSocket
{
71 * Socket pool constructor
76 * Socket pool constructor
78 * @param hosts list of host names
79 * @param ports list of port names
81 TSocketPool(const std::vector
<std::string
>& hosts
, const std::vector
<int>& ports
);
84 * Socket pool constructor
86 * @param servers list of pairs of host name and port
88 TSocketPool(const std::vector
<std::pair
<std::string
, int> >& servers
);
91 * Socket pool constructor
93 * @param servers list of TSocketPoolServers
95 TSocketPool(const std::vector
<std::shared_ptr
<TSocketPoolServer
> >& servers
);
98 * Socket pool constructor
100 * @param host single host
101 * @param port single port
103 TSocketPool(const std::string
& host
, int port
);
106 * Destroyes the socket object, closing it if necessary.
108 ~TSocketPool() override
;
111 * Add a server to the pool
113 void addServer(const std::string
& host
, int port
);
116 * Add a server to the pool
118 void addServer(std::shared_ptr
<TSocketPoolServer
>& server
);
121 * Set list of servers in this pool
123 void setServers(const std::vector
<std::shared_ptr
<TSocketPoolServer
> >& servers
);
126 * Get list of servers in this pool
128 void getServers(std::vector
<std::shared_ptr
<TSocketPoolServer
> >& servers
);
131 * Sets how many times to keep retrying a host in the connect function.
133 void setNumRetries(int numRetries
);
136 * Sets how long to wait until retrying a host if it was marked down
138 void setRetryInterval(int retryInterval
);
141 * Sets how many times to keep retrying a host before marking it as down.
143 void setMaxConsecutiveFailures(int maxConsecutiveFailures
);
146 * Turns randomization in connect order on or off.
148 void setRandomize(bool randomize
);
151 * Whether to always try the last server.
153 void setAlwaysTryLast(bool alwaysTryLast
);
156 * Creates and opens the UNIX socket.
158 void open() override
;
161 * Closes the UNIX socket
163 void close() override
;
166 void setCurrentServer(const std::shared_ptr
<TSocketPoolServer
>& server
);
168 /** List of servers to connect to */
169 std::vector
<std::shared_ptr
<TSocketPoolServer
> > servers_
;
171 /** Current server */
172 std::shared_ptr
<TSocketPoolServer
> currentServer_
;
174 /** How many times to retry each host in connect */
177 /** Retry interval in seconds, how long to not try a host if it has been
180 time_t retryInterval_
;
182 /** Max consecutive failures before marking a host down. */
183 int maxConsecutiveFailures_
;
185 /** Try hosts in order? or Randomized? */
188 /** Always try last host, even if marked down? */
193 } // apache::thrift::transport
195 #endif // #ifndef _THRIFT_TRANSPORT_TSOCKETPOOL_H_