Skip to content

Commit

Permalink
Refactor: make fields private, avoid overriding failures, avoid calli…
Browse files Browse the repository at this point in the history
…ng complete method on SD failures.
  • Loading branch information
aureamunoz committed Oct 11, 2023
1 parent 5a79349 commit 0cc94ba
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@

public class StorkObservationPoints {
// Handler / Reporter
protected final StorkEventHandler handler;
private final StorkEventHandler handler;

// Metadata
protected final String serviceName;
protected final String serviceDiscoveryType;
protected final String serviceSelectionType;
private final String serviceName;
private final String serviceDiscoveryType;
private final String serviceSelectionType;

// Time
protected final long begin;
protected volatile long endOfServiceDiscovery;
protected volatile long endOfServiceSelection;
private final long begin;
private volatile long endOfServiceDiscovery;
private volatile long endOfServiceSelection;

// Service discovery data
protected volatile int instancesCount = -1;
private volatile int instancesCount = -1;

// Service selection data
protected volatile long selectedInstanceId = -1L;
private volatile long selectedInstanceId = -1L;

// Overall status
protected volatile boolean done;
protected volatile boolean serviceDiscoverySuccessful = false;
protected volatile Throwable failure;
private volatile boolean done;
private volatile boolean serviceDiscoverySuccessful = false;
private volatile Throwable failure;

public StorkObservationPoints(String serviceName, String serviceDiscoveryType, String serviceSelectionType,
StorkEventHandler handler) {
Expand All @@ -52,7 +52,6 @@ public void onServiceDiscoverySuccess(List<ServiceInstance> instances) {
public void onServiceDiscoveryFailure(Throwable throwable) {
this.endOfServiceDiscovery = System.nanoTime();
this.failure = throwable;
this.handler.complete(this);
}

public void onServiceSelectionSuccess(long id) {
Expand All @@ -64,7 +63,9 @@ public void onServiceSelectionSuccess(long id) {

public void onServiceSelectionFailure(Throwable throwable) {
this.endOfServiceSelection = System.nanoTime();
this.failure = throwable;
if (failure != throwable) {
this.failure = throwable;
}
this.handler.complete(this);
}

Expand Down

0 comments on commit 0cc94ba

Please sign in to comment.