Class AutoCloseableDelegateInvocationHandler

  • All Implemented Interfaces:
    java.lang.reflect.InvocationHandler
    Direct Known Subclasses:
    NioChannelDelegateInvocationHandler

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

      Fields 
      Modifier and Type Field Description
      private java.lang.Object[] closers  
      private java.lang.AutoCloseable delegate  
      private java.lang.Object proxyTarget  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.AutoCloseable getAutoCloseableDelegate()  
      java.lang.Object getProxyTarget()  
      java.lang.Object invoke​(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)  
      static boolean isCloseMethod​(java.lang.reflect.Method m)  
      static boolean isCloseMethodInvocation​(java.lang.reflect.Method m, java.lang.Object[] args)  
      static <T extends java.lang.AutoCloseable>
      T
      wrapDelegateCloseable​(java.lang.Object proxyTarget, java.lang.Class<T> type, java.lang.AutoCloseable delegate)
      Wraps a target instance and an AutoCloseable delegate into a proxy instance that closes both when wrapper close method called.
      • Methods inherited from class java.lang.Object

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

      • proxyTarget

        private final java.lang.Object proxyTarget
      • delegate

        private final java.lang.AutoCloseable delegate
      • closers

        private final java.lang.Object[] closers
    • Constructor Detail

      • AutoCloseableDelegateInvocationHandler

        public AutoCloseableDelegateInvocationHandler​(java.lang.Object proxyTarget,
                                                      java.lang.AutoCloseable delegate)
    • Method Detail

      • getProxyTarget

        public java.lang.Object getProxyTarget()
      • getAutoCloseableDelegate

        public java.lang.AutoCloseable getAutoCloseableDelegate()
      • invoke

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

        public static <T extends java.lang.AutoCloseable> T wrapDelegateCloseable​(java.lang.Object proxyTarget,
                                                                                  java.lang.Class<T> type,
                                                                                  java.lang.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​(java.lang.reflect.Method m,
                                                      java.lang.Object[] args)
      • isCloseMethod

        public static boolean isCloseMethod​(java.lang.reflect.Method m)