1 /**
2  * Autogenerated by Thrift
3  *
4  * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5  *  @generated
6  */
7 
8 package test.fixtures.basic;
9 
10 import static com.facebook.swift.service.SwiftConstants.STICKY_HASH_KEY;
11 
12 import java.util.*;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.atomic.AtomicLong;
15 import org.apache.thrift.protocol.*;
16 import org.apache.thrift.ClientPushMetadata;
17 import org.apache.thrift.InteractionCreate;
18 import org.apache.thrift.InteractionTerminate;
19 import com.facebook.thrift.client.ResponseWrapper;
20 import com.facebook.thrift.client.RpcOptions;
21 
22 public class DbMixedStackArgumentsReactiveClient
23   implements DbMixedStackArguments.Reactive {
24   private static final AtomicLong _interactionCounter = new AtomicLong(0);
25 
26   private final org.apache.thrift.ProtocolId _protocolId;
27   private final reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient;
28   private final Map<String, String> _headers;
29   private final Map<String, String> _persistentHeaders;
30   private final Set<Long> _activeInteractions;
31 
32   private static final TField _getDataByKey0_KEY_FIELD_DESC = new TField("key", TType.STRING, (short)1);
33   private static final java.util.Map<Short, com.facebook.thrift.payload.Reader> _getDataByKey0_EXCEPTION_READERS = java.util.Collections.emptyMap();
34   private static final TField _getDataByKey1_KEY_FIELD_DESC = new TField("key", TType.STRING, (short)1);
35   private static final java.util.Map<Short, com.facebook.thrift.payload.Reader> _getDataByKey1_EXCEPTION_READERS = java.util.Collections.emptyMap();
36 
37   static {
38   }
39 
DbMixedStackArgumentsReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient)40   public DbMixedStackArgumentsReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient) {
41 
42     this._protocolId = _protocolId;
43     this._rpcClient = _rpcClient;
44     this._headers = java.util.Collections.emptyMap();
45     this._persistentHeaders = java.util.Collections.emptyMap();
46     this._activeInteractions = ConcurrentHashMap.newKeySet();
47   }
48 
DbMixedStackArgumentsReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient, Map<String, String> _headers, Map<String, String> _persistentHeaders)49   public DbMixedStackArgumentsReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient, Map<String, String> _headers, Map<String, String> _persistentHeaders) {
50     this(_protocolId, _rpcClient, _headers, _persistentHeaders, new AtomicLong(), ConcurrentHashMap.newKeySet());
51   }
52 
DbMixedStackArgumentsReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient, Map<String, String> _headers, Map<String, String> _persistentHeaders, AtomicLong interactionCounter, Set<Long> activeInteractions)53   public DbMixedStackArgumentsReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient, Map<String, String> _headers, Map<String, String> _persistentHeaders, AtomicLong interactionCounter, Set<Long> activeInteractions) {
54 
55     this._protocolId = _protocolId;
56     this._rpcClient = _rpcClient;
57     this._headers = _headers;
58     this._persistentHeaders = _persistentHeaders;
59     this._activeInteractions = activeInteractions;
60   }
61 
62   @java.lang.Override
dispose()63   public void dispose() {}
64 
_creategetDataByKey0Writer(final String key)65   private com.facebook.thrift.payload.Writer _creategetDataByKey0Writer(final String key) {
66     return oprot -> {
67       try {
68         {
69           oprot.writeFieldBegin(_getDataByKey0_KEY_FIELD_DESC);
70 
71           String _iter0 = key;
72 
73           oprot.writeString(key);
74           oprot.writeFieldEnd();
75         }
76 
77 
78       } catch (Throwable _e) {
79         throw reactor.core.Exceptions.propagate(_e);
80       }
81     };
82   }
83 
84   private static final com.facebook.thrift.payload.Reader _getDataByKey0_READER =
85     oprot -> {
86               try {
87                 byte[] _r = oprot.readBinary().array();
88                 return _r;
89 
90 
91               } catch (Throwable _e) {
92                 throw reactor.core.Exceptions.propagate(_e);
93               }
94             };
95 
96 
97   @java.lang.Override
98   public reactor.core.publisher.Mono<com.facebook.thrift.client.ResponseWrapper<byte[]>> getDataByKey0Wrapper(final String key,  final com.facebook.thrift.client.RpcOptions rpcOptions) {
99     return _rpcClient
100       .flatMap(_rpc -> {
101         org.apache.thrift.RequestRpcMetadata _metadata = new org.apache.thrift.RequestRpcMetadata.Builder()
102                 .setName("getDataByKey0")
103                 .setKind(org.apache.thrift.RpcKind.SINGLE_REQUEST_SINGLE_RESPONSE)
104                 .setOtherMetadata(getHeaders(rpcOptions))
105                 .setProtocol(_protocolId)
106                 .build();
107 
108             com.facebook.thrift.payload.ClientRequestPayload<byte[]> _crp =
109                 com.facebook.thrift.payload.ClientRequestPayload.create(
110                     _creategetDataByKey0Writer(key),
111                     _getDataByKey0_READER,
112                     _getDataByKey0_EXCEPTION_READERS,
113                     _metadata,
114                     java.util.Collections.emptyMap());
115 
116             return _rpc
117                 .singleRequestSingleResponse(_crp, rpcOptions).doOnNext(_p -> {if(_p.getException() != null) throw reactor.core.Exceptions.propagate(_p.getException());});
118       });
119   }
120 
121   @java.lang.Override
122   public reactor.core.publisher.Mono<byte[]> getDataByKey0(final String key,  final com.facebook.thrift.client.RpcOptions rpcOptions) {
123     return getDataByKey0Wrapper(key,  rpcOptions).map(_p -> _p.getData());
124   }
125 
126   @java.lang.Override
127   public reactor.core.publisher.Mono<byte[]> getDataByKey0(final String key) {
128     return getDataByKey0(key,  com.facebook.thrift.client.RpcOptions.EMPTY);
129   }
130 
131   private com.facebook.thrift.payload.Writer _creategetDataByKey1Writer(final String key) {
132     return oprot -> {
133       try {
134         {
135           oprot.writeFieldBegin(_getDataByKey1_KEY_FIELD_DESC);
136 
137           String _iter0 = key;
138 
139           oprot.writeString(key);
140           oprot.writeFieldEnd();
141         }
142 
143 
144       } catch (Throwable _e) {
145         throw reactor.core.Exceptions.propagate(_e);
146       }
147     };
148   }
149 
150   private static final com.facebook.thrift.payload.Reader _getDataByKey1_READER =
151     oprot -> {
152               try {
153                 byte[] _r = oprot.readBinary().array();
154                 return _r;
155 
156 
157               } catch (Throwable _e) {
158                 throw reactor.core.Exceptions.propagate(_e);
159               }
160             };
161 
162 
163   @java.lang.Override
164   public reactor.core.publisher.Mono<com.facebook.thrift.client.ResponseWrapper<byte[]>> getDataByKey1Wrapper(final String key,  final com.facebook.thrift.client.RpcOptions rpcOptions) {
165     return _rpcClient
166       .flatMap(_rpc -> {
167         org.apache.thrift.RequestRpcMetadata _metadata = new org.apache.thrift.RequestRpcMetadata.Builder()
168                 .setName("getDataByKey1")
169                 .setKind(org.apache.thrift.RpcKind.SINGLE_REQUEST_SINGLE_RESPONSE)
170                 .setOtherMetadata(getHeaders(rpcOptions))
171                 .setProtocol(_protocolId)
172                 .build();
173 
174             com.facebook.thrift.payload.ClientRequestPayload<byte[]> _crp =
175                 com.facebook.thrift.payload.ClientRequestPayload.create(
176                     _creategetDataByKey1Writer(key),
177                     _getDataByKey1_READER,
178                     _getDataByKey1_EXCEPTION_READERS,
179                     _metadata,
180                     java.util.Collections.emptyMap());
181 
182             return _rpc
183                 .singleRequestSingleResponse(_crp, rpcOptions).doOnNext(_p -> {if(_p.getException() != null) throw reactor.core.Exceptions.propagate(_p.getException());});
184       });
185   }
186 
187   @java.lang.Override
188   public reactor.core.publisher.Mono<byte[]> getDataByKey1(final String key,  final com.facebook.thrift.client.RpcOptions rpcOptions) {
189     return getDataByKey1Wrapper(key,  rpcOptions).map(_p -> _p.getData());
190   }
191 
192   @java.lang.Override
193   public reactor.core.publisher.Mono<byte[]> getDataByKey1(final String key) {
194     return getDataByKey1(key,  com.facebook.thrift.client.RpcOptions.EMPTY);
195   }
196 
197 
198 
199   private Map<String, String> getHeaders(com.facebook.thrift.client.RpcOptions rpcOptions) {
200       Map<String, String> headers = new HashMap<>();
201       if (rpcOptions.getRequestHeaders() != null && !rpcOptions.getRequestHeaders().isEmpty()) {
202           headers.putAll(rpcOptions.getRequestHeaders());
203       }
204       if (_headers != null && !_headers.isEmpty()) {
205           headers.putAll(_headers);
206       }
207       if (_persistentHeaders != null && !_persistentHeaders.isEmpty()) {
208           headers.putAll(_persistentHeaders);
209       }
210       return headers;
211   }
212 }
213