21
21
* http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/schedulers/Schedulers.html
22
22
23
23
## preface
24
+
24
25
The main goal of this project is to explore basic features of
25
26
` reactive streams ` introduced in ` Java 9 ` :
27
+
26
28
* ** Publisher**
27
29
* ** Subscriber**
28
30
* ** Subscription** (** Backpressure** )
@@ -198,6 +200,7 @@ then closes the connection and disconnects from the server
198
200
```
199
201
200
202
## definitions
203
+
201
204
* **[Flow.Publisher](https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.Publisher.html)** -
202
205
source of data
203
206
* **[Flow.Subscriber](https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.Subscriber.html)** -
@@ -213,19 +216,24 @@ the only one implementation (in `JDK`) of `Flow.Publisher`; has ability to async
213
216
items to current subscribers until it is closed.
214
217
215
218
## data flow
219
+
216
220
```
217
221
PUBLISHER -> PROCESSOR -> PROCESSOR -> SUBSCRIBER
218
222
```
223
+
219
224
We have two scenarios:
225
+
220
226
* `Publisher` is slow, `Subscriber` is fast (best scenario)
221
227
* `Publisher` is fast, `Subscriber` is slow (the `Subscriber` must deal
228
+
222
229
with excessive data - the most naive approach is just to drop all
223
- excessive data - so the data will be irrevitable )
230
+ excessive data - so the data will be lost )
224
231
225
232
Note that if we have multiple `subscribers` and one `publisher` - they
226
233
are receiving elements in the same order.
227
234
228
235
## interaction steps
236
+
229
237
1. implement `Flow.Publisher` (using, for example `SubmissionPublisher<T>`) and `Flow.Subscriber`
230
238
1. the subscriber attempts to subscribe to the publisher by calling the
231
239
`subscribe(Flow.Subscriber<? super T> subscriber)
@@ -250,7 +258,9 @@ the end of stream, and interaction ends
250
258
cancellation if there were pending requests before
251
259
252
260
## additional remarks
261
+
253
262
Correctly `@Override` method `onSubscribe` looks as below:
263
+
254
264
```
255
265
@Override
256
266
public void onSubscribe(Flow.Subscription subscription) {
@@ -276,10 +286,14 @@ one, we don't accept any furthers)
276
286
implementations
277
287
278
288
## tests
289
+
279
290
We test it by running:
291
+
280
292
* `RunAnswer`
281
293
* `RunWorkshop`
294
+
282
295
the output should be:
296
+
283
297
```
284
298
onNext, item: new mapping: 2
285
299
onNext, item: new mapping: 4
0 commit comments