Update
This commit is contained in:
parent
dbcdbaafeb
commit
3a48d63b11
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<groupId>it.cavallium</groupId>
|
<groupId>it.cavallium</groupId>
|
||||||
<artifactId>filequeue</artifactId>
|
<artifactId>filequeue</artifactId>
|
||||||
<name>file queue project</name>
|
<name>file queue project</name>
|
||||||
<version>3.0.0</version>
|
<version>3.0.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Light weight, high performance, simple, reliable and persistent queue</description>
|
<description>Light weight, high performance, simple, reliable and persistent queue</description>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -2,6 +2,7 @@ package it.cavallium.filequeue;
|
|||||||
|
|
||||||
import com.squareup.tape2.QueueFile;
|
import com.squareup.tape2.QueueFile;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public final class DiskQueueToConsumer<T> implements IQueueToConsumer<T> {
|
public final class DiskQueueToConsumer<T> implements IQueueToConsumer<T> {
|
||||||
@ -10,10 +11,24 @@ public final class DiskQueueToConsumer<T> implements IQueueToConsumer<T> {
|
|||||||
private final QueueFile queueFile;
|
private final QueueFile queueFile;
|
||||||
|
|
||||||
public DiskQueueToConsumer(Path file,
|
public DiskQueueToConsumer(Path file,
|
||||||
|
boolean clear,
|
||||||
Serializer<T> serializer,
|
Serializer<T> serializer,
|
||||||
Deserializer<T> deserializer,
|
Deserializer<T> deserializer,
|
||||||
QueueConsumer<T> consumer) throws IOException {
|
QueueConsumer<T> consumer) throws IOException {
|
||||||
QueueFile queueFile = new QueueFile.Builder(file.toFile()).build();
|
QueueFile queueFile;
|
||||||
|
try {
|
||||||
|
queueFile = new QueueFile.Builder(file.toFile()).zero(false).build();
|
||||||
|
if (clear) {
|
||||||
|
queueFile.clear();
|
||||||
|
}
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(file);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
|
||||||
|
}
|
||||||
|
queueFile = new QueueFile.Builder(file.toFile()).zero(false).build();
|
||||||
|
}
|
||||||
this.queueFile = queueFile;
|
this.queueFile = queueFile;
|
||||||
this.queue = new QueueToConsumer<>(new SimpleQueueFile<>(queueFile, serializer, deserializer), consumer);
|
this.queue = new QueueToConsumer<>(new SimpleQueueFile<>(queueFile, serializer, deserializer), consumer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user