Update to java 16

This commit is contained in:
Andrea Cavalli 2021-05-21 00:18:39 +02:00
parent bce04a20a4
commit f39070f2f3
16 changed files with 48 additions and 67 deletions

30
pom.xml
View File

@ -30,8 +30,6 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.>11</maven.compiler.>
</properties> </properties>
<repositories> <repositories>
@ -55,9 +53,10 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>io.soabase.record-builder</groupId>
<artifactId>lombok</artifactId> <artifactId>record-builder-core</artifactId>
<version>1.18.20</version> <version>1.19</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
@ -88,21 +87,24 @@
</dependencies> </dependencies>
<build> <build>
<sourceDirectory>src/main/lombok</sourceDirectory>
<testSourceDirectory>src/test/lombok</testSourceDirectory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.8.1</version>
<configuration> <configuration>
<source>16</source>
<target>16</target>
<annotationProcessorPaths> <annotationProcessorPaths>
<annotationProcessorPath> <annotationProcessorPath>
<groupId>org.projectlombok</groupId> <groupId>io.soabase.record-builder</groupId>
<artifactId>lombok</artifactId> <artifactId>record-builder-processor</artifactId>
<version>1.18.20</version> <version>1.19</version>
</annotationProcessorPath> </annotationProcessorPath>
</annotationProcessorPaths> </annotationProcessorPaths>
<annotationProcessors>
<annotationProcessor>io.soabase.recordbuilder.processor.RecordBuilderProcessor</annotationProcessor>
</annotationProcessors>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
@ -118,10 +120,6 @@
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version> <version>3.0.2</version>
</plugin> </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version> <version>2.22.1</version>

View File

@ -32,14 +32,11 @@ import it.cavallium.dbengine.database.LLDictionaryResultType;
import it.cavallium.dbengine.database.LLKeyValueDatabase; import it.cavallium.dbengine.database.LLKeyValueDatabase;
import it.cavallium.dbengine.database.UpdateMode; import it.cavallium.dbengine.database.UpdateMode;
import it.cavallium.dbengine.database.UpdateReturnMode; import it.cavallium.dbengine.database.UpdateReturnMode;
import it.cavallium.dbengine.database.disk.LLLocalDictionary.ReleasableSlice;
import it.unimi.dsi.fastutil.booleans.BooleanArrayList; import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.warp.filesponge.DiskMetadata.DiskMetadataSerializer; import org.warp.filesponge.DiskMetadata.DiskMetadataSerializer;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@ -86,8 +83,8 @@ public class DiskCache implements URLsDiskHandler, URLsWriter {
return oldValue; return oldValue;
} else { } else {
return diskMetadataSerializer.serialize(new DiskMetadata( return diskMetadataSerializer.serialize(new DiskMetadata(
metadata.getSize(), metadata.size(),
BooleanArrayList.wrap(new boolean[DiskMetadata.getBlocksCount(metadata.getSize(), BLOCK_SIZE)]) BooleanArrayList.wrap(new boolean[DiskMetadata.getBlocksCount(metadata.size(), BLOCK_SIZE)])
)); ));
} }
}, UpdateReturnMode.NOTHING), }, UpdateReturnMode.NOTHING),
@ -118,10 +115,10 @@ public class DiskCache implements URLsDiskHandler, URLsWriter {
@Nullable DiskMetadata result; @Nullable DiskMetadata result;
if (prevBytes != null) { if (prevBytes != null) {
DiskMetadata prevMeta = diskMetadataSerializer.deserialize(prevBytes); DiskMetadata prevMeta = diskMetadataSerializer.deserialize(prevBytes);
if (!prevMeta.getDownloadedBlocks().getBoolean(dataBlock.getId())) { if (!prevMeta.downloadedBlocks().getBoolean(dataBlock.getId())) {
BooleanArrayList bal = prevMeta.getDownloadedBlocks().clone(); BooleanArrayList bal = prevMeta.downloadedBlocks().clone();
bal.set(dataBlock.getId(), true); bal.set(dataBlock.getId(), true);
result = new DiskMetadata(prevMeta.getSize(), bal); result = new DiskMetadata(prevMeta.size(), bal);
} else { } else {
result = prevMeta; result = prevMeta;
} }
@ -144,7 +141,7 @@ public class DiskCache implements URLsDiskHandler, URLsWriter {
public Flux<DataBlock> requestContent(URL url) { public Flux<DataBlock> requestContent(URL url) {
return requestDiskMetadata(url) return requestDiskMetadata(url)
.filter(DiskMetadata::isDownloadedFully) .filter(DiskMetadata::isDownloadedFully)
.flatMapMany(meta -> Flux.fromIterable(meta.getDownloadedBlocks()) .flatMapMany(meta -> Flux.fromIterable(meta.downloadedBlocks())
.index() .index()
// Get only downloaded blocks // Get only downloaded blocks
.filter(Tuple2::getT2) .filter(Tuple2::getT2)
@ -164,8 +161,8 @@ public class DiskCache implements URLsDiskHandler, URLsWriter {
try { try {
int blockOffset = getBlockOffset(blockId); int blockOffset = getBlockOffset(blockId);
int blockLength = data.readableBytes(); int blockLength = data.readableBytes();
if (blockOffset + blockLength >= meta.getSize()) { if (blockOffset + blockLength >= meta.size()) {
if (blockOffset + blockLength > meta.getSize()) { if (blockOffset + blockLength > meta.size()) {
throw new IllegalStateException("Overflowed data size"); throw new IllegalStateException("Overflowed data size");
} }
} else { } else {

View File

@ -29,39 +29,30 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import lombok.Data; import java.io.IOException;
import lombok.SneakyThrows; import org.apache.commons.lang3.SerializationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.warp.filesponge.DiskMetadata.DiskMetadataSerializer;
@Data /**
public class DiskMetadata { * size -1 = unknown size
*/
/** public record DiskMetadata(int size, BooleanArrayList downloadedBlocks) {
* -1 = unknown size
*/
private final int size;
private final BooleanArrayList downloadedBlocks;
private Boolean downloadedFully;
public boolean isDownloadedFully() { public boolean isDownloadedFully() {
if (downloadedFully == null) { boolean downloadedFullyVal;
// Ensure blocks count is valid by calling getBlocksCount() // Ensure blocks count is valid by calling getBlocksCount()
getBlocksCount(); getBlocksCount();
// It's fully downloaded if every block is true // It's fully downloaded if every block is true
downloadedFully = !this.getDownloadedBlocks().contains(false); downloadedFullyVal = !this.downloadedBlocks().contains(false);
} return downloadedFullyVal;
return downloadedFully;
} }
private int getBlocksCount() { private int getBlocksCount() {
var expectedBlocksCount = getBlocksCount(size, FileSponge.BLOCK_SIZE); var expectedBlocksCount = getBlocksCount(size, FileSponge.BLOCK_SIZE);
if (this.getDownloadedBlocks().size() != expectedBlocksCount) { if (this.downloadedBlocks.size() != expectedBlocksCount) {
throw new IllegalStateException( throw new IllegalStateException(
"Blocks array length (" + this.getDownloadedBlocks().size() "Blocks array length (" + this.downloadedBlocks().size() + ") != expected blocks count ("
+ ") != expected blocks count (" + expectedBlocksCount + ")"); + expectedBlocksCount + ")");
} }
return expectedBlocksCount; return expectedBlocksCount;
} }
@ -81,8 +72,7 @@ public class DiskMetadata {
public DiskMetadataSerializer(ByteBufAllocator allocator) { public DiskMetadataSerializer(ByteBufAllocator allocator) {
this.allocator = allocator; this.allocator = allocator;
} }
@SneakyThrows
@Override @Override
public @NotNull DiskMetadata deserialize(@NotNull ByteBuf serialized) { public @NotNull DiskMetadata deserialize(@NotNull ByteBuf serialized) {
try { try {
@ -95,24 +85,27 @@ public class DiskMetadata {
downloadedBlocks.add(dis.readBoolean()); downloadedBlocks.add(dis.readBoolean());
} }
return new DiskMetadata(size, downloadedBlocks); return new DiskMetadata(size, downloadedBlocks);
} catch (IOException e) {
throw new SerializationException(e);
} finally { } finally {
serialized.release(); serialized.release();
} }
} }
@SneakyThrows
@Override @Override
public @NotNull ByteBuf serialize(@NotNull DiskMetadata deserialized) { public @NotNull ByteBuf serialize(@NotNull DiskMetadata deserialized) {
ByteBuf buffer = allocator.buffer(); ByteBuf buffer = allocator.buffer();
try (var bos = new ByteBufOutputStream(buffer)) { try (var bos = new ByteBufOutputStream(buffer)) {
try (var dos = new DataOutputStream(bos)) { try (var dos = new DataOutputStream(bos)) {
dos.writeInt(deserialized.getSize()); dos.writeInt(deserialized.size());
deserialized.getBlocksCount(); deserialized.getBlocksCount();
for (boolean downloadedBlock : deserialized.getDownloadedBlocks()) { for (boolean downloadedBlock : deserialized.downloadedBlocks) {
dos.writeBoolean(downloadedBlock); dos.writeBoolean(downloadedBlock);
} }
} }
return buffer; return buffer;
} catch (IOException e) {
throw new SerializationException(e);
} }
} }

View File

@ -18,7 +18,6 @@
package org.warp.filesponge; package org.warp.filesponge;
import it.cavallium.dbengine.database.disk.LLLocalDictionary.ReleasableSlice;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;

View File

@ -18,14 +18,8 @@
package org.warp.filesponge; package org.warp.filesponge;
import lombok.Value;
@Value /**
public class Metadata { * size -1 = unknown size
*/
/** public record Metadata(int size) {}
* -1 = unknown size
*/
int size;
}