Skip to content

Commit

Permalink
Client optimisations and potential fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Smudgge committed Jul 9, 2024
1 parent cb87891 commit 9a13b7c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
44 changes: 33 additions & 11 deletions src/main/java/com/github/kerbity/kerb/client/KerbClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ public int getMaxReconnectionAttempts() {
return this.objectListenerList;
}

/**
* Used to get the list of sequence identifiers
* that are currently active.
*
* @return The list of sequence identifiers.
*/
public @NotNull List<String> getAllSequences() {
return this.resultMap.keySet().stream().toList();
}

/**
* Used to get the result from the sequence identifier.
*
Expand Down Expand Up @@ -374,16 +384,24 @@ public CompletableResultSet<Integer> getAmountOfClients() {
// Create a new sequence identifier.
String sequenceIdentifier = UUID.randomUUID().toString();

// Send packet.
this.send(new Packet()
.setType(PacketType.CLIENT_AMOUNT)
.setSequenceIdentifier(sequenceIdentifier)
.getPacketString()
);

// Create a result collection.
CompletableResultSet<Integer> resultCollection = new CompletableResultSet<>(1);

// Register the result collection before sending
// in case it comes back too quick.
this.addResult(sequenceIdentifier, resultCollection);

// Thread the sending of the packet to stop wait times.
new Thread(() -> {

// Send the packet.
this.send(new Packet()
.setType(PacketType.CLIENT_AMOUNT)
.setSequenceIdentifier(sequenceIdentifier)
.getPacketString()
);
}).start();

return resultCollection;
}

Expand Down Expand Up @@ -497,10 +515,14 @@ public boolean isConnected() {
CompletableResultSet<T> resultCollection = new CompletableResultSet<>(amount);
this.addResult(sequenceIdentifier, resultCollection);

// Send the event packet.
this.send(event.packet()
.setSequenceIdentifier(sequenceIdentifier)
.getPacketString());
// Thread the sending of the packet to stop wait times.
new Thread(() -> {

// Send the event packet.
this.send(event.packet()
.setSequenceIdentifier(sequenceIdentifier)
.getPacketString());
});

return resultCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void interpret(@NotNull Packet packet) {

// Check if the result collection is null.
if (resultCollection == null) {
this.client.getLogger().warn("Packet referenced a result collection that doesnt exist. packet=" + packet);
this.client.getLogger().warn("Packet referenced a result collection that doesnt exist. packet=" + packet);
this.client.getLogger().warn("Ongoing sequences: " + this.client.getAllSequences());
return;
}

Expand Down

0 comments on commit 9a13b7c

Please sign in to comment.