Class CloseShieldChannelHandler

  • All Implemented Interfaces:
    java.lang.reflect.InvocationHandler

    final class CloseShieldChannelHandler
    extends java.lang.Object
    implements java.lang.reflect.InvocationHandler
    An InvocationHandler supporting the implementation of CloseShieldChannel.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean closed  
      private java.nio.channels.Channel delegate  
      private static java.util.Set<java.lang.Class<? extends java.nio.channels.Channel>> SUPPORTED_INTERFACES  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object invoke​(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)  
      private java.lang.Object invokeObjectMethod​(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)  
      private static boolean isAllowedAfterClose​(java.lang.Class<?> declaringClass, java.lang.String name, int parameterCount)
      Tests whether the given method is allowed to be called after the shield is closed.
      (package private) static boolean isSupported​(java.lang.Class<?> interfaceClass)  
      private static boolean returnsThis​(java.lang.Class<?> declaringClass, java.lang.String name, int parameterCount)
      Tests whether the given method returns 'this' (the channel) as per JDK spec.
      • Methods inherited from class java.lang.Object

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

      • SUPPORTED_INTERFACES

        private static final java.util.Set<java.lang.Class<? extends java.nio.channels.Channel>> SUPPORTED_INTERFACES
      • delegate

        private final java.nio.channels.Channel delegate
      • closed

        private volatile boolean closed
    • Constructor Detail

      • CloseShieldChannelHandler

        CloseShieldChannelHandler​(java.nio.channels.Channel delegate)
    • Method Detail

      • isAllowedAfterClose

        private static boolean isAllowedAfterClose​(java.lang.Class<?> declaringClass,
                                                   java.lang.String name,
                                                   int parameterCount)
        Tests whether the given method is allowed to be called after the shield is closed.
        Parameters:
        declaringClass - The class declaring the method.
        name - The method name.
        parameterCount - The number of parameters.
        Returns:
        true if the method is allowed after close(), false otherwise.
      • isSupported

        static boolean isSupported​(java.lang.Class<?> interfaceClass)
      • returnsThis

        private static boolean returnsThis​(java.lang.Class<?> declaringClass,
                                           java.lang.String name,
                                           int parameterCount)
        Tests whether the given method returns 'this' (the channel) as per JDK spec.
        Parameters:
        declaringClass - The class declaring the method.
        name - The method name.
        parameterCount - The number of parameters.
        Returns:
        true if the method returns 'this', false otherwise.
      • 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
      • invokeObjectMethod

        private java.lang.Object invokeObjectMethod​(java.lang.Object proxy,
                                                    java.lang.reflect.Method method,
                                                    java.lang.Object[] args)