diff --git a/.idea/misc.xml b/.idea/misc.xml index 9df5cdf..e3eedd3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/main/java/com/github/kerbity/kerb/client/KerbClient.java b/src/main/java/com/github/kerbity/kerb/client/KerbClient.java index 118d94f..2d66377 100644 --- a/src/main/java/com/github/kerbity/kerb/client/KerbClient.java +++ b/src/main/java/com/github/kerbity/kerb/client/KerbClient.java @@ -234,7 +234,7 @@ public int getPort() { if (resultCollection.isComplete()) return; // Complete the result collection. - resultCollection.complete(); + resultCollection.complete(CompletableResultSet.CompleteReason.TIME); // Remove the result collection from the map. this.removeResult(sequenceIdentifier); diff --git a/src/main/java/com/github/kerbity/kerb/result/CompletableResultSet.java b/src/main/java/com/github/kerbity/kerb/result/CompletableResultSet.java index 840248e..47c8676 100644 --- a/src/main/java/com/github/kerbity/kerb/result/CompletableResultSet.java +++ b/src/main/java/com/github/kerbity/kerb/result/CompletableResultSet.java @@ -43,12 +43,19 @@ public class CompletableResultSet { private static final int LOCK_TIME_MILLS = 100; private final @NotNull List result; + private @NotNull CompletableResultSet.CompleteReason completeReason; private final int size; private boolean isComplete; private boolean containsCancelled; private boolean containsCompleted; private Object defaultSettableValue; + public enum CompleteReason { + UNCOMPLETED, // The results haven't been completed. + TIME, // The clients took too much time to respond. + SIZE, // The result set was completed. + } + /** * Used to create a completable * result collection. @@ -58,9 +65,29 @@ public class CompletableResultSet { */ public CompletableResultSet(int size) { this.result = new ArrayList<>(); + this.completeReason = CompleteReason.UNCOMPLETED; this.size = size; this.isComplete = false; this.containsCancelled = false; + this.containsCompleted = false; + } + + /** + * Used to get the reason the results were completed. + * + * @return The reason the results where completed. + */ + public @NotNull CompleteReason getCompleteReason() { + return this.completeReason; + } + + /** + * Used to get the expected size of the result list. + * + * @return The expected size of the result list. + */ + public int getSize() { + return this.size; } /** @@ -251,8 +278,8 @@ public CompletableResultSet(int size) { this.result.add(result); // Auto completes the completable result collection. - if (this.result.size() == this.size) { - this.complete(); + if (this.result.size() >= this.size) { + this.complete(CompleteReason.SIZE); } return this; @@ -281,7 +308,8 @@ public CompletableResultSet(int size) { * * @return This instance. */ - public @NotNull CompletableResultSet complete() { + public @NotNull CompletableResultSet complete(@NotNull CompletableResultSet.CompleteReason reason) { + this.completeReason = reason; this.isComplete = true; return this; } @@ -370,7 +398,7 @@ public boolean containsCancelled() { * @return This instance. */ public @NotNull CompletableResultSet setContainsCompleted(boolean containsCompleted) { - this.containsCancelled = containsCompleted; + this.containsCompleted = containsCompleted; return this; }