org.opensearch.migrations.replay.util.RefSafeHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trafficReplayer Show documentation
Show all versions of trafficReplayer Show documentation
Everything opensearch migrations
package org.opensearch.migrations.replay.util;
import javax.annotation.Nullable;
import com.google.errorprone.annotations.MustBeClosed;
import io.netty.util.ReferenceCountUtil;
public class RefSafeHolder implements AutoCloseable {
private final T resource;
private RefSafeHolder(@Nullable T resource) {
this.resource = resource;
}
@MustBeClosed
static public RefSafeHolder create(@Nullable T resource) {
return new RefSafeHolder<>(resource);
}
public @Nullable T get() {
return resource;
}
@Override
public void close() {
ReferenceCountUtil.release(resource);
}
}