memorysegments scope
This commit is contained in:
parent
09519997dc
commit
fe33243258
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<groupId>it.cavallium</groupId>
|
||||
<artifactId>filequeue</artifactId>
|
||||
<name>file queue project</name>
|
||||
<version>3.1.7</version>
|
||||
<version>3.1.8</version>
|
||||
<packaging>jar</packaging>
|
||||
<description>Light weight, high performance, simple, reliable and persistent queue</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -60,13 +60,15 @@ public class SimpleQueueMemorySegment<T> implements SimpleQueue<T>, Closeable {
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
var memorySegment = arena.allocateArray(ValueLayout.JAVA_BYTE, serialized);
|
||||
try {
|
||||
if (!getQueueSegmentForWrite().offer(memorySegment)) {
|
||||
expandQueueSegmentForWrite().add(memorySegment);
|
||||
try (var arena = Arena.ofConfined()) {
|
||||
var memorySegment = arena.allocateArray(ValueLayout.JAVA_BYTE, serialized);
|
||||
try {
|
||||
if (!getQueueSegmentForWrite().offer(memorySegment)) {
|
||||
expandQueueSegmentForWrite().add(memorySegment);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,18 +120,18 @@ public class SimpleQueueMemorySegment<T> implements SimpleQueue<T>, Closeable {
|
||||
@Override
|
||||
public T remove() {
|
||||
MemorySegment removed;
|
||||
try {
|
||||
removed = getQueueSegmentForRead().poll();
|
||||
try (var arena = Arena.ofConfined()) {
|
||||
removed = getQueueSegmentForRead().poll(arena);
|
||||
if (removed == null) {
|
||||
if (popQueueSegmentForRead()) {
|
||||
removed = getQueueSegmentForRead().poll();
|
||||
removed = getQueueSegmentForRead().poll(arena);
|
||||
}
|
||||
}
|
||||
if (removed == null) throw new NoSuchElementException();
|
||||
return readObject(removed.toArray(ValueLayout.JAVA_BYTE));
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
if (removed == null) throw new NoSuchElementException();
|
||||
return readObject(removed.toArray(ValueLayout.JAVA_BYTE));
|
||||
}
|
||||
|
||||
private T readObject(byte[] byteBuffer) {
|
||||
|
@ -62,7 +62,7 @@ public class SimpleQueueMemorySegmentFixedSize implements Closeable {
|
||||
return true;
|
||||
}
|
||||
|
||||
public MemorySegment poll() {
|
||||
public MemorySegment poll(Arena arena) {
|
||||
if (readPosition >= fixedSize) {
|
||||
return null;
|
||||
}
|
||||
@ -77,8 +77,8 @@ public class SimpleQueueMemorySegmentFixedSize implements Closeable {
|
||||
return segment;
|
||||
}
|
||||
|
||||
public MemorySegment remove() {
|
||||
var polled = poll();
|
||||
public MemorySegment remove(Arena arena) {
|
||||
var polled = poll(arena);
|
||||
if (polled == null) throw new NoSuchElementException();
|
||||
return polled;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user