Class NativeObject

java.lang.Object
org.apache.opendal.NativeObject
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
AsyncExecutor, BlockingOperator, Operator

public abstract class NativeObject extends Object implements AutoCloseable
NativeObject is the base-class of all OpenDAL classes that have a pointer to a native object.

NativeObject has the close() method, which frees its associated native object.

This function should be called manually, or even better, called implicitly using a try-with-resources statement, when you are finished with the object. It is no longer called automatically during the regular Java GC process via Object.finalize().

Explanatory note

When or if the Garbage Collector calls Object.finalize() depends on the JVM implementation and system conditions, which the programmer cannot control. In addition, the GC cannot see through the native reference long member variable (which is the pointer value to the native object), and cannot know what other resources depend on it.

Finalization is deprecated and subject to removal in a future release. The use of finalization can lead to problems with security, performance, and reliability. See JEP 421 for discussion and alternatives.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final long
    An immutable reference to the value of the underneath pointer pointing to some underlying native OpenDAL object.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    NativeObject(long nativeHandle)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected abstract void
    disposeInternal(long handle)
    Deletes underlying native object pointer.
    boolean
    Check if the object has been disposed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • nativeHandle

      protected final long nativeHandle
      An immutable reference to the value of the underneath pointer pointing to some underlying native OpenDAL object.
  • Constructor Details

    • NativeObject

      protected NativeObject(long nativeHandle)
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • isDisposed

      public boolean isDisposed()
      Check if the object has been disposed. Useful for defensive programming.
      Returns:
      if the object has been disposed.
    • disposeInternal

      protected abstract void disposeInternal(long handle)
      Deletes underlying native object pointer.
      Parameters:
      handle - to the native object pointer