Package software.amazon.awssdk.crt
Class CrtResource
- java.lang.Object
-
- software.amazon.awssdk.crt.CrtResource
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
AwsSigningConfig,ClientBootstrap,ClientConnection,ClientConnectionContinuation,CredentialsProvider,EccKeyPair,EventLoopGroup,HostResolver,Http2StreamManager,HttpClientConnection,HttpClientConnectionManager,HttpStreamBase,Message,Mqtt5Client,MqttClient,MqttClientConnection,MqttConnectionConfig,MqttRequestResponseClient,Pkcs11Lib,S3Client,S3MetaRequest,ServerBootstrap,ServerConnection,ServerConnectionContinuation,ServerListener,SocketOptions,StreamingOperation,TlsConnectionOptions,TlsContext,TlsContextOptions,TlsContextPkcs11Options
public abstract class CrtResource extends Object implements AutoCloseable
This wraps a native pointer and/or one or more references to an AWS Common Runtime resource. It also ensures that the first time a resource is referenced, the CRT will be loaded and bound.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCrtResource.ResourceInstanceDebug/diagnostic data about a CrtResource object
-
Constructor Summary
Constructors Constructor Description CrtResource()Default constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRef()Increments the reference count to this resource.voidaddReferenceTo(CrtResource resource)Marks a resource as referenced by this resource.voidclose()static voidcollectNativeResource(Consumer<CrtResource.ResourceInstance> fn)Applies a generic diagnostic-gathering functor to all CRTResource objectsstatic voidcollectNativeResources(Consumer<String> fn)Applies a resource description consuming functor to all CRTResource objectsvoiddecRef()Decrements the reference count to this resource.voiddecRef(CrtResource decRefInstigator)Decrements the reference count to this resource.longgetNativeHandle()returns the native handle associated with this CRTResource.StringgetResourceLogDescription()Gets a debug/diagnostic string describing this resource and its reference statebooleanisNull()Checks if this resource's native handle is NULL.static voidlogNativeResources()Debug method to log all of the currently un-closed CRTResource objects.static voidlogNativeResources(Log.LogLevel logLevel)voidremoveReferenceTo(CrtResource resource)Removes a reference from this resource to another.voidsetDescription(String description)Sets a custom logging description for this resourcestatic voidwaitForNoResources()Debug/test method to wait for the CRTResource count to drop to zero.
-
-
-
Method Detail
-
addReferenceTo
public void addReferenceTo(CrtResource resource)
Marks a resource as referenced by this resource.- Parameters:
resource- The resource to add a reference to
-
removeReferenceTo
public void removeReferenceTo(CrtResource resource)
Removes a reference from this resource to another.- Parameters:
resource- The resource to remove a reference to
-
getNativeHandle
public long getNativeHandle()
returns the native handle associated with this CRTResource.- Returns:
- native address
-
addRef
public void addRef()
Increments the reference count to this resource.
-
isNull
public boolean isNull()
Checks if this resource's native handle is NULL. For always-null resources this is always true. For all other resources it means it has already been cleaned up or was not properly constructed.- Returns:
- true if no native resource is bound, false otherwise
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
decRef
public void decRef(CrtResource decRefInstigator)
Decrements the reference count to this resource. If zero is reached, begins (and possibly completes) the resource's cleanup process.- Parameters:
decRefInstigator- Instigating CrtResource
-
decRef
public void decRef()
Decrements the reference count to this resource.
-
setDescription
public void setDescription(String description)
Sets a custom logging description for this resource- Parameters:
description- custom resource description
-
getResourceLogDescription
public String getResourceLogDescription()
Gets a debug/diagnostic string describing this resource and its reference state- Returns:
- resource diagnostic string
-
collectNativeResources
public static void collectNativeResources(Consumer<String> fn)
Applies a resource description consuming functor to all CRTResource objects- Parameters:
fn- function to apply to each resource description
-
collectNativeResource
public static void collectNativeResource(Consumer<CrtResource.ResourceInstance> fn)
Applies a generic diagnostic-gathering functor to all CRTResource objects- Parameters:
fn- function to apply to each outstanding Crt resource
-
logNativeResources
public static void logNativeResources()
Debug method to log all of the currently un-closed CRTResource objects.
-
logNativeResources
public static void logNativeResources(Log.LogLevel logLevel)
-
waitForNoResources
public static void waitForNoResources()
Debug/test method to wait for the CRTResource count to drop to zero. Times out with an exception after a period of waiting.
-
-