Clover icon

sunshower-sdk

  1. Project Clover database Sat May 12 2018 05:15:40 UTC
  2. Package io.sunshower.sdk.channel

File CurrentContextSubscriber.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
26% of files have more coverage

Code metrics

0
7
5
1
42
34
5
0.71
1.4
5
1

Classes

Class Line # Actions
CurrentContextSubscriber 11 7 5
0.583333358.3%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.sdk.channel;
2   
3    import org.reactivestreams.Subscriber;
4    import org.reactivestreams.Subscription;
5   
6    import javax.ws.rs.core.MediaType;
7    import javax.ws.rs.sse.OutboundSseEvent;
8    import javax.ws.rs.sse.Sse;
9    import javax.ws.rs.sse.SseEventSink;
10   
 
11    public class CurrentContextSubscriber<T> implements Subscriber<T> {
12    private final Sse sse;
13    private final SseEventSink sink;
14    private Subscription subscription;
15    private final MediaType mediaType;
16   
 
17  2 toggle public CurrentContextSubscriber(Sse sse, MediaType mediaType, SseEventSink sink) {
18  2 this.sse = sse;
19  2 this.sink = sink;
20  2 this.mediaType = mediaType;
21    }
22   
 
23  0 toggle @Override
24    public void onSubscribe(Subscription s) {
25  0 this.subscription = s;
26    }
27   
 
28  56 toggle @Override
29    public void onNext(T t) {
30  56 OutboundSseEvent event =
31    sse.newEventBuilder().mediaType(MediaType.APPLICATION_JSON_TYPE).data(t).build();
32  56 sink.send(event);
33    }
34   
 
35  0 toggle @Override
36    public void onError(Throwable t) {}
37   
 
38  0 toggle @Override
39    public void onComplete() {
40  0 sink.close();
41    }
42    }