| 1 | package com.jsql.view.subscriber; | |
| 2 | ||
| 3 | import com.jsql.util.LogLevelUtil; | |
| 4 | import org.apache.logging.log4j.LogManager; | |
| 5 | import org.apache.logging.log4j.Logger; | |
| 6 | ||
| 7 | import javax.swing.*; | |
| 8 | import java.util.concurrent.Flow.Subscriber; | |
| 9 | import java.util.concurrent.Flow.Subscription; | |
| 10 | ||
| 11 | public abstract class AbstractSubscriber implements Subscriber<Seal> { | |
| 12 | ||
| 13 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 14 | ||
| 15 | private Subscription subscription; | |
| 16 | ||
| 17 | @Override | |
| 18 | public void onSubscribe(Subscription subscription) { | |
| 19 | this.subscription = subscription; | |
| 20 |
1
1. onSubscribe : removed call to java/util/concurrent/Flow$Subscription::request → NO_COVERAGE |
subscription.request(1); // enable receiving items |
| 21 | } | |
| 22 | ||
| 23 | @Override | |
| 24 | public void onNext(Seal request) { | |
| 25 |
1
1. onNext : removed call to java/util/concurrent/Flow$Subscription::request → NO_COVERAGE |
this.subscription.request(1); |
| 26 | ||
| 27 | // Display model thread name in logs instead of the observer name | |
| 28 | String nameThread = Thread.currentThread().getName(); | |
| 29 |
1
1. onNext : removed call to javax/swing/SwingUtilities::invokeLater → NO_COVERAGE |
SwingUtilities.invokeLater(() -> { |
| 30 |
1
1. lambda$onNext$0 : removed call to java/lang/Thread::setName → NO_COVERAGE |
Thread.currentThread().setName("from " + nameThread); |
| 31 |
1
1. lambda$onNext$0 : removed call to com/jsql/view/subscriber/AbstractSubscriber::execute → NO_COVERAGE |
this.execute(request); |
| 32 | }); | |
| 33 | } | |
| 34 | ||
| 35 | protected abstract void execute(Seal request); | |
| 36 | ||
| 37 | @Override | |
| 38 | public void onError(Throwable e) { | |
| 39 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 40 | } | |
| 41 | ||
| 42 | @Override | |
| 43 | public void onComplete() { | |
| 44 | // Nothing | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Observer pattern.<br> | |
| 49 | * Receive an update order from the model:<br> | |
| 50 | * - Use the Request message to get the Interaction class,<br> | |
| 51 | * - Pass the parameters to that class. | |
| 52 | */ | |
| 53 | public Subscription getSubscription() { | |
| 54 |
1
1. getSubscription : replaced return value with null for com/jsql/view/subscriber/AbstractSubscriber::getSubscription → NO_COVERAGE |
return this.subscription; |
| 55 | } | |
| 56 | } | |
Mutations | ||
| 20 |
1.1 |
|
| 25 |
1.1 |
|
| 29 |
1.1 |
|
| 30 |
1.1 |
|
| 31 |
1.1 |
|
| 54 |
1.1 |