aspects

Why does the serialVersionUID field exist?

天涯浪子 提交于 2019-12-05 21:30:08
It has baffled me from the launch of the Serializable interface why I have to incorporate this field in all of my classes. I understand that this interface needs a unique identifier to mark the class but why cant they generate this at run-time. For instance they could generate it using an MD5 hash of the fully-qualified class name or a similar methodology used to handle duplicates in their rare occurrence (Which is, I'm sure, what eclipse does when asked to generate the id anyway). So what I'm asking (no this post isn't just a rant against the standard library) is exactly how the serialization

How to intercept method which handles its own exceptions using AspectJ

你。 提交于 2019-12-04 17:32:55
I'm trying add some monitoring when some specific exception occurs. For example, if I have an aspect like this: @Aspect public class LogAspect { @AfterThrowing(value = "execution(* *(..))", throwing = "e") public void log(JoinPoint joinPoint, Throwable e){ System.out.println("Some logging stuff"); } } And test class: public class Example { public void divideByZeroWithCatch(){ try{ int a = 5/0; } catch (ArithmeticException e){ System.out.println("Can not divide by zero"); } } public void divideByZeroWithNoCatch(){ int b = 5/0; } public static void main (String [] args){ Example e = new Example(

How to separate logging logic from business logic in a C program? And in a C++ one?

柔情痞子 提交于 2019-12-04 11:22:58
问题 I am currently coding in C and I have lots of printfs so that I can track, at some times, the flow of my application. The problem is that some times I want more detail than others, so I usually spend my time commenting/uncommenting my C code, so I can get the appropriate output. When using Java or C#, I can generally separate both my implementation code from the logging logic by using Aspects. Is there any similar technique you use in C to get around this problem? I know I could put a flag

How to separate logging logic from business logic in a C program? And in a C++ one?

做~自己de王妃 提交于 2019-12-03 08:14:49
I am currently coding in C and I have lots of printfs so that I can track, at some times, the flow of my application. The problem is that some times I want more detail than others, so I usually spend my time commenting/uncommenting my C code, so I can get the appropriate output. When using Java or C#, I can generally separate both my implementation code from the logging logic by using Aspects. Is there any similar technique you use in C to get around this problem? I know I could put a flag called DEBUG that could be either on or off, so I wouldn't have to go all around and comment/uncomment my

Interceptors vs Aspects in Spring?

一曲冷凌霜 提交于 2019-12-02 15:37:25
I am trying to use interceptors in Spring. I want to implement an interceptor on some methods to handle specific logic when these methods are called. I also want to be apart from using web framework, as am tending to use Spring as back end, without any headers. After searching, I think spring approach is called Aspects, could you please mention best practice to do this? In Spring there are two different constructs that get called "interceptors". First, there are Handler Interceptors , which are part of the Spring MVC framework, and allow you to add interceptor logic to web requests. I suspect

@AspectJ syntax for “after() : staticinitialization(*)”

佐手、 提交于 2019-11-30 08:52:28
问题 I'm trying to implement a tracing aspect using the pertypewithin instantiation model. In this way, I'll be able to use one logger per class per type. From some examples arround the we I can find this code to init the logger: public abstract aspect TraceAspect pertypewithin(com.something.*) { abstract pointcut traced(); after() : staticinitialization(*) { logger = Logger.getLogger(getWithinTypeName()); } before() : traced() { logger.log(...); } //.... } unfortunately, I'm not able to fully

PostSharp on assemblies I don't have source for

不问归期 提交于 2019-11-30 08:34:18
问题 In the examples on their website, PostSharp has a demo of intercepting calls in main system assemblies. I have tried a few times to setup and replicate said intercept calls on assemblies I don't have the source code for with no success. My approach was to simply place the assembly level attribute targeting the namespace and method I wanted to instrument. This has never worked for me. something like: [assembly: Trace("MyCategory", AttributeTargetTypes = "My.BusinessLayer.*")] Am I missing

@AspectJ syntax for “after() : staticinitialization(*)”

青春壹個敷衍的年華 提交于 2019-11-29 08:45:46
I'm trying to implement a tracing aspect using the pertypewithin instantiation model. In this way, I'll be able to use one logger per class per type. From some examples arround the we I can find this code to init the logger: public abstract aspect TraceAspect pertypewithin(com.something.*) { abstract pointcut traced(); after() : staticinitialization(*) { logger = Logger.getLogger(getWithinTypeName()); } before() : traced() { logger.log(...); } //.... } unfortunately, I'm not able to fully translate this to the @AspectJ syntax (it's a project requirement outside my control), especially the part

PostSharp on assemblies I don't have source for

倖福魔咒の 提交于 2019-11-29 07:08:33
In the examples on their website, PostSharp has a demo of intercepting calls in main system assemblies. I have tried a few times to setup and replicate said intercept calls on assemblies I don't have the source code for with no success. My approach was to simply place the assembly level attribute targeting the namespace and method I wanted to instrument. This has never worked for me. something like: [assembly: Trace("MyCategory", AttributeTargetTypes = "My.BusinessLayer.*")] Am I missing something here? Can I not do a runtime injection of my instrumentation aspect on a assembly if I don't have

What is AspectJ good for? [closed]

回眸只為那壹抹淺笑 提交于 2019-11-28 03:12:08
First let me note, that I use AspectJ and I like it, but what else can I do with it. I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can also be used to enhance classes with (code-generated) methods, like Spring Roo does. But I believe AspectJ and AOP in general, can be used for more than: logging, transaction controlling, and simulation partial classes. So what are other useful use cases for AspectJ and AOP? permission check interrupt action that takes too long run action in separate