Package org.signal.libsignal.internal
Class NativeHandleGuard
-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public class NativeHandleGuard implements AutoCloseable
Provides access to a Rust object handle while keeping the Java wrapper alive.
Intended for use with try-with-resources syntax. NativeHandleGuard prevents the Java wrapper from being finalized, which would destroy the Rust object, while the handle is in use. To use it, the Java wrapper type should conform to the NativeHandleGuard.Owner interface.
Note that it is not necessary to use NativeHandleGuard in the implementation of
finalizeitself. The point of NativeHandleGuard is to delay finalization while the Rust object is being used; once finalization has begun, there can be no other uses of the Rust object from Java.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceNativeHandleGuard.Ownerpublic abstract classNativeHandleGuard.SimpleOwnerpublic abstract classNativeHandleGuard.CloseableOwner
-
Constructor Summary
Constructors Constructor Description NativeHandleGuard(NativeHandleGuard.Owner owner)
-
Method Summary
Modifier and Type Method Description longnativeHandle()Returns the native handle owned by the Java object, or 0 if the owner is null.voidclose()-
-
Constructor Detail
-
NativeHandleGuard
NativeHandleGuard(NativeHandleGuard.Owner owner)
-
-
Method Detail
-
nativeHandle
long nativeHandle()
Returns the native handle owned by the Java object, or 0 if the owner is
null.
-
close
void close()
-
-
-
-