Skip to content

Commit

Permalink
v1.20
Browse files Browse the repository at this point in the history
 - changed access to lastAction in client class, which helps for server-based client that can now override this method
 - reduced ping sent out depending on lastAction
 - fixed wrong event count in metrics (should have been five times higher)
  • Loading branch information
matsfunk committed Dec 30, 2020
1 parent 23c2906 commit b25733d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
Binary file modified server/dist/OOCSI_server.jar
Binary file not shown.
11 changes: 7 additions & 4 deletions server/src/nl/tue/id/oocsi/server/OOCSIServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class OOCSIServer extends Server {

// constants
public static final String VERSION = "1.19";
public static final String VERSION = "1.20";

// defaults for different services
private int maxClients = 100;
Expand Down Expand Up @@ -420,7 +420,10 @@ public void statusTask() {

// keep-alive ping-pong with socket clients
for (Client client : INSTANCE.getClients()) {
client.ping();
// only ping if last action is at least 5 seconds ago
if (client.lastAction() + 5000 < start) {
client.ping();
}
}

long afterPings = System.currentTimeMillis();
Expand Down Expand Up @@ -464,8 +467,8 @@ public void statusTask() {
// total messages since startup
message.addData("messagesTotal", messageTotal);

// messages per second, averaged over 5 seconds
message.addData("messages", (int) Math.ceil(messageCount / 5.));
// messages per second
message.addData("messages", messageCount);

// channel count
message.addData("channels", INSTANCE.subChannels.size());
Expand Down
10 changes: 9 additions & 1 deletion server/src/nl/tue/id/oocsi/server/model/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected enum ClientType {
OOCSI, PD, JSON, OSC
}

protected long lastAction = System.currentTimeMillis();
private long lastAction = System.currentTimeMillis();

/**
* constructor
Expand Down Expand Up @@ -63,4 +63,12 @@ public Client(String token, ChangeListener presence) {
public long lastAction() {
return lastAction;
}

/**
* set last action to now
*
*/
public void touch() {
lastAction = System.currentTimeMillis();
}
}
12 changes: 6 additions & 6 deletions server/src/nl/tue/id/oocsi/server/model/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public boolean addClient(Client client) {
if (socketClientOld.getIPAddress() != null && socketClientNew.getIPAddress() != null) {
if (socketClientOld.getIPAddress().equals(socketClientNew.getIPAddress())) {
// check mini-timeout (last action of old socket at least 2 seconds ago)
if (socketClientOld.lastAction < System.currentTimeMillis() - 2000) {
if (socketClientOld.lastAction() < System.currentTimeMillis() - 2000) {

// kill old socket
presence.leave(clientName, clientName);
Expand Down Expand Up @@ -175,15 +175,15 @@ public boolean canAcceptClient(Client c) {
*/
protected void closeStaleClients() {
long now = System.currentTimeMillis();
for (Client existingClient : clients.values()) {
if (now - existingClient.lastAction() > 120000 || !existingClient.isConnected()) {
OOCSIServer.log("Client " + existingClient.getName()
for (Client client : clients.values()) {
if (client.lastAction() + 120000 < now || !client.isConnected()) {
OOCSIServer.log("Client " + client.getName()
+ " has not responded for 120 secs and will be disconnected");

// remove from presence tracking if tracking
presence.timeout(existingClient.getName(), existingClient.getName());
presence.timeout(client.getName(), client.getName());

removeClient(existingClient);
removeClient(client);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/nl/tue/id/oocsi/server/services/SocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void run() {
if ((inputLine = input.readLine()) != null) {

// update last action
lastAction = System.currentTimeMillis();
touch();

// do some filtering for SSH clients connecting and other abuse
if (inputLine.length() > 200) {
Expand Down Expand Up @@ -297,7 +297,7 @@ public void run() {
while ((inputLine = input.readLine()) != null) {

// update last action
lastAction = System.currentTimeMillis();
touch();

// clean input from PD clients
if (type == ClientType.PD) {
Expand Down

0 comments on commit b25733d

Please sign in to comment.