I have a java program. I would like to intercept every function entries and exits and log them, without changing the existing (~5k) function bodies.
I know AspectJ and Spring AOP are suitable for that. But unfortunately, I am not allowed to use them on the target system (this is not my decistion).
One possibility would be to use following:
void func()
{
logger.logEntry();
// here stuff
logger.logExit();
}
How can I achieve this without any third-party component/tool (this is very important!) without needed to insert these mentioned extra traces? Is there any Java interface/abstract class or any other method/possibility that can be used for this purpose? Or any event handler/subsriber etc.?
As I googled, I found only third-party solutions for this.
What the best soultion would be, if an abstract class with a 2 abstract functions that is called if functions of the from it extended classes' methods are called. Like this:
public abstract class InterceptFunctionCalls
{
// here the internal stuff that call the following methods below
protected abstract void EnteredFunction(String func);
protected abstract void ExitedFunction(String func);
}
Is there any Java interface/abstract class or any other method/possibility that can be used for this purpose?
No... That's why some third-parties decided to show up and provide for the need. Java as the unextended language isn't trying to offer AOP.