diff --git a/lib/src/main/java/com/github/shautvast/exceptional/MPSCBufferWriter.java b/lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java similarity index 92% rename from lib/src/main/java/com/github/shautvast/exceptional/MPSCBufferWriter.java rename to lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java index 48768b5..937b5af 100644 --- a/lib/src/main/java/com/github/shautvast/exceptional/MPSCBufferWriter.java +++ b/lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java @@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * Enables multithreaded writing, while keeping CircularByteBuffer simpler (only suitable for single-threaded writing) */ -public class MPSCBufferWriter implements AutoCloseable { +public class CircularBufferWriter implements AutoCloseable { private static Linker linker; private static SymbolLookup rustlib; private static final LinkedBlockingDeque writeQueue = new LinkedBlockingDeque<>(); // unbounded @@ -20,8 +20,7 @@ public class MPSCBufferWriter implements AutoCloseable { }); private final AtomicBoolean active = new AtomicBoolean(false); - public MPSCBufferWriter() { -// DatabaseInit.initializeDatabase(); + public CircularBufferWriter() { startWriteQueueListener(); } @@ -39,7 +38,7 @@ public class MPSCBufferWriter implements AutoCloseable { arena = Arena.ofConfined(); linker = Linker.nativeLinker(); //TODO relative path, or configurable - rustlib = SymbolLookup.libraryLookup("/Users/Shautvast/dev/exceptional/rustlib/target/debug/librustlib.dylib", arena); + rustlib = SymbolLookup.libraryLookup(System.getProperty("agentlib"), arena); MemorySegment create = rustlib.find("buffer_updated").orElseThrow(); var updateHandle = linker.downcallHandle(create, FunctionDescriptor.ofVoid( ValueLayout.ADDRESS diff --git a/lib/src/main/java/com/github/shautvast/exceptional/ExceptionLogger.java b/lib/src/main/java/com/github/shautvast/exceptional/ExceptionLogger.java index 3b338cb..a4263a3 100644 --- a/lib/src/main/java/com/github/shautvast/exceptional/ExceptionLogger.java +++ b/lib/src/main/java/com/github/shautvast/exceptional/ExceptionLogger.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @SuppressWarnings("unused") // this code is called from the instrumented code public class ExceptionLogger { private final static ObjectMapper objectMapper = new ObjectMapper(); - private final static MPSCBufferWriter bufferWriter = new MPSCBufferWriter(); + private final static CircularBufferWriter bufferWriter = new CircularBufferWriter(); public static void log(Throwable throwable) { try { diff --git a/lib/src/test/java/com/github/shautvast/exceptional/MPSCBufferWriterTest.java b/lib/src/test/java/com/github/shautvast/exceptional/MPSCBufferWriterTest.java index bcfc678..4869166 100644 --- a/lib/src/test/java/com/github/shautvast/exceptional/MPSCBufferWriterTest.java +++ b/lib/src/test/java/com/github/shautvast/exceptional/MPSCBufferWriterTest.java @@ -1,7 +1,5 @@ package com.github.shautvast.exceptional; -import org.junit.jupiter.api.Test; - import java.lang.foreign.Arena; import static java.nio.charset.StandardCharsets.UTF_8; @@ -14,7 +12,7 @@ class MPSCBufferWriterTest { var arena = Arena.ofConfined(); var ringbufferMemory = arena.allocate(4096); // var buffer = new CircularByteBuffer(ringbufferMemory); - MPSCBufferWriter writer = new MPSCBufferWriter(); + CircularBufferWriter writer = new CircularBufferWriter(); byte[] bytes = "cow".getBytes(UTF_8); writer.put(bytes); writer.put(bytes); diff --git a/lib/src/test/java/com/github/shautvast/exceptional/RingBufferTest.java b/lib/src/test/java/com/github/shautvast/exceptional/RingBufferTest.java index fcc9f3a..8ee63b5 100644 --- a/lib/src/test/java/com/github/shautvast/exceptional/RingBufferTest.java +++ b/lib/src/test/java/com/github/shautvast/exceptional/RingBufferTest.java @@ -3,7 +3,6 @@ package com.github.shautvast.exceptional; import org.junit.jupiter.api.Test; -import java.lang.foreign.MemorySegment; import java.nio.charset.StandardCharsets; // TODO scheduled for demolition @@ -12,7 +11,7 @@ class RingBufferTest { @Test void testWriteAndRead() { // var ringBuffer = new CircularByteBuffer(MemorySegment.ofArray(new byte[16])); - var writer = new MPSCBufferWriter(); + var writer = new CircularBufferWriter(); // writer.startReader(x -> System.out.println("read " + new String(x, StandardCharsets.UTF_8))); for (int i = 0; i < 10; i++) {