Implemented Players, CpuUsage, RamUsage Commands. Updated README

This commit is contained in:
Carlos
2019-08-13 19:38:37 +02:00
parent 59fa012a18
commit 7f170f15b6
18 changed files with 266 additions and 66 deletions

View File

@ -18,11 +18,6 @@ public class ConsoleOutput implements JSONOutput{
public String getMessage() {
return message;
}
@Override
public String getRespondsTo() {
return null;
}
@Override
public String toJSON() {

View File

@ -0,0 +1,42 @@
package com.mesacarlos.webconsole.json;
import com.google.gson.JsonObject;
public class CpuUsage implements JSONOutput{
private String message;
private double usage;
public CpuUsage(String message, double usage) {
this.message = message;
this.usage = usage;
}
@Override
public int getStatusCode() {
return 1001;
}
@Override
public String getMessage() {
return message;
}
/**
* Gets system CPU Usage
* @return Global CPU Usage
*/
public double getUsage() {
return usage;
}
@Override
public String toJSON() {
JsonObject object = new JsonObject();
object.addProperty("status", getStatusCode());
object.addProperty("statusDescription", "Cpu Usage");
object.addProperty("usage", getUsage());
object.addProperty("message", getMessage());
return object.toString();
}
}

View File

@ -7,13 +7,6 @@ public interface JSONOutput {
*/
int getStatusCode();
/**
* Returns the command sended by client who created this response.
* In case of a server-generated response (like ConsoleOutput), this will be null
* @return
*/
String getRespondsTo();
/**
* Explanatory message of this response
* @return Explanatory message of this response

View File

@ -18,11 +18,6 @@ public class LoginRequired implements JSONOutput{
public String getMessage() {
return message;
}
@Override
public String getRespondsTo() {
return null;
}
@Override
public String toJSON() {

View File

@ -0,0 +1,45 @@
package com.mesacarlos.webconsole.json;
import com.google.gson.JsonObject;
public class Players implements JSONOutput{
private String message;
private int connectedPlayers;
private int maxPlayers;
public Players(String message, int connectedPlayers, int maxPlayers) {
this.message = message;
this.connectedPlayers = connectedPlayers;
this.maxPlayers = maxPlayers;
}
@Override
public int getStatusCode() {
return 1000;
}
@Override
public String getMessage() {
return message;
}
public int getConnectedPlayers() {
return connectedPlayers;
}
public int getMaxPlayers() {
return maxPlayers;
}
@Override
public String toJSON() {
JsonObject object = new JsonObject();
object.addProperty("status", getStatusCode());
object.addProperty("statusDescription", "Players");
object.addProperty("connectedPlayers", getConnectedPlayers());
object.addProperty("maxPlayers", getMaxPlayers());
object.addProperty("message", getMessage());
return object.toString();
}
}

View File

@ -25,8 +25,11 @@ public class Processed implements JSONOutput{
return message;
}
@Override
public String getRespondsTo() {
/**
* The command that originated this response
* @return WebSockets full command and parameters
*/
private String getRespondsTo() {
return respondsTo;
}

View File

@ -0,0 +1,64 @@
package com.mesacarlos.webconsole.json;
import com.google.gson.JsonObject;
public class RamUsage implements JSONOutput {
private String message;
private int free;
private int used;
private int max;
public RamUsage(String message, int free, int used, int max) {
this.message = message;
this.free = free;
this.used = used;
this.max = max;
}
@Override
public int getStatusCode() {
return 1002;
}
@Override
public String getMessage() {
return message;
}
/**
* Free amount of RAM, in MB
* @return
*/
public int getFree() {
return free;
}
/**
* Used amount of RAM, in MB
* @return
*/
public int getUsed() {
return used;
}
/**
* Max amount of RAM, in MB
* @return
*/
public int getMax() {
return max;
}
@Override
public String toJSON() {
JsonObject object = new JsonObject();
object.addProperty("status", getStatusCode());
object.addProperty("statusDescription", "RAM Usage");
object.addProperty("free", getFree());
object.addProperty("total", getUsed());
object.addProperty("max", getMax());
object.addProperty("message", getMessage());
return object.toString();
}
}

View File

@ -2,11 +2,11 @@ package com.mesacarlos.webconsole.json;
import com.google.gson.JsonObject;
public class UnknownWSCmd implements JSONOutput{
public class UnknownCommand implements JSONOutput{
private String message;
private String respondsTo;
public UnknownWSCmd(String message, String respondsTo) {
public UnknownCommand(String message, String respondsTo) {
this.message = message;
this.respondsTo = respondsTo;
}
@ -21,7 +21,10 @@ public class UnknownWSCmd implements JSONOutput{
return message;
}
@Override
/**
* The command that originated this response
* @return WebSockets full command and parameters
*/
public String getRespondsTo() {
return respondsTo;
}