-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Realtime WebSockets Event Server #261
base: develop
Are you sure you want to change the base?
Realtime WebSockets Event Server #261
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! This could be very useful. I've included a few comments and if you have questions you can dm me ;)
loadProperty("RTWSEventIP", "localhost"); //As a default, localhost is used for security. | ||
loadProperty("RTWSEventPort", "8081"); | ||
loadProperty("RTWSEventMaxConnections", "10000"); | ||
loadProperty("RTWSMaxConnectionsPerUniqueIP", "10"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
*/ | ||
public void init(){ | ||
Logger.info("Initializing WebSocketEventServer"); | ||
JettyServer.getInstance(); //initialize the Jetty server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually recommend modifying the design of JettyServer and Clients classes so that they are fields of the WebsocketEventServer class instead of each one being a singleton. Clients.class can also be renamed to ClientsHandler or smth, so there would be getClientsHandler() and getJettyServer() methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/** | ||
* The WebSocketBroadcast class is responsible for broadcasting messages to all connected clients. | ||
*/ | ||
public class WebSocketBroadcast { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I would move this stuff to WebSocketEventServer :kek
This is just adding another singleton class and the WebSocketEventServer would not be flexible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
GlobalQuakeServer/src/main/java/gqserver/websocketserver/ServerEndpoint.java
Outdated
Show resolved
Hide resolved
GlobalQuakeServer/src/main/java/gqserver/websocketserver/JettyServer.java
Outdated
Show resolved
Hide resolved
try{ | ||
count = uniqueIPConnectionCounts.get(ip); | ||
} | ||
catch(Exception e) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
umm what? maybe you wanted to use HashMap instead of Hashtable.. there is a function called getOrDefault(...)
private int incrementConnectionCount(String address) { | ||
int count = 0; | ||
|
||
synchronized (uniqueIPConnectionCounts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the synchronizations here seem a bit sketchy to me 💀 I would be quite worried about deadlocks or race conditions from my experience. Perhaps you can use ConcurrentHashMap to do the job?
...lQuakeServer/src/main/java/gqserver/websocketserver/handler_chain/DropConnectionHandler.java
Outdated
Show resolved
Hide resolved
May I suggest adding additional data to the ArchivedQuake part of things in order to allow for the transmission of additional important information such as quality and intensity levels? I think a lot of this information is crucial to the interpretation of websocket data. Here's an example of how a few additional paramaters (quality and intensity levels) could be added but feel free to modify and add more properties as needed: // ArchivedQuake.java
public JSONObject getGeoJSON() {
JSONObject earthquakeJSON = new JSONObject();
JSONObject estimatedIntensityJSON = new JSONObject();
// more properties here...
properties.put("quality", getQualityClass().toString());
calculatePGA();
estimatedIntensityJSON.put("mmi",
IntensityScales.MMI.getLevel(getMaxPGA()) != null ? IntensityScales.MMI.getLevel(getMaxPGA()).toString()
: null);
estimatedIntensityJSON.put("shindo",
IntensityScales.SHINDO.getLevel(getMaxPGA()) != null
? IntensityScales.SHINDO.getLevel(getMaxPGA()).toString()
: null);
properties.put("estimated_intensity", estimatedIntensityJSON);
// more properties here...
return earthquakeJSON;
} |
@dzlandis a plan to overhaul the fdsntext, geojson, and xml methods in a different PR as they are also used in the fdsnws-event module |
Dev merge from upstream
Keep feature branch up to date with upstream dev branch
This is a http server with only websocket support.
All other connections and path requests will be dropped.
Clients may connect over http and will be sent:
-Event Creations
-Event Updates
-Event Deletions
5 new settings have been added..
-enableRTWSEventServer;
-RTWSEventIP;
-RTWSEventPort;
-RTWSEventMaxConnections;
-RTWSMaxConnectionsPerUniqueIP;
RTWSEventMaxConnections is the total number of connections allowed to the server.
RTWSMaxConnectionsPerUniqueIP is the total number of connections allowed for one unique IP address,
for example, 1.1.1.1 | 8.8.8.8 are both unique IPs that can only have a certain number of connections each.
By default it is disabled.
Its init and start are a part of the main servers load sequence (when enabled).
Its path is /realtime_events/v1
This first version is meant to mimic the system available from EMSC at https://www.seismicportal.eu/realtime.html
Later i would like to improve it, adding many more features and options then the EMSC service.
Soon also i will provide a sample html page to connect to the server and display the events.