Class RemoteDbDelegateInvocationHandler
java.lang.Object
org.tentackle.dbms.trip.RemoteDbDelegateInvocationHandler
- All Implemented Interfaces:
InvocationHandler
Invocation handler to capture TRIP method invocations.
- Author:
- harald
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRemoteDbDelegateInvocationHandler(RemoteDbDelegateImpl<?> delegate) Creates an invocation handler for aRemoteDbDelegate. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanupDbAfterException(Throwable cause) Cleans up the db after an exception.
Invoked fromhandleInvocationException(Object, Method, Object[], Throwable).protected voidclearMDC()Clears the MDC.protected voidClears the thread-locals and session's owner thread.Gets the delegate.static longGets the minimum milliseconds a method needs to execute before being logged.static intGets the minimum size of the returned collection to get logged.static PatternGets the MDC filter.protected RuntimeExceptionhandleInvocationException(Object proxy, Method method, Object[] args, Throwable cause) Handles an invocation exception.
Figures out the real exception cause and throws it, skipping InvocationTargetExceptions.protected ObjectinvokeImpl(Object proxy, Method method, Object[] args) Invokes the delegate's method.static booleanReturns whether statistics should be collected.static booleanReturns whether args and return values will be logged as well.static booleanReturns whether each invocation should be logged.protected booleanChecks whether the mapped diagnostic context is valid for statistics logging.protected voidLogs and counts the invocation.static voidsetCollectingStatistics(boolean collect) Sets whether statistics should be collected.static voidsetLoggingInvocationDetails(boolean log) Sets whether args and return values will be logged as well.static voidsetLoggingInvocations(boolean log) Sets whether each invocation should be logged.static voidsetLogMinDurationMillis(long millis) Sets the minimum milliseconds a method needs to execute before being logged.static voidsetLogMinReturnedCollectionSize(int size) Sets the minimum size of the returned collection to get logged.static voidsetMdcFilter(Pattern filter) Sets the optional filter to log only TRIP-calls for certain MappedDiagnosticContexts.
If set, statements are only collected for logging if the MDC is valid and the pattern matches the toString-value of the MDC.protected voidUpdates theMappedDiagnosticContextwith the session data.protected voidUpdates the thread-locals and sets the session's owner thread.
-
Field Details
-
MDC_SESSION_KEY
-
-
Constructor Details
-
RemoteDbDelegateInvocationHandler
Creates an invocation handler for aRemoteDbDelegate.The invocation handler may be used to intercept remote method invocations. The default implementation just sets the session info into the
MappedDiagnosticContext.- Parameters:
delegate- the remote delegate
-
-
Method Details
-
isCollectingStatistics
public static boolean isCollectingStatistics()Returns whether statistics should be collected.- Returns:
- true if method invocations are counted and measured per method
-
setCollectingStatistics
public static void setCollectingStatistics(boolean collect) Sets whether statistics should be collected.- Parameters:
collect- true if method invocations are counted and measured per method
-
isLoggingInvocations
public static boolean isLoggingInvocations()Returns whether each invocation should be logged.- Returns:
- true if invocations are logged
-
setLoggingInvocations
public static void setLoggingInvocations(boolean log) Sets whether each invocation should be logged.- Parameters:
log- true if invocations are logged
-
isLoggingInvocationDetails
public static boolean isLoggingInvocationDetails()Returns whether args and return values will be logged as well.- Returns:
- true if log arguments and return value
-
setLoggingInvocationDetails
public static void setLoggingInvocationDetails(boolean log) Sets whether args and return values will be logged as well.- Parameters:
log- true if log arguments and return value
-
getLogMinDurationMillis
public static long getLogMinDurationMillis()Gets the minimum milliseconds a method needs to execute before being logged.- Returns:
- 0 if disabled
-
setLogMinDurationMillis
public static void setLogMinDurationMillis(long millis) Sets the minimum milliseconds a method needs to execute before being logged.- Parameters:
millis- 0 to disable
-
getLogMinReturnedCollectionSize
public static int getLogMinReturnedCollectionSize()Gets the minimum size of the returned collection to get logged.- Returns:
- 0 if disabled
-
setLogMinReturnedCollectionSize
public static void setLogMinReturnedCollectionSize(int size) Sets the minimum size of the returned collection to get logged.- Parameters:
size- 0 to disable
-
getMdcFilter
-
setMdcFilter
Sets the optional filter to log only TRIP-calls for certain MappedDiagnosticContexts.
If set, statements are only collected for logging if the MDC is valid and the pattern matches the toString-value of the MDC.- Parameters:
filter- the filter, null to clear
-
getDelegate
-
invoke
-
updateMDC
protected void updateMDC()Updates theMappedDiagnosticContextwith the session data. -
clearMDC
protected void clearMDC()Clears the MDC. -
isMDCValid
protected boolean isMDCValid()Checks whether the mapped diagnostic context is valid for statistics logging.- Returns:
- true if loggable
-
updateThreadInfo
protected void updateThreadInfo()Updates the thread-locals and sets the session's owner thread. -
clearThreadInfo
protected void clearThreadInfo()Clears the thread-locals and session's owner thread. -
handleInvocationException
protected RuntimeException handleInvocationException(Object proxy, Method method, Object[] args, Throwable cause) Handles an invocation exception.
Figures out the real exception cause and throws it, skipping InvocationTargetExceptions. Furthermore, the exception will be logged in the server's log as well (not just the client).- Parameters:
proxy- the dynamic proxymethod- the method to invokeargs- the method's argumentscause- the invocation exception
-
cleanupDbAfterException
Cleans up the db after an exception.
Invoked fromhandleInvocationException(Object, Method, Object[], Throwable).- Parameters:
cause- the cause of failure
-
invokeImpl
Invokes the delegate's method.If the invocation failed for some reason, the stacktrace is logged.
- Parameters:
proxy- the dynamic proxymethod- the method to invokeargs- the method's arguments- Returns:
- the method's return value
-
log
-