Class AutoCloseableDelegateInvocationHandler

java.lang.Object
org.apache.sshd.common.util.closeable.AutoCloseableDelegateInvocationHandler
All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
NioChannelDelegateInvocationHandler

public class AutoCloseableDelegateInvocationHandler extends Object implements InvocationHandler
Wraps a target instance and an AutoCloseable delegate into a proxy instance that closes both when wrapper close method called.
  • Field Details

    • proxyTarget

      private final Object proxyTarget
    • delegate

      private final AutoCloseable delegate
    • closers

      private final Object[] closers
  • Constructor Details

    • AutoCloseableDelegateInvocationHandler

      public AutoCloseableDelegateInvocationHandler(Object proxyTarget, AutoCloseable delegate)
  • Method Details

    • getProxyTarget

      public Object getProxyTarget()
    • getAutoCloseableDelegate

      public AutoCloseable getAutoCloseableDelegate()
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • wrapDelegateCloseable

      public static <T extends AutoCloseable> T wrapDelegateCloseable(Object proxyTarget, Class<T> type, AutoCloseable delegate)
      Wraps a target instance and an AutoCloseable delegate into a proxy instance that closes both when wrapper close method called.
      Type Parameters:
      T - The generic AutoCloseable wrapping interface
      Parameters:
      proxyTarget - The (never null) target instance - if not AutoCloseable then it's close() method will not be invoked (i.e., only the delegate)
      type - The target wrapping interface
      delegate - The (never null) delegate to close. Note: the delegate is closed after the target instance.
      Returns:
      The wrapping proxy
    • isCloseMethodInvocation

      public static boolean isCloseMethodInvocation(Method m, Object[] args)
    • isCloseMethod

      public static boolean isCloseMethod(Method m)