Clover icon

sunshower-sdk

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

File ManagedChannel.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
31% of files have more coverage

Code metrics

4
20
7
1
70
57
9
0.45
2.86
7
1.29

Classes

Class Line # Actions
ManagedChannel 8 20 9
0.4838709548.4%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.sdk.channel;
2   
3    import lombok.Synchronized;
4    import org.reactivestreams.Subscriber;
5   
6    import java.util.concurrent.Future;
7   
 
8    public class ManagedChannel<I, T> implements Channel<T>, Runnable {
9   
10    final I id;
11    final Channel<T> delegate;
12    final ReactiveChannelSelector selector;
13   
14    private volatile Future<T> future;
15    private volatile Status status = Status.Unknown;
16   
 
17  2 toggle ManagedChannel(ReactiveChannelSelector selector, I id, Channel<T> delegate) {
18  2 this.id = id;
19  2 this.selector = selector;
20  2 this.delegate = delegate;
21    }
22   
 
23  0 toggle @Override
24    public Status getStatus() {
25  0 return status;
26    }
27   
 
28  2 toggle @Override
29    public void start() {
30  2 selector.submit(this);
31    }
32   
 
33  0 toggle @Override
34    @Synchronized
35    public void stop() {
36  0 if (future == null) {
37  0 throw new IllegalStateException("Task hasn't been started yet");
38    }
39  0 status = Status.Stopping;
40  0 if (future.cancel(true)) {
41  0 status = Status.Stopped;
42    } else {
43  0 status = Status.Unknown;
44    }
45    }
46   
 
47  2 toggle @Override
48    public void subscribe(Subscriber<? super T> s) {
49  2 delegate.subscribe(s);
50    }
51   
 
52  2 toggle @Override
53    public void run() {
54  2 status = Status.Started;
55  2 try {
56  2 delegate.start();
57  0 status = Status.Stopping;
58    } finally {
59  0 selector.remove(id);
60  0 status = Status.Stopped;
61    }
62    }
63   
 
64  2 toggle @Synchronized
65    public void setFuture(Future<T> future) {
66  2 status = Status.Starting;
67  2 this.future = future;
68   
69    }
70    }