Skip to content

Commit

Permalink
nevermind, reformat all files
Browse files Browse the repository at this point in the history
  • Loading branch information
xspanger3770 committed Apr 20, 2024
1 parent 21d4b0f commit 50bf6ea
Show file tree
Hide file tree
Showing 185 changed files with 4,516 additions and 4,470 deletions.
3 changes: 2 additions & 1 deletion GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public interface Packet extends Serializable {

default void onServerReceive(ServerClient serverClient) {}
default void onServerReceive(ServerClient serverClient) {
}

}
3 changes: 2 additions & 1 deletion GlobalQuakeAPI/src/main/java/gqserver/api/ServerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ServerClient {
limitRules.put(ArchivedQuakesRequestPacket.class, 4);
limitRules.put(DataRequestPacket.class, 60);
}

public ServerClient(Socket socket) throws IOException {
this.socket = socket;
this.inputStream = new ObjectInputStream(socket.getInputStream());
Expand Down Expand Up @@ -130,7 +131,7 @@ public ServerClientConfig getClientConfig() {
}

public synchronized void queuePacket(Packet packet) {
if(destroyed){
if (destroyed) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serial;
import java.io.Serializable;

public record ArchivedEventData(float lat, float lon, float maxRatio, long pWave) implements Serializable {
@Serial
private static final long serialVersionUID = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.io.Serializable;
import java.util.UUID;

public record ArchivedQuakeData(UUID uuid, float lat, float lon, float depth, float magnitude, long origin, byte qualityID, long finalUpdateMillis) implements Serializable {
public record ArchivedQuakeData(UUID uuid, float lat, float lon, float depth, float magnitude, long origin,
byte qualityID, long finalUpdateMillis) implements Serializable {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.io.Serializable;
import java.util.UUID;

public record HypocenterData(UUID uuid, int revisionID, float lat, float lon, float depth, long origin, float magnitude, long lastUpdate, String region) implements Serializable {
public record HypocenterData(UUID uuid, int revisionID, float lat, float lon, float depth, long origin, float magnitude,
long lastUpdate, String region) implements Serializable {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.io.Serial;
import java.io.Serializable;

public record HypocenterQualityData(float errOrigin, float errDepth, float errNS, float errEW, int stations, float pct) implements Serializable {
public record HypocenterQualityData(float errOrigin, float errDepth, float errNS, float errEW, int stations,
float pct) implements Serializable {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.io.Serializable;
import java.util.List;

public record LocationConfidenceIntervalData(List<PolygonConfidenceIntervalData> polygonConfidenceIntervalDataList) implements Serializable {
public record LocationConfidenceIntervalData(
List<PolygonConfidenceIntervalData> polygonConfidenceIntervalDataList) implements Serializable {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.io.Serial;
import java.io.Serializable;

public record StationInfoData(int index, float lat, float lon, String network, String station, String channel, String location,
long time, float maxIntensity, boolean eventMode, InputType sensorType) implements Serializable {
public record StationInfoData(int index, float lat, float lon, String network, String station, String channel,
String location,
long time, float maxIntensity, boolean eventMode,
InputType sensorType) implements Serializable {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import java.io.Serial;
import java.util.List;

public record ArchivedQuakePacket(ArchivedQuakeData archivedQuakeData, List<ArchivedEventData> archivedEventDataList) implements Packet {
public record ArchivedQuakePacket(ArchivedQuakeData archivedQuakeData,
List<ArchivedEventData> archivedEventDataList) implements Packet {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import java.io.Serial;

public record HypocenterDataPacket(HypocenterData data, AdvancedHypocenterData advancedHypocenterData, ClusterData clusterData) implements Packet {
public record HypocenterDataPacket(HypocenterData data, AdvancedHypocenterData advancedHypocenterData,
ClusterData clusterData) implements Packet {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import java.util.List;
import java.util.UUID;

public record StationsIntensityPacket(UUID stationsIndexing, long time, List<StationIntensityData> intensities) implements Packet {
public record StationsIntensityPacket(UUID stationsIndexing, long time,
List<StationIntensityData> intensities) implements Packet {
@Serial
private static final long serialVersionUID = 0L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AlertManager {
public AlertManager() {
this.warnings = new HashMap<>();

GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener(){
GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener() {
@Override
public void onQuakeCreate(QuakeCreateEvent event) {
tick();
Expand All @@ -48,7 +48,7 @@ public synchronized void tick() {
Warning warning = kv.getValue();

long age = GlobalQuake.instance.currentTimeMillis() - warning.createdAt;
if(age > 1000 * 60 * STORE_TIME_MINUTES){
if (age > 1000 * 60 * STORE_TIME_MINUTES) {
iterator.remove();
continue;
}
Expand All @@ -61,13 +61,13 @@ public synchronized void tick() {
}

private void conditionsSatisfied(Warnable warnable, Warning warning) {
if(GlobalQuakeLocal.instance != null){
if (GlobalQuakeLocal.instance != null) {
GlobalQuakeLocal.instance.getLocalEventHandler().fireEvent(new AlertIssuedEvent(warnable, warning));
}
}

private boolean meetsConditions(Warnable warnable) {
if(warnable instanceof Earthquake){
if (warnable instanceof Earthquake) {
return meetsConditions((Earthquake) warnable, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,32 @@ public void connect(String ip, int port) throws IOException, ClassNotFoundExcept
sendPacket(new StationsRequestPacket());
GlobalQuakeClient.instance.getLocalEventHandler().fireEvent(new SocketReconnectEvent());
status = ClientSocketStatus.CONNECTED;
} catch(ConnectException | SocketTimeoutException ce){
} catch (ConnectException | SocketTimeoutException ce) {
Logger.trace(ce);
status = ClientSocketStatus.DISCONNECTED;
throw ce;
} catch(Exception e) {
} catch (Exception e) {
status = ClientSocketStatus.DISCONNECTED;
Logger.error(e);
throw e;
}
}

public void runReconnectService(){
public void runReconnectService() {
reconnectService = Executors.newSingleThreadScheduledExecutor();
reconnectService.scheduleAtFixedRate(this::checkReconnect, 0, 10, TimeUnit.SECONDS);
}

public void destroy(){
if(reconnectService == null){
public void destroy() {
if (reconnectService == null) {
return;
}

GlobalQuake.instance.stopService(reconnectService);
}

private void checkReconnect() {
if(!socket.isConnected() || socket.isClosed()){
if (!socket.isConnected() || socket.isClosed()) {
try {
connect(ip, port);
} catch (Exception e) {
Expand All @@ -105,7 +105,7 @@ private void checkReconnect() {
private void sendQuakeRequest() {
try {
sendPacket(new EarthquakesRequestPacket());
} catch(SocketTimeoutException | SocketException e){
} catch (SocketTimeoutException | SocketException e) {
Logger.trace(e);
onClose();
} catch (IOException e) {
Expand All @@ -117,7 +117,7 @@ private void sendQuakeRequest() {
private void sendHeartbeat() {
try {
sendPacket(new HeartbeatPacket());
} catch(SocketTimeoutException | SocketException e){
} catch (SocketTimeoutException | SocketException e) {
Logger.trace(e);
onClose();
} catch (IOException e) {
Expand All @@ -128,10 +128,10 @@ private void sendHeartbeat() {

private void onClose() {
status = ClientSocketStatus.DISCONNECTED;
if(socket != null){
if (socket != null) {
try {
socket.close();
} catch(SocketTimeoutException | SocketException e){
} catch (SocketTimeoutException | SocketException e) {
Logger.trace(e);
onClose();
} catch (IOException e) {
Expand All @@ -145,7 +145,7 @@ private void onClose() {
GlobalQuake.instance.stopService(quakeCheckService);
}

public boolean isConnected(){
public boolean isConnected() {
return socket.isConnected() && !socket.isClosed();
}

Expand All @@ -156,17 +156,17 @@ private void runReader() {
Logger.trace("Received packet: %s".formatted(packet.toString()));
((GlobalQuakeClient) GlobalQuakeClient.instance).processPacket(this, packet);
}
} catch(SocketTimeoutException | SocketException se){
} catch (SocketTimeoutException | SocketException se) {
Logger.trace(se);
}catch (Exception e){
} catch (Exception e) {
Logger.error(e);
} finally {
onClose();
}
}

public synchronized void sendPacket(Packet packet) throws IOException {
if(outputStream == null){
if (outputStream == null) {
return;
}

Expand All @@ -178,8 +178,8 @@ public synchronized void sendPacket(Packet packet) throws IOException {
private void handshake() throws IOException, ClassNotFoundException {
sendPacket(new HandshakePacket(GQApi.COMPATIBILITY_VERSION, new ServerClientConfig(true, true)));
Packet packet = (Packet) inputStream.readObject();
if(!(packet instanceof HandshakeSuccessfulPacket)) {
if(packet instanceof TerminationPacket terminationPacket){
if (!(packet instanceof HandshakeSuccessfulPacket)) {
if (packet instanceof TerminationPacket terminationPacket) {
throw new RuntimeApplicationException(terminationPacket.cause());
} else {
throw new RuntimeApplicationException("Unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public ClusterAnalysisClient() {

private void checkClusters() {
List<Cluster> toRemove = new ArrayList<>();
for(Cluster cluster : clusters){
if(GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() > 30 * 60 * 1000){
for (Cluster cluster : clusters) {
if (GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() > 30 * 60 * 1000) {
toRemove.add(cluster);
}
}
Expand All @@ -46,14 +46,14 @@ public List<Cluster> getClusters() {
}

public void processPacket(ClientSocket ignoredSocket, Packet packet) {
if(packet instanceof ClusterPacket clusterPacket){
if (packet instanceof ClusterPacket clusterPacket) {
getCluster(clusterPacket.clusterData());
}
}

public Cluster getCluster(ClusterData clusterData) {
Cluster existing = findCluster(clusterData.uuid());
if(existing != null) {
if (existing != null) {
existing.updateLevel(clusterData.level());
existing.updateRoot(clusterData.rootLat(), clusterData.rootLon());
} else {
Expand Down
Loading

0 comments on commit 50bf6ea

Please sign in to comment.