diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..e9553e9
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace (conflicted copy 2023-11-16 204932).xml b/.idea/workspace (conflicted copy 2023-11-16 204932).xml
new file mode 100644
index 0000000..a916673
--- /dev/null
+++ b/.idea/workspace (conflicted copy 2023-11-16 204932).xml
@@ -0,0 +1,159 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 1
+}
+
+
+
+
+
+
+ {
+ "keyToString": {
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "WebServerToolWindowFactoryState": "false",
+ "git-widget-placeholder": "main",
+ "last_opened_file_path": "/home/brett/Documents/Brock/CS 3P95/Assignments/Assignment 2 Java/libs",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "project.structure.last.edited": "Modules",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2",
+ "settings.editor.selected.configurable": "reference.settings.project.maven.repository.indices",
+ "vue.rearranger.settings.migration": "true"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1699642690668
+
+
+ 1699642690668
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d97ee55..412df04 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,5 +100,10 @@
lz4-java
1.8.0
+
+ io.opentelemetry
+ opentelemetry-sdk-trace
+ 1.32.0
+
\ No newline at end of file
diff --git a/src/main/java/server/ChunkedCompressedChecksumFileReader.java b/src/main/java/server/ChunkedCompressedChecksumFileReader.java
index 8593a7c..707536f 100644
--- a/src/main/java/server/ChunkedCompressedChecksumFileReader.java
+++ b/src/main/java/server/ChunkedCompressedChecksumFileReader.java
@@ -28,7 +28,7 @@ public class ChunkedCompressedChecksumFileReader {
}
public FileHeader readChunk(Tracer trace, Span sp) throws IOException {
- Span gf = trace.spanBuilder("Chunk Read").setParent(Context.current().with(sp)).startSpan();
+ Span gf = trace.spanBuilder("Chunk Read").startSpan();
FileHeader header = readHeader();
try (Scope scope = gf.makeCurrent()) {
if (header.getUncompressed() == 0)
diff --git a/src/main/java/server/Connection.java b/src/main/java/server/Connection.java
index 69f0b8e..9ece3cc 100644
--- a/src/main/java/server/Connection.java
+++ b/src/main/java/server/Connection.java
@@ -1,5 +1,6 @@
package server;
+import client.Client;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.Tracer;
@@ -18,10 +19,10 @@ public class Connection implements Runnable {
private final Server server;
private DataOutputStream out;
private DataInputStream in;
- private Tracer trace;
- private Span fileSend;
+ private final Tracer trace;
+ private final Span fileSend;
- public Connection(Server server, Tracer trace, Span parent, Socket clientSocket) {
+ public Connection(Server server, Tracer trace, Socket clientSocket) {
this.server = server;
this.clientSocket = clientSocket;
this.trace = trace;
@@ -31,12 +32,12 @@ public class Connection implements Runnable {
} catch (Exception e) {
ExceptionLogger.log(e);
}
- parent.addEvent("Connection Established");
- SpanBuilder sb = trace.spanBuilder("New Connection");
+ SpanBuilder sb = trace.spanBuilder("New Client Connection");
sb.setAttribute("INetAddress", clientSocket.getInetAddress().toString());
sb.setAttribute("Port", clientSocket.getPort());
sb.setAttribute("LocalPort", clientSocket.getLocalPort());
fileSend = sb.startSpan();
+ fileSend.addEvent("Connection Established");
}
@Override
@@ -66,6 +67,7 @@ public class Connection implements Runnable {
}
}
} catch (IOException e) {
+ fileSend.recordException(e);
throw new RuntimeException(e);
}
}
@@ -76,9 +78,16 @@ public class Connection implements Runnable {
out.close();
in.close();
clientSocket.close();
- } catch (Exception ignored) {}
+ } catch (Exception e) {
+ ExceptionLogger.log(e);
+ }
+ System.out.println("Client Disconnected");
Server.running = false;
- Server.close();
+// try {
+// // evil hack
+// new Client("localhost", Server.SERVER_PORT).close();
+// } catch (IOException ignored) {
+// }
}
}
diff --git a/src/main/java/server/FileHeader.java b/src/main/java/server/FileHeader.java
index 6119808..dfcd523 100644
--- a/src/main/java/server/FileHeader.java
+++ b/src/main/java/server/FileHeader.java
@@ -11,9 +11,10 @@ public class FileHeader {
private int compressed;
private long hash;
- public FileHeader() {}
+ public FileHeader() {
+ }
- public FileHeader read(DataInputStream reader) throws IOException{
+ public FileHeader read(DataInputStream reader) throws IOException {
uncompressed = reader.readInt();
if (uncompressed == 0)
return this;
diff --git a/src/main/java/server/Server.java b/src/main/java/server/Server.java
index 99ed41e..4a04e58 100644
--- a/src/main/java/server/Server.java
+++ b/src/main/java/server/Server.java
@@ -11,6 +11,7 @@ import shared.OTelUtils;
import java.io.IOException;
import java.net.ServerSocket;
+import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -27,39 +28,32 @@ public class Server {
public Server() {
Tracer main = ot.getTracer("Main Server", "0.69");
- Span sbs = main.spanBuilder("Start Server").setAttribute("Server Port", SERVER_PORT).startSpan();
- try (Scope scope = sbs.makeCurrent()) {
+ try {
System.out.println("Starting server");
- sbs.addEvent("Server Start", System.nanoTime(), TimeUnit.NANOSECONDS);
ServerSocket serverSocket = new ServerSocket(SERVER_PORT);
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- System.out.println("Closing Server");
- running = false;
- sbs.end();
- executor.shutdown();
- try {
- serverSocket.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
System.out.println("Server Started");
while (running)
- executor.execute(new Connection(this, main, sbs, serverSocket.accept()));
+ executor.execute(new Connection(this, main, serverSocket.accept()));
serverSocket.close();
} catch (IOException e) {
- sbs.recordException(e);
ExceptionLogger.log(e);
- } finally {
- sbs.end();
}
System.out.println("Closing thread pool");
executor.shutdown();
+ try {
+ if (!executor.awaitTermination(1, TimeUnit.SECONDS)){
+ List runs = executor.shutdownNow();
+ System.out.println("Hello runs " + runs.size());
+ if (!executor.awaitTermination(1, TimeUnit.SECONDS))
+ System.out.println("Unable to terminate");
+ }
+ } catch (InterruptedException e) {
+ executor.shutdownNow();
+ Thread.currentThread().interrupt();
+ ExceptionLogger.log(e);
+ }
System.out.println("Server exited!");
}
@@ -74,7 +68,8 @@ public class Server {
}
public static void close(){
- srv.notifyAll();
+ if (srv != null)
+ srv.notifyAll();
}
}
\ No newline at end of file
diff --git a/src/main/java/shared/FileUtil.java b/src/main/java/shared/FileUtil.java
index 3d7d9b7..9f8aaeb 100644
--- a/src/main/java/shared/FileUtil.java
+++ b/src/main/java/shared/FileUtil.java
@@ -3,6 +3,7 @@ package shared;
import client.ChunkedCompressedChecksumFileWriter;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.context.Scope;
import net.jpountz.lz4.LZ4Compressor;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;
@@ -70,7 +71,7 @@ public class FileUtil {
ChunkedCompressedChecksumFileReader reader = new ChunkedCompressedChecksumFileReader(dataIn, path, FileUtil.SEED);
// ugh I want while(reader.readChunk().getUncompressed()); but it makes warnings!!!
- while(true) {
+ while (true) {
if (reader.readChunk(trace, sp).getUncompressed() == 0) {
sp.addEvent("Chunk Read");
break;
diff --git a/src/main/java/shared/OTelUtils.java b/src/main/java/shared/OTelUtils.java
index 256949e..f4af919 100644
--- a/src/main/java/shared/OTelUtils.java
+++ b/src/main/java/shared/OTelUtils.java
@@ -16,6 +16,7 @@ import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
+import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.semconv.ResourceAttributes;
@@ -30,20 +31,10 @@ public class OTelUtils {
.setResource(resource)
.build();
- SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
- .registerMetricReader(PeriodicMetricReader.builder(LoggingMetricExporter.create()).build())
- .setResource(resource)
- .build();
-
- SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder()
- .addLogRecordProcessor(BatchLogRecordProcessor.builder(SystemOutLogRecordExporter.create()).build())
- .setResource(resource)
- .build();
-
return OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
- .setMeterProvider(sdkMeterProvider)
- .setLoggerProvider(sdkLoggerProvider)
+ .setMeterProvider(createLoggingMeter(resource))
+ .setLoggerProvider(createLoggerProvider(resource))
.setPropagators(ContextPropagators.create(TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance())))
.buildAndRegisterGlobal();
}
@@ -53,29 +44,39 @@ public class OTelUtils {
SpanExporter otlpExporter = OtlpGrpcSpanExporter.builder()
.setEndpoint("http://sc.on.underlying.skynet.tpgc.me:4317")
+ .setCompression("gzip")
+ .build();
+
+ BatchSpanProcessor batchSpanProcessor = BatchSpanProcessor.builder(otlpExporter)
+ .setMaxQueueSize(2048)
+ .setMaxExportBatchSize(512) // Example max export batch size
.build();
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
- .addSpanProcessor(SimpleSpanProcessor.create(otlpExporter))
- .setResource(resource)
- .build();
-
- SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
- .registerMetricReader(PeriodicMetricReader.builder(LoggingMetricExporter.create()).build())
- .setResource(resource)
- .build();
-
- SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder()
- .addLogRecordProcessor(BatchLogRecordProcessor.builder(SystemOutLogRecordExporter.create()).build())
+ .addSpanProcessor(batchSpanProcessor)
.setResource(resource)
.build();
return OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
- .setMeterProvider(sdkMeterProvider)
- .setLoggerProvider(sdkLoggerProvider)
+ .setMeterProvider(createLoggingMeter(resource))
+ .setLoggerProvider(createLoggerProvider(resource))
.setPropagators(ContextPropagators.create(TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance())))
.buildAndRegisterGlobal();
}
+ private static SdkMeterProvider createLoggingMeter(Resource resource){
+ return SdkMeterProvider.builder()
+ .registerMetricReader(PeriodicMetricReader.builder(LoggingMetricExporter.create()).build())
+ .setResource(resource)
+ .build();
+ }
+
+ private static SdkLoggerProvider createLoggerProvider(Resource resource){
+ return SdkLoggerProvider.builder()
+ .addLogRecordProcessor(BatchLogRecordProcessor.builder(SystemOutLogRecordExporter.create()).build())
+ .setResource(resource)
+ .build();
+ }
+
}
diff --git a/target/classes/server/ChunkedCompressedChecksumFileReader.class b/target/classes/server/ChunkedCompressedChecksumFileReader.class
index 594e896..0336e4e 100644
Binary files a/target/classes/server/ChunkedCompressedChecksumFileReader.class and b/target/classes/server/ChunkedCompressedChecksumFileReader.class differ
diff --git a/target/classes/server/Connection.class b/target/classes/server/Connection.class
index 5d68511..09208c4 100644
Binary files a/target/classes/server/Connection.class and b/target/classes/server/Connection.class differ
diff --git a/target/classes/server/FileHeader.class b/target/classes/server/FileHeader.class
index cb31c7f..1365438 100644
Binary files a/target/classes/server/FileHeader.class and b/target/classes/server/FileHeader.class differ
diff --git a/target/classes/server/Server$1.class b/target/classes/server/Server$1.class
deleted file mode 100644
index 944a7d6..0000000
Binary files a/target/classes/server/Server$1.class and /dev/null differ
diff --git a/target/classes/server/Server.class b/target/classes/server/Server.class
index 996c1a4..0ad00d6 100644
Binary files a/target/classes/server/Server.class and b/target/classes/server/Server.class differ
diff --git a/target/classes/shared/FileUtil$COMMAND.class b/target/classes/shared/FileUtil$COMMAND.class
index b2c652d..c128413 100644
Binary files a/target/classes/shared/FileUtil$COMMAND.class and b/target/classes/shared/FileUtil$COMMAND.class differ
diff --git a/target/classes/shared/FileUtil$InvalidUsageException.class b/target/classes/shared/FileUtil$InvalidUsageException.class
index 286e2ee..8c157cd 100644
Binary files a/target/classes/shared/FileUtil$InvalidUsageException.class and b/target/classes/shared/FileUtil$InvalidUsageException.class differ
diff --git a/target/classes/shared/FileUtil.class b/target/classes/shared/FileUtil.class
index c220a9a..bcaf31f 100644
Binary files a/target/classes/shared/FileUtil.class and b/target/classes/shared/FileUtil.class differ
diff --git a/target/classes/shared/OTelUtils.class b/target/classes/shared/OTelUtils.class
index 91742e6..b9b2bab 100644
Binary files a/target/classes/shared/OTelUtils.class and b/target/classes/shared/OTelUtils.class differ
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
index de0ae23..c49df92 100644
--- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -1,13 +1,12 @@
shared/ExceptionLogger.class
-server/Server$1.class
+shared/FileUtil$InvalidUsageException.class
shared/FileUtil.class
+shared/OTelUtils.class
+client/Client.class
server/Server.class
server/Connection.class
+server/FileHeader.class
+shared/FileUtil$COMMAND.class
shared/ArrayData.class
server/ChunkedCompressedChecksumFileReader.class
client/ChunkedCompressedChecksumFileWriter.class
-shared/FileUtil$InvalidUsageException.class
-shared/OTelUtils.class
-client/Client.class
-server/FileHeader.class
-shared/FileUtil$COMMAND.class