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