Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
Make Disposable interface implement Closeable
Dieser Commit ist enthalten in:
Ursprung
c2db8d4ac1
Commit
89f98ce57d
@ -1,16 +1,19 @@
|
||||
package com.velocitypowered.natives;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
/**
|
||||
* This marker interface indicates that this object should be explicitly disposed before the object
|
||||
* can no longer be used. Not disposing these objects will likely leak native resources and
|
||||
* eventually lead to resource exhaustion.
|
||||
*/
|
||||
public interface Disposable {
|
||||
public interface Disposable extends Closeable {
|
||||
|
||||
/**
|
||||
* Disposes this object. After this call returns, any use of this object becomes invalid. Multiple
|
||||
* calls to this function should be safe: there should be no side-effects once an object is
|
||||
* disposed.
|
||||
*/
|
||||
void dispose();
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class Java11VelocityCompressor implements VelocityCompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void close() {
|
||||
disposed = true;
|
||||
deflater.end();
|
||||
inflater.end();
|
||||
|
@ -118,7 +118,7 @@ public class JavaVelocityCompressor implements VelocityCompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void close() {
|
||||
disposed = true;
|
||||
deflater.end();
|
||||
inflater.end();
|
||||
|
@ -70,7 +70,7 @@ public class LibdeflateVelocityCompressor implements VelocityCompressor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void close() {
|
||||
if (!disposed) {
|
||||
inflate.free(inflateCtx);
|
||||
deflate.free(deflateCtx);
|
||||
|
@ -55,7 +55,7 @@ public class JavaVelocityCipher implements VelocityCipher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void close() {
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class NativeVelocityCipher implements VelocityCipher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
public void close() {
|
||||
if (!disposed) {
|
||||
impl.free(ctx);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.condition.OS.LINUX;
|
||||
import static org.junit.jupiter.api.condition.OS.MAC;
|
||||
|
||||
import com.velocitypowered.natives.util.BufferPreference;
|
||||
import com.velocitypowered.natives.util.Natives;
|
||||
@ -43,7 +42,7 @@ class VelocityCompressorTest {
|
||||
void nativeIntegrityCheck() throws DataFormatException {
|
||||
VelocityCompressor compressor = Natives.compress.get().create(Deflater.DEFAULT_COMPRESSION);
|
||||
if (compressor.preferredBufferType() != BufferPreference.DIRECT_REQUIRED) {
|
||||
compressor.dispose();
|
||||
compressor.close();
|
||||
fail("Loaded regular compressor");
|
||||
}
|
||||
check(compressor, () -> Unpooled.directBuffer(TEST_DATA.length + 32));
|
||||
@ -97,7 +96,7 @@ class VelocityCompressorTest {
|
||||
source.release();
|
||||
dest.release();
|
||||
decompressed.release();
|
||||
compressor.dispose();
|
||||
compressor.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VelocityCipherTest {
|
||||
@ -62,8 +61,8 @@ class VelocityCipherTest {
|
||||
} finally {
|
||||
source.release();
|
||||
workingBuf.release();
|
||||
decrypt.dispose();
|
||||
encrypt.dispose();
|
||||
decrypt.close();
|
||||
encrypt.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ public class MinecraftCipherDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
cipher.dispose();
|
||||
cipher.close();
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ public class MinecraftCipherEncoder extends MessageToMessageEncoder<ByteBuf> {
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
cipher.dispose();
|
||||
cipher.close();
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,6 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
compressor.dispose();
|
||||
compressor.close();
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,6 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
compressor.dispose();
|
||||
compressor.close();
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren