class RefCountResource {

    public T retain() throws RefCountResourceException {
        synchronized (this) {
            if (refCount.getAndIncrement() == 0) {
                try {
                    log.debug("First Reference. Create Resource.");
                    resource.set(resourceSupplier.get());
                }
                catch (Throwable throwable) {
                    throw new RefCountResourceException(throwable);
                }
            }

            return resource.get();
        }
    }

    public  RefCountResource(Supplier<? extends T> resourceSupplier,
                            Consumer<? super T> resourceCleanup);
      RefCountResource(Supplier<? extends T> resourceSupplier,
                     Consumer<? super T> resourceCleanup,
                     AtomicInteger refCount,
                     AtomicReference<T> resource);

}