Skip to content

Commit ade9f96

Browse files
Dan Dengmeta-codesync[bot]
authored andcommitted
Add ConsumerCallback to ServerSinkBridge
Reviewed By: evanjzou Differential Revision: D89158038 fbshipit-source-id: 26a968bc5d8809c6391c0cb8db5269f59c1f8213
1 parent f51672c commit ade9f96

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

third-party/thrift/src/thrift/lib/cpp2/async/ServerSinkBridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class ServerSinkBridge : public TwoWayBridge<
7979
// start() should be called on the CPU thread
8080
folly::coro::Task<void> start();
8181

82+
uint64_t getBufferSize() const { return consumer_.bufferSize; }
83+
8284
//
8385
// SinkServerCallback method
8486
//
@@ -103,6 +105,11 @@ class ServerSinkBridge : public TwoWayBridge<
103105
// end of TwoWayBridge methods
104106
//
105107

108+
using TwoWayBridge::serverClose;
109+
using TwoWayBridge::serverGetMessages;
110+
using TwoWayBridge::serverPush;
111+
using TwoWayBridge::serverWait;
112+
106113
private:
107114
ServerSinkBridge(
108115
SinkConsumerImpl&& sinkConsumer,

third-party/thrift/src/thrift/lib/cpp2/async/ServerSinkFactory.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ void ServerSinkFactory::setContextStack(ContextStack::UniquePtr contextStack) {
9292
contextStack_ = std::move(contextStack);
9393
}
9494

95+
ServerSinkFactory::ServerSinkFactory(
96+
ConsumerCallback* consumerCallback,
97+
uint64_t bufferSize,
98+
std::chrono::milliseconds chunkTimeout)
99+
: bufferSize_{bufferSize}, chunkTimeout_{chunkTimeout} {
100+
startFunction_ = [consumerCallback](
101+
uint64_t bufferSize,
102+
std::chrono::milliseconds chunkTimeout,
103+
folly::EventBase* evb,
104+
TilePtr&& interaction,
105+
ContextStack::UniquePtr contextStack,
106+
FirstResponsePayload&& firstResponsePayload,
107+
SinkClientCallback* clientCallback) {
108+
DCHECK(evb->isInEventBaseThread());
109+
SinkConsumerImpl sinkConsumer;
110+
sinkConsumer.bufferSize = bufferSize;
111+
sinkConsumer.chunkTimeout = chunkTimeout;
112+
sinkConsumer.interaction = std::move(interaction);
113+
sinkConsumer.contextStack = std::move(contextStack);
114+
115+
auto sink =
116+
new ServerSinkBridge(std::move(sinkConsumer), *evb, clientCallback);
117+
auto sinkPtr = sink->copy();
118+
119+
std::ignore = clientCallback->onFirstResponse(
120+
std::move(firstResponsePayload), evb, sink);
121+
122+
sink->serverPush(bufferSize);
123+
consumerCallback->provideSink(std::move(sinkPtr));
124+
};
125+
}
126+
95127
} // namespace apache::thrift::detail
96128

97129
#endif

third-party/thrift/src/thrift/lib/cpp2/async/ServerSinkFactory.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class ServerSinkFactory {
3636
FirstResponsePayload&&,
3737
SinkClientCallback*)>;
3838

39+
class ConsumerCallback {
40+
public:
41+
virtual void provideSink(ServerSinkBridge::Ptr sink) = 0;
42+
ConsumerCallback() = default;
43+
virtual ~ConsumerCallback() = default;
44+
};
45+
3946
explicit ServerSinkFactory();
4047

4148
explicit ServerSinkFactory(StartFunction&& fn);
@@ -46,6 +53,11 @@ class ServerSinkFactory {
4653
uint64_t bufferSize,
4754
std::chrono::milliseconds timeout);
4855

56+
explicit ServerSinkFactory(
57+
ConsumerCallback* consumerCallback,
58+
uint64_t bufferSize,
59+
std::chrono::milliseconds timeout);
60+
4961
void start(
5062
FirstResponsePayload&& payload,
5163
SinkClientCallback* callback,

0 commit comments

Comments
 (0)