public abstract class CrtResource extends Object implements AutoCloseable
Modifier and Type | Class and Description |
---|---|
class |
CrtResource.ResourceInstance |
Constructor and Description |
---|
CrtResource() |
Modifier and Type | Method and Description |
---|---|
protected void |
acquireNativeHandle(long handle)
Takes ownership of a native object where the native pointer is tracked as a long.
|
void |
addRef()
Increments the reference count to this resource.
|
void |
addReferenceTo(CrtResource resource)
Marks a resource as referenced by this resource.
|
protected abstract boolean |
canReleaseReferencesImmediately()
Override that determines whether a resource releases its dependencies at the same time the native handle is released or if it waits.
|
void |
close() |
static void |
collectNativeResource(java.util.function.Consumer<CrtResource.ResourceInstance> fn) |
static void |
collectNativeResources(java.util.function.Consumer<String> fn) |
void |
decRef()
Decrements the reference count to this resource.
|
long |
getNativeHandle()
returns the native handle associated with this CRTResource.
|
String |
getResourceLogDescription() |
boolean |
isNull()
Checks if this resource's native handle is NULL.
|
static void |
logNativeResources()
Debug method to log all of the currently un-closed CRTResource objects.
|
protected abstract void |
releaseNativeHandle()
Required override method that must begin the release process of the acquired native handle
|
protected void |
releaseReferences()
Decrements the ref counts for all resources referenced by this resource.
|
void |
removeReferenceTo(CrtResource resource)
Removes a reference from this resource to another.
|
void |
setDescription(String description) |
protected void |
swapReferenceTo(CrtResource oldReference,
CrtResource newReference) |
static void |
waitForNoResources()
Debug/test method to wait for the CRTResource count to drop to zero.
|
public void addReferenceTo(CrtResource resource)
resource
- The resource to add a reference topublic void removeReferenceTo(CrtResource resource)
resource
- The resource to remove a reference toprotected void swapReferenceTo(CrtResource oldReference, CrtResource newReference)
protected void acquireNativeHandle(long handle)
handle
- pointer to the native object being acquiredpublic long getNativeHandle()
public void addRef()
protected abstract void releaseNativeHandle()
protected abstract boolean canReleaseReferencesImmediately()
public boolean isNull()
public void close()
close
in interface AutoCloseable
public void decRef()
protected void releaseReferences()
public void setDescription(String description)
public String getResourceLogDescription()
public static void collectNativeResources(java.util.function.Consumer<String> fn)
public static void collectNativeResource(java.util.function.Consumer<CrtResource.ResourceInstance> fn)
public static void logNativeResources()
public static void waitForNoResources()
Copyright © 2021. All rights reserved.