renames
This commit is contained in:
parent
2e1200b911
commit
0b1ac32869
4 changed files with 6 additions and 10 deletions
|
|
@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
/**
|
/**
|
||||||
* Enables multithreaded writing, while keeping CircularByteBuffer simpler (only suitable for single-threaded writing)
|
* 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 Linker linker;
|
||||||
private static SymbolLookup rustlib;
|
private static SymbolLookup rustlib;
|
||||||
private static final LinkedBlockingDeque<byte[]> writeQueue = new LinkedBlockingDeque<>(); // unbounded
|
private static final LinkedBlockingDeque<byte[]> writeQueue = new LinkedBlockingDeque<>(); // unbounded
|
||||||
|
|
@ -20,8 +20,7 @@ public class MPSCBufferWriter implements AutoCloseable {
|
||||||
});
|
});
|
||||||
private final AtomicBoolean active = new AtomicBoolean(false);
|
private final AtomicBoolean active = new AtomicBoolean(false);
|
||||||
|
|
||||||
public MPSCBufferWriter() {
|
public CircularBufferWriter() {
|
||||||
// DatabaseInit.initializeDatabase();
|
|
||||||
startWriteQueueListener();
|
startWriteQueueListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,7 +38,7 @@ public class MPSCBufferWriter implements AutoCloseable {
|
||||||
arena = Arena.ofConfined();
|
arena = Arena.ofConfined();
|
||||||
linker = Linker.nativeLinker();
|
linker = Linker.nativeLinker();
|
||||||
//TODO relative path, or configurable
|
//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();
|
MemorySegment create = rustlib.find("buffer_updated").orElseThrow();
|
||||||
var updateHandle = linker.downcallHandle(create, FunctionDescriptor.ofVoid(
|
var updateHandle = linker.downcallHandle(create, FunctionDescriptor.ofVoid(
|
||||||
ValueLayout.ADDRESS
|
ValueLayout.ADDRESS
|
||||||
|
|
@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@SuppressWarnings("unused") // this code is called from the instrumented code
|
@SuppressWarnings("unused") // this code is called from the instrumented code
|
||||||
public class ExceptionLogger {
|
public class ExceptionLogger {
|
||||||
private final static ObjectMapper objectMapper = new ObjectMapper();
|
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) {
|
public static void log(Throwable throwable) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.shautvast.exceptional;
|
package com.github.shautvast.exceptional;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.lang.foreign.Arena;
|
import java.lang.foreign.Arena;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
@ -14,7 +12,7 @@ class MPSCBufferWriterTest {
|
||||||
var arena = Arena.ofConfined();
|
var arena = Arena.ofConfined();
|
||||||
var ringbufferMemory = arena.allocate(4096);
|
var ringbufferMemory = arena.allocate(4096);
|
||||||
// var buffer = new CircularByteBuffer(ringbufferMemory);
|
// var buffer = new CircularByteBuffer(ringbufferMemory);
|
||||||
MPSCBufferWriter writer = new MPSCBufferWriter();
|
CircularBufferWriter writer = new CircularBufferWriter();
|
||||||
byte[] bytes = "cow".getBytes(UTF_8);
|
byte[] bytes = "cow".getBytes(UTF_8);
|
||||||
writer.put(bytes);
|
writer.put(bytes);
|
||||||
writer.put(bytes);
|
writer.put(bytes);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.github.shautvast.exceptional;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.foreign.MemorySegment;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
// TODO scheduled for demolition
|
// TODO scheduled for demolition
|
||||||
|
|
@ -12,7 +11,7 @@ class RingBufferTest {
|
||||||
@Test
|
@Test
|
||||||
void testWriteAndRead() {
|
void testWriteAndRead() {
|
||||||
// var ringBuffer = new CircularByteBuffer(MemorySegment.ofArray(new byte[16]));
|
// 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)));
|
// writer.startReader(x -> System.out.println("read " + new String(x, StandardCharsets.UTF_8)));
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue