@@ -20,6 +20,14 @@ import org.axonframework.messaging.responsetypes.ResponseTypes
20
20
import org.axonframework.queryhandling.QueryGateway
21
21
import java.util.*
22
22
import java.util.concurrent.CompletableFuture
23
+ import java.util.concurrent.TimeUnit
24
+ import java.util.stream.Stream
25
+
26
+ /* *
27
+ * Query Gateway extensions.
28
+ *
29
+ * @author Henrique Sena
30
+ */
23
31
24
32
/* *
25
33
* Reified version of [QueryGateway.query]
@@ -113,3 +121,114 @@ inline fun <reified R, reified Q> QueryGateway.queryOptional(query: Q): Completa
113
121
inline fun <reified R , reified Q > QueryGateway.queryOptional (queryName : String , query : Q ): CompletableFuture <Optional <R >> {
114
122
return this .query(queryName, query, ResponseTypes .optionalInstanceOf(R ::class .java))
115
123
}
124
+
125
+ /* *
126
+ * Reified version of [QueryGateway.scatterGather]
127
+ * which expects an Stream object as a response using [org.axonframework.messaging.responsetypes.InstanceResponseType]
128
+ * @param query Query to send
129
+ * @param timeout a timeout for the query
130
+ * @param timeUnit the selected TimeUnit for the given timeout
131
+ * @param [Q] the type of payload of the query
132
+ * @param [R] the response class contained in the given responseType
133
+ * @return [Stream] a stream of results
134
+ * @see QueryGateway.scatterGather
135
+ * @see ResponseTypes
136
+ * @since 0.2.0
137
+ */
138
+ inline fun <reified R , reified Q > QueryGateway.scatterGather (query : Q , timeout : Long ,
139
+ timeUnit : TimeUnit ): Stream <R > {
140
+ return this .scatterGather(query, ResponseTypes .instanceOf(R ::class .java), timeout, timeUnit)
141
+ }
142
+
143
+ /* *
144
+ * Reified version of [QueryGateway.scatterGather] with explicit query name
145
+ * which expects an Stream object as a response using [org.axonframework.messaging.responsetypes.InstanceResponseType]
146
+ * @param query Query to send
147
+ * @param queryName Name of the query
148
+ * @param timeout a timeout for the query
149
+ * @param timeUnit the selected TimeUnit for the given timeout
150
+ * @param [Q] the type of payload of the query
151
+ * @param [R] the response class contained in the given responseType
152
+ * @return [Stream] a stream of results
153
+ * @see QueryGateway.scatterGather
154
+ * @see ResponseTypes
155
+ * @since 0.2.0
156
+ */
157
+ inline fun <reified R , reified Q > QueryGateway.scatterGather (queryName : String , query : Q , timeout : Long ,
158
+ timeUnit : TimeUnit ): Stream <R > {
159
+ return this .scatterGather(queryName, query, ResponseTypes .instanceOf(R ::class .java), timeout, timeUnit)
160
+ }
161
+
162
+ /* *
163
+ * Reified version of [QueryGateway.scatterGather]
164
+ * which expects a collection as a response using [org.axonframework.messaging.responsetypes.MultipleInstancesResponseType]
165
+ * @param query Query to send
166
+ * @param timeout a timeout for the query
167
+ * @param timeUnit the selected TimeUnit for the given timeout
168
+ * @param [Q] the type of payload of the query
169
+ * @param [R] the response class contained in the given responseType
170
+ * @return [Stream] a stream of results
171
+ * @see QueryGateway.scatterGather
172
+ * @see ResponseTypes
173
+ * @since 0.2.0
174
+ */
175
+ inline fun <reified R , reified Q > QueryGateway.scatterGatherMany (query : Q , timeout : Long ,
176
+ timeUnit : TimeUnit ): Stream <List <R >> {
177
+ return this .scatterGather(query, ResponseTypes .multipleInstancesOf(R ::class .java), timeout, timeUnit)
178
+ }
179
+
180
+ /* *
181
+ * Reified version of [QueryGateway.scatterGather] with explicit query name
182
+ * which expects a collection as a response using [org.axonframework.messaging.responsetypes.MultipleInstancesResponseType]
183
+ * @param query Query to send
184
+ * @param queryName Name of the query
185
+ * @param timeout a timeout for the query
186
+ * @param timeUnit the selected TimeUnit for the given timeout
187
+ * @param [Q] the type of payload of the query
188
+ * @param [R] the response class contained in the given responseType
189
+ * @return [Stream] a stream of results
190
+ * @see QueryGateway.scatterGather
191
+ * @see ResponseTypes
192
+ * @since 0.2.0
193
+ */
194
+ inline fun <reified R , reified Q > QueryGateway.scatterGatherMany (queryName : String , query : Q , timeout : Long ,
195
+ timeUnit : TimeUnit ): Stream <List <R >> {
196
+ return this .scatterGather(queryName, query, ResponseTypes .multipleInstancesOf(R ::class .java), timeout, timeUnit)
197
+ }
198
+
199
+ /* *
200
+ * Reified version of [QueryGateway.scatterGather]
201
+ * which expects a collection as a response using [org.axonframework.messaging.responsetypes.OptionalResponseType]
202
+ * @param query Query to send
203
+ * @param timeout a timeout for the query
204
+ * @param timeUnit the selected TimeUnit for the given timeout
205
+ * @param [Q] the type of payload of the query
206
+ * @param [R] the response class contained in the given responseType
207
+ * @return [Stream] a stream of results
208
+ * @see QueryGateway.scatterGather
209
+ * @see ResponseTypes
210
+ * @since 0.2.0
211
+ */
212
+ inline fun <reified R , reified Q > QueryGateway.scatterGatherOptional (query : Q , timeout : Long ,
213
+ timeUnit : TimeUnit ): Stream <Optional <R >> {
214
+ return this .scatterGather(query, ResponseTypes .optionalInstanceOf(R ::class .java), timeout, timeUnit)
215
+ }
216
+
217
+ /* *
218
+ * Reified version of [QueryGateway.scatterGather] with explicit query name
219
+ * which expects a collection as a response using [org.axonframework.messaging.responsetypes.OptionalResponseType]
220
+ * @param query Query to send
221
+ * @param queryName Name of the query
222
+ * @param timeout a timeout for the query
223
+ * @param timeUnit the selected TimeUnit for the given timeout
224
+ * @param [Q] the type of payload of the query
225
+ * @param [R] the response class contained in the given responseType
226
+ * @return [Stream] a stream of results
227
+ * @see QueryGateway.scatterGather
228
+ * @see ResponseTypes
229
+ * @since 0.2.0
230
+ */
231
+ inline fun <reified R , reified Q > QueryGateway.scatterGatherOptional (queryName : String , query : Q , timeout : Long ,
232
+ timeUnit : TimeUnit ): Stream <Optional <R >> {
233
+ return this .scatterGather(queryName, query, ResponseTypes .optionalInstanceOf(R ::class .java), timeout, timeUnit)
234
+ }
0 commit comments