Skip to content

Commit 0ce0d00

Browse files
authored
Merge pull request #22 from renvins/feat/reduce-size-influxdb
Extremely reduce size of plugin/mod jars
2 parents d29582a + 74661a8 commit 0ce0d00

File tree

8 files changed

+201
-279
lines changed

8 files changed

+201
-279
lines changed

api/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ repositories {
1515
mavenCentral()
1616
}
1717

18-
dependencies {
19-
api("com.influxdb:influxdb-client-java:7.2.0")
20-
}
21-
2218
publishing {
2319
publications {
2420
create<MavenPublication>("maven") {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package it.renvins.serverpulse.api.data;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Represents a single point in the InfluxDB line protocol format.
8+
* This class is used to construct a line protocol point with measurement, tags, fields, and timestamp.
9+
*/
10+
public class LineProtocolPoint {
11+
12+
private final String measurement;
13+
private final Map<String, String> tags;
14+
private final Map<String, Object> fields;
15+
private long timestamp;
16+
17+
public LineProtocolPoint(String measurement) {
18+
this.measurement = measurement;
19+
this.tags = new HashMap<>();
20+
this.fields = new HashMap<>();
21+
}
22+
23+
public LineProtocolPoint addTag(String key, String value) {
24+
tags.put(key, value);
25+
return this;
26+
}
27+
28+
public LineProtocolPoint addField(String key, Object value) {
29+
fields.put(key, value);
30+
return this;
31+
}
32+
33+
public LineProtocolPoint setTimestamp(long timestamp) {
34+
this.timestamp = timestamp;
35+
return this;
36+
}
37+
38+
public String toLineProtocol() {
39+
StringBuilder sb = new StringBuilder();
40+
sb.append(measurement);
41+
42+
if (!tags.isEmpty()) {
43+
sb.append(",");
44+
tags.forEach((key, value) -> sb.append(key).append("=").append(value).append(","));
45+
sb.setLength(sb.length() - 1); // Remove the last comma
46+
}
47+
48+
sb.append(" ");
49+
50+
if (!fields.isEmpty()) {
51+
fields.forEach((key, value) -> {
52+
sb.append(key).append("=");
53+
if (value instanceof String) {
54+
sb.append("\"").append(value).append("\"");
55+
} else if (value instanceof Integer || value instanceof Long) {
56+
sb.append(value).append("i");
57+
} else {
58+
sb.append(value);
59+
}
60+
sb.append(",");
61+
});
62+
sb.setLength(sb.length() - 1); // Remove the last comma
63+
}
64+
65+
sb.append(" ").append(timestamp);
66+
67+
return sb.toString();
68+
}
69+
}
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package it.renvins.serverpulse.api.service;
22

3-
import com.influxdb.client.InfluxDBClient;
4-
import com.influxdb.client.WriteApi;
3+
import java.util.concurrent.CompletableFuture;
54

65
public interface IDatabaseService extends Service {
76

7+
/**
8+
* Writes a line protocol string to the InfluxDB instance.
9+
* @param lineProtocol The line protocol string to write.
10+
* @return A CompletableFuture that completes with true if the write was successful, false otherwise.
11+
*/
12+
CompletableFuture<Boolean> writeLineProtocol(String lineProtocol);
13+
814
/**
915
* Performs a health check ping to the InfluxDB instance.
1016
* Should only be called internally by connect() or dedicated health checks.
@@ -13,16 +19,15 @@ public interface IDatabaseService extends Service {
1319
boolean ping();
1420

1521
/**
16-
* Returns the last known connection status. Does not perform a live check.
17-
* @return true if the service believes it's connected, false otherwise.
22+
* Sets the isConnected flag to false.
1823
*/
19-
boolean isConnected();
24+
void disconnect();
2025

2126
/**
22-
* Connects to the InfluxDB instance using the configured settings.
23-
* This method should be called before performing any database operations.
27+
* Returns the last known connection status. Does not perform a live check.
28+
* @return true if the service believes it's connected, false otherwise.
2429
*/
25-
void disconnect();
30+
boolean isConnected();
2631

2732
/**
2833
* Disconnects from the InfluxDB instance and cleans up resources.
@@ -31,17 +36,4 @@ public interface IDatabaseService extends Service {
3136
*/
3237
void startRetryTaskIfNeeded();
3338

34-
/**
35-
* Gets the configured InfluxDB client instance.
36-
*
37-
* @return The InfluxDBClient.
38-
*/
39-
InfluxDBClient getClient();
40-
41-
/**
42-
* Gets the InfluxDB Write API instance for sending data points.
43-
*
44-
* @return The WriteApi.
45-
*/
46-
WriteApi getWriteApi();
4739
}

bukkit/build.gradle.kts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,16 @@ dependencies {
2121
implementation(project(":common"))
2222

2323
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
24-
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
2524
}
2625

2726
java {
2827
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
2928
}
3029

31-
val relocatePath = "it.renvins.serverpulse.bukkit.libs"
32-
3330
tasks.withType<ShadowJar> {
3431
archiveBaseName = "serverpulse"
3532
archiveClassifier = "bukkit"
3633
archiveVersion = "${rootProject.version}"
37-
38-
relocate("com.influxdb", "$relocatePath.influxdb")
39-
relocate("okhttp3", "$relocatePath.okhttp3")
40-
relocate("okio", "$relocatePath.okio")
41-
relocate("org.jetbrains", "$relocatePath.jetbrains")
42-
relocate("com.google", "$relocatePath.google")
43-
relocate("io.reactivex", "$relocatePath.reactivex")
44-
relocate("javax.annotation", "$relocatePath.annotation")
45-
relocate("org.apache", "$relocatePath.apache")
46-
relocate("org.intellij", "$relocatePath.intellij")
47-
relocate("org.reactivestreams", "$relocatePath.reactivestreams")
48-
relocate("retrofit2", "$relocatePath.retrofit2")
49-
relocate("kotlin", "$relocatePath.kotlin") // Relocate instead of exclude
50-
relocate("org.jetbrains.kotlin", "$relocatePath.jetbrains.kotlin") // Relocate instead of exclude
51-
52-
// Prevent Paper from giving errors about duplicate files
53-
exclude("META-INF/AL2.0")
54-
exclude("META-INF/LGPL2.1")
55-
exclude("META-INF/LICENSE")
56-
exclude("META-INF/LICENSE.txt")
57-
exclude("META-INF/NOTICE.txt")
5834
}
5935

6036
tasks.withType<ProcessResources> {

0 commit comments

Comments
 (0)