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.adapter;
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 ServiceReactiveClient
23   implements Service.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 _func_ARG1_FIELD_DESC = new TField("arg1", TType.STRING, (short)1);
33   private static final TField _func_ARG2_FIELD_DESC = new TField("arg2", TType.STRING, (short)2);
34   private static final TField _func_ARG3_FIELD_DESC = new TField("arg3", TType.STRUCT, (short)3);
35   private static final java.util.Map<Short, com.facebook.thrift.payload.Reader> _func_EXCEPTION_READERS = java.util.Collections.emptyMap();
36 
37   static {
38   }
39 
ServiceReactiveClient(org.apache.thrift.ProtocolId _protocolId, reactor.core.publisher.Mono<? extends com.facebook.thrift.client.RpcClient> _rpcClient)40   public ServiceReactiveClient(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 
ServiceReactiveClient(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 ServiceReactiveClient(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 
ServiceReactiveClient(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 ServiceReactiveClient(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 
_createfuncWriter(final String arg1, final String arg2, final test.fixtures.adapter.Foo arg3)65   private com.facebook.thrift.payload.Writer _createfuncWriter(final String arg1, final String arg2, final test.fixtures.adapter.Foo arg3) {
66     return oprot -> {
67       try {
68         {
69           oprot.writeFieldBegin(_func_ARG1_FIELD_DESC);
70 
71           String _iter0 = arg1;
72 
73           oprot.writeString(arg1);
74           oprot.writeFieldEnd();
75         }
76 
77         {
78           oprot.writeFieldBegin(_func_ARG2_FIELD_DESC);
79 
80           String _iter0 = arg2;
81 
82           oprot.writeString(arg2);
83           oprot.writeFieldEnd();
84         }
85 
86         {
87           oprot.writeFieldBegin(_func_ARG3_FIELD_DESC);
88 
89           test.fixtures.adapter.Foo _iter0 = arg3;
90 
91           _iter0.write0(oprot);
92           oprot.writeFieldEnd();
93         }
94 
95 
96       } catch (Throwable _e) {
97         throw reactor.core.Exceptions.propagate(_e);
98       }
99     };
100   }
101 
102   private static final com.facebook.thrift.payload.Reader _func_READER =
103     oprot -> {
104               try {
105                 int _r = oprot.readI32();
106                 return _r;
107 
108 
109               } catch (Throwable _e) {
110                 throw reactor.core.Exceptions.propagate(_e);
111               }
112             };
113 
114 
115   @java.lang.Override
116   public reactor.core.publisher.Mono<com.facebook.thrift.client.ResponseWrapper<Integer>> funcWrapper(final String arg1, final String arg2, final test.fixtures.adapter.Foo arg3,  final com.facebook.thrift.client.RpcOptions rpcOptions) {
117     return _rpcClient
118       .flatMap(_rpc -> {
119         org.apache.thrift.RequestRpcMetadata _metadata = new org.apache.thrift.RequestRpcMetadata.Builder()
120                 .setName("func")
121                 .setKind(org.apache.thrift.RpcKind.SINGLE_REQUEST_SINGLE_RESPONSE)
122                 .setOtherMetadata(getHeaders(rpcOptions))
123                 .setProtocol(_protocolId)
124                 .build();
125 
126             com.facebook.thrift.payload.ClientRequestPayload<Integer> _crp =
127                 com.facebook.thrift.payload.ClientRequestPayload.create(
128                     _createfuncWriter(arg1, arg2, arg3),
129                     _func_READER,
130                     _func_EXCEPTION_READERS,
131                     _metadata,
132                     java.util.Collections.emptyMap());
133 
134             return _rpc
135                 .singleRequestSingleResponse(_crp, rpcOptions).doOnNext(_p -> {if(_p.getException() != null) throw reactor.core.Exceptions.propagate(_p.getException());});
136       });
137   }
138 
139   @java.lang.Override
140   public reactor.core.publisher.Mono<Integer> func(final String arg1, final String arg2, final test.fixtures.adapter.Foo arg3,  final com.facebook.thrift.client.RpcOptions rpcOptions) {
141     return funcWrapper(arg1, arg2, arg3,  rpcOptions).map(_p -> _p.getData());
142   }
143 
144   @java.lang.Override
145   public reactor.core.publisher.Mono<Integer> func(final String arg1, final String arg2, final test.fixtures.adapter.Foo arg3) {
146     return func(arg1, arg2, arg3,  com.facebook.thrift.client.RpcOptions.EMPTY);
147   }
148 
149 
150 
151   private Map<String, String> getHeaders(com.facebook.thrift.client.RpcOptions rpcOptions) {
152       Map<String, String> headers = new HashMap<>();
153       if (rpcOptions.getRequestHeaders() != null && !rpcOptions.getRequestHeaders().isEmpty()) {
154           headers.putAll(rpcOptions.getRequestHeaders());
155       }
156       if (_headers != null && !_headers.isEmpty()) {
157           headers.putAll(_headers);
158       }
159       if (_persistentHeaders != null && !_persistentHeaders.isEmpty()) {
160           headers.putAll(_persistentHeaders);
161       }
162       return headers;
163   }
164 }
165