All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensearch.migrations.replay.util.RefSafeHolder Maven / Gradle / Ivy

There is a newer version: 0.2.0.4
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy