Skip to content
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

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

DecryptingElectrons
Copy link
Contributor

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.

Copy link
Owner

@xspanger3770 xspanger3770 left a 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");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

GlobalQuakeServer/src/main/java/gqserver/main/Main.java Outdated Show resolved Hide resolved
*/
public void init(){
Logger.info("Initializing WebSocketEventServer");
JettyServer.getInstance(); //initialize the Jetty server
Copy link
Owner

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.

Copy link
Contributor Author

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 {
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try{
count = uniqueIPConnectionCounts.get(ip);
}
catch(Exception e) {}
Copy link
Owner

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) {
Copy link
Owner

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?

@dzlandis
Copy link

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;
}

@DecryptingElectrons
Copy link
Contributor Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants