Class AutoCloseableDelegateInvocationHandler
- java.lang.Object
-
- org.apache.sshd.common.util.closeable.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 anAutoCloseable
delegate into a proxy instance that closes both when wrapperclose
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
-
Constructor Summary
Constructors Constructor Description AutoCloseableDelegateInvocationHandler(java.lang.Object proxyTarget, java.lang.AutoCloseable delegate)
-
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>
TwrapDelegateCloseable(java.lang.Object proxyTarget, java.lang.Class<T> type, java.lang.AutoCloseable delegate)
Wraps a target instance and anAutoCloseable
delegate into a proxy instance that closes both when wrapperclose
method called.
-
-
-
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 interfacejava.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 anAutoCloseable
delegate into a proxy instance that closes both when wrapperclose
method called.- Type Parameters:
T
- The genericAutoCloseable
wrapping interface- Parameters:
proxyTarget
- The (nevernull
) target instance - if notAutoCloseable
then it'sclose()
method will not be invoked (i.e., only the delegate)type
- The target wrapping interfacedelegate
- The (nevernull
) 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)
-
-