Class ProxyDestructor

java.lang.Object
com.exonum.binding.core.proxy.ProxyDestructor
All Implemented Interfaces:
CancellableCleanAction<java.lang.Class<?>>, CleanAction<java.lang.Class<?>>

public final class ProxyDestructor
extends java.lang.Object
implements CancellableCleanAction<java.lang.Class<?>>
ProxyDestructor is a clean action that destroys a native proxy and closes its native handle.

Most native proxies do not implement any interface (e.g., CloseableNativeProxy) and use this class so that there is no public #close method available in the interface of the proxy, making the risk of misuse smaller.

All method parameters are non-null by default.

This class is not thread-safe.

  • Constructor Summary

    Constructors 
    Constructor Description
    ProxyDestructor​(NativeHandle nativeHandle, java.lang.Class<?> proxyClass, java.util.function.LongConsumer destructorFunction)
    Creates a new destructor of a native proxy.
  • Method Summary

    Modifier and Type Method Description
    void cancel()
    Cancels this clean action, making CleanAction.clean() a no-op.
    void clean()
    Closes the native handle, so that it can no longer be accessed, and performs a clean action, passing the native handle value.
    static ProxyDestructor newRegistered​(Cleaner cleaner, NativeHandle nativeHandle, java.lang.Class<?> proxyClass, java.util.function.LongConsumer destructorFunction)
    Creates a new destructor of a native proxy, registered in the given cleaner.
    java.util.Optional<java.lang.Class<?>> resourceType()
    Returns the description of the type of resource this action corresponds to.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ProxyDestructor

      public ProxyDestructor​(NativeHandle nativeHandle, java.lang.Class<?> proxyClass, java.util.function.LongConsumer destructorFunction)
      Creates a new destructor of a native proxy.
      Parameters:
      nativeHandle - a handle to the native object
      proxyClass - a class of the proxy
      destructorFunction - a clean function to perform
  • Method Details

    • newRegistered

      @CanIgnoreReturnValue public static ProxyDestructor newRegistered​(Cleaner cleaner, NativeHandle nativeHandle, java.lang.Class<?> proxyClass, java.util.function.LongConsumer destructorFunction)
      Creates a new destructor of a native proxy, registered in the given cleaner.
      Parameters:
      cleaner - a cleaner to register the destructor in
      nativeHandle - a handle to the native object
      proxyClass - a class of proxy
      destructorFunction - a clean function to perform
    • clean

      public void clean()
      Closes the native handle, so that it can no longer be accessed, and performs a clean action, passing the native handle value.

      If native handle is not valid, does nothing.

      This method is idempotent.

      Specified by:
      clean in interface CleanAction<java.lang.Class<?>>
    • resourceType

      public java.util.Optional<java.lang.Class<?>> resourceType()
      Description copied from interface: CleanAction
      Returns the description of the type of resource this action corresponds to.
      Specified by:
      resourceType in interface CleanAction<java.lang.Class<?>>
    • cancel

      public void cancel()
      Description copied from interface: CancellableCleanAction
      Cancels this clean action, making CleanAction.clean() a no-op. This operation cannot be reversed.
      Specified by:
      cancel in interface CancellableCleanAction<java.lang.Class<?>>
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object