Make Disposable interface implement Closeable

This commit is contained in:
Andrew Steinborn
2020-07-29 05:34:15 -04:00
parent c2db8d4ac1
commit 89f98ce57d
12 changed files with 18 additions and 17 deletions

View File

@@ -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();
}

View File

@@ -123,7 +123,7 @@ public class Java11VelocityCompressor implements VelocityCompressor {
}
@Override
public void dispose() {
public void close() {
disposed = true;
deflater.end();
inflater.end();

View File

@@ -118,7 +118,7 @@ public class JavaVelocityCompressor implements VelocityCompressor {
}
@Override
public void dispose() {
public void close() {
disposed = true;
deflater.end();
inflater.end();

View File

@@ -70,7 +70,7 @@ public class LibdeflateVelocityCompressor implements VelocityCompressor {
}
@Override
public void dispose() {
public void close() {
if (!disposed) {
inflate.free(inflateCtx);
deflate.free(deflateCtx);

View File

@@ -55,7 +55,7 @@ public class JavaVelocityCipher implements VelocityCipher {
}
@Override
public void dispose() {
public void close() {
disposed = true;
}

View File

@@ -39,7 +39,7 @@ public class NativeVelocityCipher implements VelocityCipher {
}
@Override
public void dispose() {
public void close() {
if (!disposed) {
impl.free(ctx);
}