Skip to content

Commit

Permalink
Added more result methods to kerb
Browse files Browse the repository at this point in the history
  • Loading branch information
Smudgge committed Nov 29, 2023
1 parent 9d4cb74 commit da464f0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ public class CompletableResultSet<T> {
private static final int LOCK_TIME_MILLS = 100;

private final @NotNull List<T> 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.
Expand All @@ -58,9 +65,29 @@ public class CompletableResultSet<T> {
*/
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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -281,7 +308,8 @@ public CompletableResultSet(int size) {
*
* @return This instance.
*/
public @NotNull CompletableResultSet<T> complete() {
public @NotNull CompletableResultSet<T> complete(@NotNull CompletableResultSet.CompleteReason reason) {
this.completeReason = reason;
this.isComplete = true;
return this;
}
Expand Down Expand Up @@ -370,7 +398,7 @@ public boolean containsCancelled() {
* @return This instance.
*/
public @NotNull CompletableResultSet<T> setContainsCompleted(boolean containsCompleted) {
this.containsCancelled = containsCompleted;
this.containsCompleted = containsCompleted;
return this;
}

Expand Down

0 comments on commit da464f0

Please sign in to comment.